/[drupal]/contributions/modules/votingapi/votingapi.install
ViewVC logotype

Contents of /contributions/modules/votingapi/votingapi.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.21 - (show annotations) (download) (as text)
Fri Jul 6 03:02:34 2007 UTC (2 years, 4 months ago) by eaton
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2, DRUPAL-6--1
Changes since 1.20: +47 -68 lines
File MIME type: text/x-php
Early stab at VotingAPI for Drupal 6 -- HEAD is the proper place for it, not the mistaken DRUPAL-5 branch checking made earlier. This branch will be moved to the appropriate D6 branch when related issues are sorted out.
1 <?php
2
3 // $Id: votingapi.install,v 1.20.2.3 2007/07/04 07:03:16 eaton Exp $
4
5 function votingapi_install() {
6 drupal_install_schema('votingapi');
7 }
8
9 /**
10 * UTF8 update
11 */
12 function votingapi_update_1() {
13 return _system_update_utf8(array('votingapi_vote', 'votingapi_cache'));
14 }
15
16 /**
17 * Value fields changed to signed floats.
18 */
19 function votingapi_update_2() {
20 $ret = array();
21 switch ($GLOBALS['db_type']) {
22 case 'mysql':
23 case 'mysqli':
24 $ret[] = update_sql("ALTER TABLE {votingapi_cache} CHANGE value value float(10) default NULL");
25 $ret[] = update_sql("ALTER TABLE {votingapi_vote} CHANGE value value float(10) default NULL");
26 break;
27 }
28
29 return $ret;
30 }
31
32 /**
33 * Value fields changed to signed floats.
34 */
35 function votingapi_update_3() {
36 $ret = array();
37 switch ($GLOBALS['db_type']) {
38 case 'mysql':
39 case 'mysqli':
40 $ret[] = update_sql("ALTER TABLE {votingapi_cache} CHANGE value_type value_type varchar(20) NOT NULL");
41 $ret[] = update_sql("ALTER TABLE {votingapi_vote} CHANGE value_type value_type varchar(20) NOT NULL");
42
43 $ret[] = update_sql("ALTER TABLE {votingapi_cache} ADD INDEX (content_type)");
44 $ret[] = update_sql("ALTER TABLE {votingapi_cache} ADD INDEX (content_id)");
45 $ret[] = update_sql("ALTER TABLE {votingapi_vote} ADD INDEX (content_type)");
46 $ret[] = update_sql("ALTER TABLE {votingapi_vote} ADD INDEX (content_id)");
47
48 $ret[] = db_query("UPDATE {votingapi_cache} SET value_type = 'percent' WHERE value_type = '1'");
49 $ret[] = db_query("UPDATE {votingapi_cache} SET value_type = 'points' WHERE value_type = '2'");
50 $ret[] = db_query("UPDATE {votingapi_cache} SET value_type = 'option' WHERE value_type = '3'");
51
52 $ret[] = db_query("UPDATE {votingapi_vote} SET value_type = 'percent' WHERE value_type = '1'");
53 $ret[] = db_query("UPDATE {votingapi_vote} SET value_type = 'points' WHERE value_type = '2'");
54 $ret[] = db_query("UPDATE {votingapi_vote} SET value_type = 'option' WHERE value_type = '3'");
55
56 break;
57 }
58
59 return $ret;
60 }
61
62 /**
63 * Initial work to roll Voting Actions functionality into Voting API.
64 */
65
66 function votingapi_update_4() {
67 $ret = array();
68 switch ($GLOBALS['db_type']) {
69 case 'mysql':
70 case 'mysqli':
71 $ret[] = update_sql("CREATE TABLE {votingapi_action_set} (
72 vasid int(10) unsigned NOT NULL,
73 parent int(10) unsigned NOT NULL,
74 required int(8) NOT NULL default '0',
75 mask varchar(8) default 'AND',
76 content_type varchar(20) default NULL,
77 name varchar(128) default NULL,
78 enabled int default 1,
79 source varchar(65) default NULL,
80 weight int(10) NOT NULL default 0,
81 PRIMARY KEY (vasid)
82 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
83
84 $ret[] = update_sql("CREATE TABLE {votingapi_action_condition} (
85 vacid int(10) unsigned NOT NULL,
86 vasid int(10) unsigned NOT NULL,
87 weight int(10) NOT NULL default 0,
88 value varchar(255),
89 handler varchar(255) NOT NULL,
90 PRIMARY KEY (vacid)
91 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
92
93 $ret[] = update_sql("CREATE TABLE {votingapi_action} (
94 vasid int(10) unsigned NOT NULL,
95 aid varchar(255) NOT NULL default '0'
96 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
97
98 break;
99 }
100
101 return $ret;
102 }
103
104 /**
105 * Fixed index definition, corrected table prefixes.
106 */
107
108 function votingapi_update_5() {
109 $ret = array();
110 switch ($GLOBALS['db_type']) {
111 case 'mysql':
112 case 'mysqli':
113 $ret[] = update_sql("ALTER TABLE {votingapi_vote} ADD INDEX content (content_type, content_id);");
114 $ret[] = update_sql("ALTER TABLE {votingapi_cache} ADD INDEX content (content_type, content_id);");
115
116 $ret[] = update_sql("ALTER TABLE {votingapi_vote} DROP INDEX content_type;");
117 $ret[] = update_sql("ALTER TABLE {votingapi_vote} DROP INDEX content_id;");
118 $ret[] = update_sql("ALTER TABLE {votingapi_cache} DROP INDEX content_type;");
119 $ret[] = update_sql("ALTER TABLE {votingapi_cache} DROP INDEX content_id;");
120
121 $ret[] = update_sql("RENAME TABLE votingapi_action_condition TO {votingapi_action_condition};");
122 $ret[] = update_sql("RENAME TABLE votingapi_action TO {votingapi_action};");
123
124 $ret[] = update_sql("UPDATE {sequences} SET name = '{votingapi_cache}' WHERE name = 'votingapi_cache';");
125 $ret[] = update_sql("UPDATE {sequences} SET name = '{votingapi_vote}' WHERE name = 'votingapi_vote';");
126
127 break;
128 }
129
130 return $ret;
131 }
132
133 function votingapi_update_6() {
134 $ret = array();
135 switch ($GLOBALS['db_type']) {
136 case 'mysql':
137 case 'mysqli':
138 $ret[] = update_sql("ALTER TABLE {votingapi_action_condition} ADD COLUMN name varchar(128) NOT NULL;");
139 $ret[] = update_sql("ALTER TABLE {votingapi_action_condition} CHANGE value data varchar(255)");
140 $ret[] = update_sql("ALTER TABLE {votingapi_action_set} ADD COLUMN description varchar(255) NOT NULL;");
141 break;
142 }
143
144 return $ret;
145
146 }
147
148
149 function votingapi_update_7() {
150 // There are quite a few changes. Let's just take the easy way and nuke this puppy.
151 // Nothing has been using the tables up to this point, anyhow.
152
153 $ret[] = update_sql("DROP TABLE {votingapi_action_set}");
154 $ret[] = update_sql("DROP TABLE {votingapi_action_condition}");
155 $ret[] = update_sql("DROP TABLE {votingapi_action}");
156
157 $ret[] = update_sql("CREATE TABLE {votingapi_action_set} (
158 name varchar(64) NOT NULL,
159 parent_name varchar(64) default NULL,
160 content_type varchar(20) default NULL,
161 source varchar(64) default NULL,
162 description varchar(255) default NULL,
163 required int(8) NOT NULL default '0',
164 criteria_mask varchar(8) default 'AND',
165 weight int(10) NOT NULL default 0,
166 PRIMARY KEY (name)
167 ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
168
169 $ret[] = update_sql("CREATE TABLE {votingapi_action_condition} (
170 name varchar(64) NOT NULL,
171 parent_name varchar(64) default NULL,
172 description varchar(255) default NULL,
173 weight int(10) NOT NULL default 0,
174 data varchar(255),
175 handler varchar(255) NOT NULL,
176 PRIMARY KEY (name)
177 ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
178
179 $ret[] = update_sql("CREATE TABLE {votingapi_action} (
180 parent_name varchar(64) NOT NULL,
181 aid varchar(255) NOT NULL
182 ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
183
184 return $ret;
185 }
186
187 function votingapi_update_8() {
188 // whoops. mis-named column.
189 $ret = array();
190 $ret[] = update_sql("ALTER TABLE {votingapi_action_set} CHANGE criteria_mask condition_mask varchar(8) DEFAULT 'AND';");
191 return $ret;
192 }
193
194 function votingapi_update_9() {
195 $ret = array();
196 switch ($GLOBALS['db_type']) {
197 case 'mysql':
198 case 'mysqli':
199 $ret[] = update_sql("ALTER TABLE {votingapi_cache} ADD COLUMN timestamp int(11) default NULL;");
200 break;
201 case 'pgsql':
202 $ret[] = update_sql("ALTER TABLE {votingapi_cache} ADD COLUMN timestamp int4 default NULL;");
203 break;
204 }
205 $ret[] = update_sql("UPDATE {votingapi_cache} SET timestamp = " . time() . " WHERE timestamp IS NULL;");
206 return $ret;
207 }
208
209 function _votingapi_update_6001() {
210 $ret = array();
211
212 // Rename the 'hostname' field to 'vote_source' for more flexibility
213 db_change_field($ret, 'votingapi_vote', 'hostname', 'vote_source', array('type' => 'varchar', 'length' => 255));
214
215 // Update fields and indexes
216 db_update_field($ret, 'votingapi_vote', 'vote_id');
217 db_update_field($ret, 'votingapi_vote', 'content_type');
218 db_update_field($ret, 'votingapi_vote', 'content_id');
219 db_update_field($ret, 'votingapi_vote', 'value');
220 db_update_field($ret, 'votingapi_vote', 'value_type');
221 db_update_field($ret, 'votingapi_vote', 'tag');
222 db_update_field($ret, 'votingapi_vote', 'uid');
223 db_update_field($ret, 'votingapi_vote', 'timestamp');
224 db_update_field($ret, 'votingapi_vote', 'vote_source');
225
226 // Update fields and indexes
227 db_update_field($ret, 'votingapi_cache', 'vote_cache_id');
228 db_update_field($ret, 'votingapi_cache', 'content_type');
229 db_update_field($ret, 'votingapi_cache', 'content_id');
230 db_update_field($ret, 'votingapi_cache', 'value');
231 db_update_field($ret, 'votingapi_cache', 'value_type');
232 db_update_field($ret, 'votingapi_cache', 'tag');
233 db_update_field($ret, 'votingapi_cache', 'function');
234 db_update_field($ret, 'votingapi_cache', 'timestamp');
235
236 // Yes, we loves us the SchemaAPI.
237 return $ret;
238 }
239
240 function votingapi_uninstall() {
241 db_query("DROP TABLE {votingapi_vote}");
242 db_query("DROP TABLE {votingapi_cache}");
243 }

  ViewVC Help
Powered by ViewVC 1.1.2