2 // $Id: updates.inc 144 2007-03-28 07:52:20Z thierry $
4 function system_update_110() {
7 // TODO: needs PGSQL version
8 if ($GLOBALS['db_type'] == 'mysql') {
13 $ret[] = update_sql('DROP TABLE {search_index}');
14 $ret[] = update_sql("CREATE TABLE {search_index} (
15 word varchar(50) NOT NULL default '',
16 sid int(10) unsigned NOT NULL default '0',
17 type varchar(16) default NULL,
18 fromsid int(10) unsigned NOT NULL default '0',
19 fromtype varchar(16) default NULL,
20 score int(10) unsigned default NULL,
22 KEY fromsid (fromsid),
26 $ret[] = update_sql("CREATE TABLE {search_total} (
27 word varchar(50) NOT NULL default '',
28 count int(10) unsigned default NULL,
29 PRIMARY KEY word (word)
37 $ret[] = update_sql('ALTER TABLE {blocks} DROP path');
38 $ret[] = update_sql('ALTER TABLE {blocks} ADD visibility tinyint(1) NOT NULL');
39 $ret[] = update_sql('ALTER TABLE {blocks} ADD pages text NOT NULL');
41 elseif ($GLOBALS['db_type'] == 'pgsql') {
45 $ret[] = update_sql('DROP TABLE {search_index}');
46 $ret[] = update_sql("CREATE TABLE {search_index} (
47 word varchar(50) NOT NULL default '',
48 sid integer NOT NULL default '0',
49 type varchar(16) default NULL,
50 fromsid integer NOT NULL default '0',
51 fromtype varchar(16) default NULL,
52 score integer default NULL
54 $ret[] = update_sql("CREATE INDEX {search_index}_sid_idx on {search_index}(sid)");
55 $ret[] = update_sql("CREATE INDEX {search_index}_fromsid_idx on {search_index}(fromsid)");
56 $ret[] = update_sql("CREATE INDEX {search_index}_word_idx on {search_index}(word)");
58 $ret[] = update_sql("CREATE TABLE {search_total} (
59 word varchar(50) NOT NULL default '' PRIMARY KEY,
60 count integer default NULL
67 // Postgres can only drop columns since 7.4
68 #$ret[] = update_sql('ALTER TABLE {blocks} DROP path');
70 $ret[] = update_sql('ALTER TABLE {blocks} ADD visibility smallint');
71 $ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN visibility set default 0");
72 $ret[] = update_sql('UPDATE {blocks} SET visibility = 0');
73 $ret[] = update_sql('ALTER TABLE {blocks} ALTER COLUMN visibility SET NOT NULL');
74 $ret[] = update_sql('ALTER TABLE {blocks} ADD pages text');
75 $ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN pages set default ''");
76 $ret[] = update_sql("UPDATE {blocks} SET pages = ''");
77 $ret[] = update_sql('ALTER TABLE {blocks} ALTER COLUMN pages SET NOT NULL');
81 $ret[] = update_sql("DELETE FROM {variable} WHERE name = 'node_cron_last'");
83 $ret[] = update_sql('UPDATE {blocks} SET status = 1, custom = 2 WHERE status = 0 AND custom = 1');
88 function system_update_111() {
91 $ret[] = update_sql("DELETE FROM {variable} WHERE name LIKE 'throttle_%'");
93 if ($GLOBALS['db_type'] == 'mysql') {
94 $ret[] = update_sql('ALTER TABLE {sessions} ADD PRIMARY KEY sid (sid)');
96 elseif ($GLOBALS['db_type'] == 'pgsql') {
97 $ret[] = update_sql('ALTER TABLE {sessions} ADD UNIQUE(sid)');
103 function system_update_112() {
106 if ($GLOBALS['db_type'] == 'mysql') {
107 $ret[] = update_sql("CREATE TABLE {flood} (
108 event varchar(64) NOT NULL default '',
109 hostname varchar(128) NOT NULL default '',
110 timestamp int(11) NOT NULL default '0'
113 elseif ($GLOBALS['db_type'] == 'pgsql') {
114 $ret[] = update_sql("CREATE TABLE {flood} (
115 event varchar(64) NOT NULL default '',
116 hostname varchar(128) NOT NULL default '',
117 timestamp integer NOT NULL default 0
124 function system_update_113() {
127 if ($GLOBALS['db_type'] == 'mysql') {
128 $ret[] = update_sql('ALTER TABLE {accesslog} ADD aid int(10) NOT NULL auto_increment, ADD PRIMARY KEY (aid)');
130 elseif ($GLOBALS['db_type'] == 'pgsql') {
131 $ret[] = update_sql("SELECT * INTO TEMPORARY {accesslog}_t FROM {accesslog}");
132 $ret[] = update_sql("DROP TABLE {accesslog}");
133 $ret[] = update_sql("CREATE TABLE {accesslog} (
135 title varchar(255) default NULL,
136 path varchar(255) default NULL,
137 url varchar(255) default NULL,
138 hostname varchar(128) default NULL,
139 uid integer default '0',
140 timestamp integer NOT NULL default '0'
142 $ret[] = update_sql("INSERT INTO {accesslog} (title, path, url, hostname, uid, timestamp) SELECT title, path, url, hostname, uid, timestamp FROM {accesslog}_t");
144 $ret[] = update_sql("DROP TABLE {accesslog}_t");
145 $ret[] = update_sql("CREATE INDEX {accesslog}_timestamp_idx ON {accesslog} (timestamp);");
149 // Flush the menu cache:
150 cache_clear_all('menu:', TRUE);
155 function system_update_114() {
157 if ($GLOBALS['db_type'] == 'mysql') {
158 $ret[] = update_sql("CREATE TABLE {queue} (
159 nid int(10) unsigned NOT NULL,
160 uid int(10) unsigned NOT NULL,
161 vote int(3) NOT NULL default '0',
162 PRIMARY KEY (nid, uid)
165 else if ($GLOBALS['db_type'] == 'pgsql') {
166 $ret[] = update_sql("CREATE TABLE {queue} (
167 nid integer NOT NULL default '0',
168 uid integer NOT NULL default '0',
169 vote integer NOT NULL default '0',
170 PRIMARY KEY (nid, uid)
172 $ret[] = update_sql("CREATE INDEX {queue}_nid_idx ON queue(nid)");
173 $ret[] = update_sql("CREATE INDEX {queue}_uid_idx ON queue(uid)");
176 $result = db_query("SELECT nid, votes, score, users FROM {node}");
177 while ($node = db_fetch_object($result)) {
178 if (isset($node->users)) {
179 $arr = explode(',', $node->users);
181 foreach ($arr as $value) {
182 $arr2 = explode('=', trim($value));
183 if (isset($arr2[0]) && isset($arr2[1])) {
186 db_query("INSERT INTO {queue} (nid, uid, vote) VALUES (%d, %d, %d)", $node->nid, (int)$arr2[0], 1);
189 db_query("INSERT INTO {queue} (nid, uid, vote) VALUES (%d, %d, %d)", $node->nid, (int)$arr2[0], -1);
192 db_query("INSERT INTO {queue} (nid, uid, vote) VALUES (%d, %d, %d)", $node->nid, (int)$arr2[0], 0);
199 if ($GLOBALS['db_type'] == 'mysql') {
200 // Postgres only supports dropping of columns since 7.4
201 $ret[] = update_sql("ALTER TABLE {node} DROP votes");
202 $ret[] = update_sql("ALTER TABLE {node} DROP score");
203 $ret[] = update_sql("ALTER TABLE {node} DROP users");
209 function system_update_115() {
212 // This update has been moved to update_fix_watchdog_115 in update.php because it
213 // is needed for the basic functioning of the update script.
218 function system_update_116() {
219 return array(update_sql("DELETE FROM {system} WHERE name = 'admin'"));
222 function system_update_117() {
224 if ($GLOBALS['db_type'] == 'mysql') {
225 $ret[] = update_sql("CREATE TABLE {vocabulary_node_types} (
226 vid int(10) NOT NULL default '0',
227 type varchar(16) NOT NULL default '',
228 PRIMARY KEY (vid, type))");
230 else if ($GLOBALS['db_type'] == 'pgsql') {
231 $ret[] = update_sql("CREATE TABLE {vocabulary_node_types} (
233 type varchar(16) NOT NULL default '',
234 PRIMARY KEY (vid, type)) ");
239 function system_update_118() {
241 $node_types = array();
242 $result = db_query('SELECT vid, nodes FROM {vocabulary}');
243 while ($vocabulary = db_fetch_object($result)) {
244 $node_types[$vocabulary->vid] = explode(',', $vocabulary->nodes);
246 foreach ($node_types as $vid => $type_array) {
247 foreach ($type_array as $type) {
248 db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $vid, $type);
251 if ($GLOBALS['db_type'] == 'mysql') {
252 $ret[] = update_sql("ALTER TABLE {vocabulary} DROP nodes");
257 function system_update_119() {
260 foreach (node_get_types() as $type => $name) {
261 $node_options = array();
262 if (variable_get('node_status_'. $type, 1)) {
263 $node_options[] = 'status';
265 if (variable_get('node_moderate_'. $type, 0)) {
266 $node_options[] = 'moderate';
268 if (variable_get('node_promote_'. $type, 1)) {
269 $node_options[] = 'promote';
271 if (variable_get('node_sticky_'. $type, 0)) {
272 $node_options[] = 'sticky';
274 if (variable_get('node_revision_'. $type, 0)) {
275 $node_options[] = 'revision';
277 variable_set('node_options_'. $type, $node_options);
278 variable_del('node_status_'. $type);
279 variable_del('node_moderate_'. $type);
280 variable_del('node_promote_'. $type);
281 variable_del('node_sticky_'. $type);
282 variable_del('node_revision_'. $type);
288 function system_update_120() {
291 // Rewrite old URL aliases. Works for both PostgreSQL and MySQL
292 $result = db_query("SELECT pid, src FROM {url_alias} WHERE src LIKE 'blog/%%'");
293 while ($alias = db_fetch_object($result)) {
294 list(, $page, $op, $uid) = explode('/', $alias->src);
295 if ($page == 'feed') {
296 $new = "blog/$uid/feed";
297 update_sql("UPDATE {url_alias} SET src = '%s' WHERE pid = '%s'", $new, $alias->pid);
304 function system_update_121() {
307 // Remove the unused page table.
308 $ret[] = update_sql('DROP TABLE {page}');
313 function system_update_122() {
316 $ret[] = update_sql("ALTER TABLE {blocks} ADD types text");
321 function system_update_123() {
324 if ($GLOBALS['db_type'] == 'mysql') {
325 $ret[] = update_sql("ALTER TABLE {vocabulary} ADD module varchar(255) NOT NULL default ''");
327 elseif ($GLOBALS['db_type'] == 'pgsql') {
328 $ret[] = update_sql("ALTER TABLE {vocabulary} ADD module varchar(255)");
329 $ret[] = update_sql("UPDATE {vocabulary} SET module = ''");
330 $ret[] = update_sql("ALTER TABLE {vocabulary} ALTER COLUMN module SET NOT NULL");
331 $ret[] = update_sql("ALTER TABLE {vocabulary} ALTER COLUMN module SET DEFAULT ''");
334 $ret[] = update_sql("UPDATE {vocabulary} SET module = 'taxonomy'");
335 $vid = variable_get('forum_nav_vocabulary', '');
337 $ret[] = update_sql("UPDATE {vocabulary} SET module = 'forum' WHERE vid = " . $vid);
343 function system_update_124() {
346 if ($GLOBALS['db_type'] == 'mysql') {
347 // redo update_105, correctly creating node_comment_statistics
348 $ret[] = update_sql("DROP TABLE IF EXISTS {node_comment_statistics}");
350 $ret[] = update_sql("CREATE TABLE {node_comment_statistics} (
351 nid int(10) unsigned NOT NULL auto_increment,
352 last_comment_timestamp int(11) NOT NULL default '0',
353 last_comment_name varchar(60) default NULL,
354 last_comment_uid int(10) NOT NULL default '0',
355 comment_count int(10) unsigned NOT NULL default '0',
357 KEY node_comment_timestamp (last_comment_timestamp)
362 // also drop incorrectly named table for PostgreSQL
363 $ret[] = update_sql("DROP TABLE {node}_comment_statistics");
365 $ret[] = update_sql("CREATE TABLE {node_comment_statistics} (
366 nid integer NOT NULL,
367 last_comment_timestamp integer NOT NULL default '0',
368 last_comment_name varchar(60) default NULL,
369 last_comment_uid integer NOT NULL default '0',
370 comment_count integer NOT NULL default '0',
374 $ret[] = update_sql("CREATE INDEX {node_comment_statistics}_timestamp_idx ON {node_comment_statistics}(last_comment_timestamp);
379 $ret[] = update_sql("INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) SELECT n.nid, n.changed, NULL, 0, 0 FROM {node} n");
382 $result = db_query("SELECT c.nid, c.timestamp, c.name, c.uid, COUNT(c.nid) as comment_count FROM {node} n LEFT JOIN {comments} c ON c.nid = n.nid WHERE c.status = 0 GROUP BY c.nid, c.timestamp, c.name, c.uid");
383 while ($comment_record = db_fetch_object($result)) {
384 $count = db_result(db_query('SELECT COUNT(cid) FROM {comments} WHERE nid = %d AND status = 0', $comment_record->nid));
385 db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", $count, $comment_record->timestamp, $comment_record->name, $comment_record->uid, $comment_record->nid);
391 function system_update_125() {
392 // Postgres only update.
395 if ($GLOBALS['db_type'] == 'pgsql') {
397 $ret[] = update_sql("CREATE OR REPLACE FUNCTION if(boolean, anyelement, anyelement) RETURNS anyelement AS '
398 SELECT CASE WHEN $1 THEN $2 ELSE $3 END;
401 $ret[] = update_sql("CREATE FUNCTION greatest(integer, integer, integer) RETURNS integer AS '
402 SELECT greatest($1, greatest($2, $3));
410 function system_update_126() {
411 variable_set('forum_block_num_0', variable_get('forum_block_num', 5));
412 variable_set('forum_block_num_1', variable_get('forum_block_num', 5));
413 variable_del('forum_block_num');
418 function system_update_127() {
420 if ($GLOBALS['db_type'] == 'pgsql') {
421 $ret[] = update_sql("ALTER TABLE {poll} RENAME voters TO polled");
423 else if ($GLOBALS['db_type'] == 'mysql') {
424 $ret[] = update_sql("ALTER TABLE {poll} CHANGE voters polled longtext");
429 function system_update_128() {
432 if ($GLOBALS['db_type'] == 'mysql') {
433 $ret[] = update_sql('ALTER TABLE {term_node} ADD PRIMARY KEY (tid,nid)');
435 elseif ($GLOBALS['db_type'] == 'pgsql') {
436 $ret[] = update_sql('ALTER TABLE {term_node} ADD PRIMARY KEY (tid,nid)');
442 function system_update_129() {
445 if ($GLOBALS['db_type'] == 'mysql') {
446 $ret[] = update_sql("ALTER TABLE {vocabulary} ADD tags tinyint(3) unsigned default '0' NOT NULL");
448 elseif ($GLOBALS['db_type'] == 'pgsql') {
449 db_add_column($ret, 'vocabulary', 'tags', 'smallint', array('default' => 0, 'not null' => TRUE));
455 function system_update_130() {
458 // This update has been moved to update_fix_sessions in update.php because it
459 // is needed for the basic functioning of the update script.
464 function system_update_131() {
467 if ($GLOBALS['db_type'] == 'mysql') {
468 $ret[] = update_sql("ALTER TABLE {boxes} DROP INDEX title");
469 // Removed recreation of the index, which is not present in the db schema
471 elseif ($GLOBALS['db_type'] == 'pgsql') {
472 $ret[] = update_sql("ALTER TABLE {boxes} DROP CONSTRAINT {boxes}_title_key");
478 function system_update_132() {
480 * PostgreSQL only update.
484 if (!variable_get('update_132_done', FALSE)) {
485 if ($GLOBALS['db_type'] == 'pgsql') {
486 $ret[] = update_sql('DROP TABLE {search_total}');
487 $ret[] = update_sql("CREATE TABLE {search_total} (
488 word varchar(50) NOT NULL default '',
489 count float default NULL)");
490 $ret[] = update_sql('CREATE INDEX {search_total}_word_idx ON {search_total}(word)');
493 * Wipe the search index
495 include_once './modules/search.module';
499 variable_del('update_132_done');
505 function system_update_133() {
508 if ($GLOBALS['db_type'] == 'mysql') {
509 $ret[] = update_sql("CREATE TABLE {contact} (
510 subject varchar(255) NOT NULL default '',
511 recipients longtext NOT NULL default '',
512 reply longtext NOT NULL default ''
514 $ret[] = update_sql("ALTER TABLE {users} ADD login int(11) NOT NULL default '0'");
516 elseif ($GLOBALS['db_type'] == 'pgsql') {
517 // Table {contact} is changed in update_143() so I have moved it's creation there.
518 // It was never created here for postgres because of errors.
520 db_add_column($ret, 'users', 'login', 'int', array('default' => 0, 'not null' => TRUE));
526 function system_update_134() {
528 $ret[] = update_sql('ALTER TABLE {blocks} DROP types');
532 function system_update_135() {
533 if (!variable_get('update_135_done', FALSE)) {
534 $result = db_query("SELECT delta FROM {blocks} WHERE module = 'aggregator'");
535 while ($block = db_fetch_object($result)) {
536 list($type, $id) = explode(':', $block->delta);
537 db_query("UPDATE {blocks} SET delta = '%s' WHERE module = 'aggregator' AND delta = '%s'", $type .'-'. $id, $block->delta);
540 variable_del('update_135_done');
545 function system_update_136() {
548 switch ($GLOBALS['db_type']) {
550 $ret[] = update_sql("DROP INDEX {users}_changed_idx"); // We drop the index first because it won't be renamed
551 $ret[] = update_sql("ALTER TABLE {users} RENAME changed TO access");
552 $ret[] = update_sql("CREATE INDEX {users}_access_idx on {users}(access)"); // Re-add the index
556 $ret[] = update_sql("ALTER TABLE {users} CHANGE COLUMN changed access int(11) NOT NULL default '0'");
560 $ret[] = update_sql('UPDATE {users} SET access = login WHERE login > created');
561 $ret[] = update_sql('UPDATE {users} SET access = created WHERE access = 0');
565 function system_update_137() {
568 if (!variable_get('update_137_done', FALSE)) {
569 if ($GLOBALS['db_type'] == 'mysql') {
570 $ret[] = update_sql("ALTER TABLE {locales_source} CHANGE location location varchar(255) NOT NULL default ''");
572 elseif ($GLOBALS['db_type'] == 'pgsql') {
573 db_change_column($ret, 'locales_source', 'location', 'location', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
575 variable_del('update_137_done');
581 function system_update_138() {
583 // duplicate of update_97 which never got into the default database.* files.
584 $ret[] = update_sql("INSERT INTO {url_alias} (src, dst) VALUES ('node/feed', 'rss.xml')");
588 function system_update_139() {
590 switch ($GLOBALS['db_type']) {
592 db_add_column($ret, 'accesslog', 'timer', 'int', array('not null' => TRUE, 'default' => 0));
596 $ret[] = update_sql("ALTER TABLE {accesslog} ADD timer int(10) unsigned NOT NULL default '0'");
603 function system_update_140() {
606 if ($GLOBALS['db_type'] == 'mysql') {
607 $ret[] = update_sql("ALTER TABLE {url_alias} ADD INDEX (src)");
609 elseif ($GLOBALS['db_type'] == 'pgsql') {
610 $ret[] = update_sql("CREATE INDEX {url_alias}_src_idx ON {url_alias}(src)");
615 function system_update_141() {
618 variable_del('upload_maxsize_total');
623 function system_update_142() {
626 // This update has been moved to update_fix_sessions in update.php because it
627 // is needed for the basic functioning of the update script.
632 function system_update_143() {
635 if ($GLOBALS['db_type'] == 'mysql') {
636 $ret[] = update_sql("ALTER TABLE {contact} CHANGE subject category VARCHAR(255) NOT NULL ");
637 $ret[] = update_sql("ALTER TABLE {contact} ADD PRIMARY KEY (category)");
639 elseif ($GLOBALS['db_type'] == 'pgsql') {
640 // Why the table is created here? See update_133().
641 $ret[] = update_sql("CREATE TABLE {contact} (
642 category varchar(255) NOT NULL default '',
643 recipients text NOT NULL default '',
644 reply text NOT NULL default '',
645 PRIMARY KEY (category))");
651 function system_update_144() {
653 if ($GLOBALS['db_type'] == 'mysql') {
654 $ret[] = update_sql("ALTER TABLE {node} CHANGE type type VARCHAR(32) NOT NULL");
656 elseif ($GLOBALS['db_type'] == 'pgsql') {
657 $ret[] = update_sql("DROP INDEX {node}_type_idx"); // Drop indexes using "type" column
658 $ret[] = update_sql("DROP INDEX {node}_title_idx");
659 db_change_column($ret, 'node', 'type', 'type', 'varchar(32)', array('not null' => TRUE, 'default' => "''"));
660 // Let's recreate the indexes
661 $ret[] = update_sql("CREATE INDEX {node}_type_idx ON {node}(type)");
662 $ret[] = update_sql("CREATE INDEX {node}_title_type_idx ON {node}(title,type)");
663 $ret[] = update_sql("CREATE INDEX {node}_status_type_nid_idx ON {node}(status,type,nid)");
668 function system_update_145() {
669 $default_theme = variable_get('theme_default', 'bluemarine');
671 $themes = list_themes();
672 if (!array_key_exists($default_theme, $themes)) {
673 variable_set('theme_default', 'bluemarine');
674 $default_theme = 'bluemarine';
679 switch ($GLOBALS['db_type']) {
681 db_change_column($ret, 'blocks', 'region', 'region', 'varchar(64)', array('default' => "'left'", 'not null' => TRUE));
682 db_add_column($ret, 'blocks', 'theme', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
686 $ret[] = update_sql("ALTER TABLE {blocks} CHANGE region region varchar(64) default 'left' NOT NULL");
687 $ret[] = update_sql("ALTER TABLE {blocks} ADD theme varchar(255) NOT NULL default ''");
691 // Intialize block data for default theme
692 $ret[] = update_sql("UPDATE {blocks} SET region = 'left' WHERE region = '0'");
693 $ret[] = update_sql("UPDATE {blocks} SET region = 'right' WHERE region = '1'");
694 db_query("UPDATE {blocks} SET theme = '%s'", $default_theme);
696 // Initialze block data for other enabled themes.
697 $themes = list_themes();
698 foreach (array_keys($themes) as $theme) {
699 if (($theme != $default_theme) && $themes[$theme]->status == 1) {
700 system_initialize_theme_blocks($theme);
707 function system_update_146() {
710 if ($GLOBALS['db_type'] == 'mysql') {
711 $ret[] = update_sql("CREATE TABLE {node_revisions}
712 SELECT nid, nid AS vid, uid, type, title, body, teaser, changed AS timestamp, format
715 $ret[] = update_sql("ALTER TABLE {node_revisions} CHANGE nid nid int(10) unsigned NOT NULL default '0'");
716 $ret[] = update_sql("ALTER TABLE {node_revisions} ADD log longtext");
718 $ret[] = update_sql("ALTER TABLE {node} ADD vid int(10) unsigned NOT NULL default '0'");
719 $ret[] = update_sql("ALTER TABLE {files} ADD vid int(10) unsigned NOT NULL default '0'");
720 $ret[] = update_sql("ALTER TABLE {book} ADD vid int(10) unsigned NOT NULL default '0'");
721 $ret[] = update_sql("ALTER TABLE {forum} ADD vid int(10) unsigned NOT NULL default '0'");
723 $ret[] = update_sql("ALTER TABLE {book} DROP PRIMARY KEY");
724 $ret[] = update_sql("ALTER TABLE {forum} DROP PRIMARY KEY");
725 $ret[] = update_sql("ALTER TABLE {files} DROP PRIMARY KEY");
727 $ret[] = update_sql("UPDATE {node} SET vid = nid");
728 $ret[] = update_sql("UPDATE {forum} SET vid = nid");
729 $ret[] = update_sql("UPDATE {book} SET vid = nid");
730 $ret[] = update_sql("UPDATE {files} SET vid = nid");
732 $ret[] = update_sql("ALTER TABLE {book} ADD PRIMARY KEY vid (vid)");
733 $ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY vid (vid)");
734 $ret[] = update_sql("ALTER TABLE {node_revisions} ADD PRIMARY KEY vid (vid)");
735 $ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY nid (nid)");
736 $ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY uid (uid)");
738 $ret[] = update_sql("CREATE TABLE {old_revisions} SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
740 $ret[] = update_sql("ALTER TABLE {book} ADD KEY nid (nid)");
741 $ret[] = update_sql("ALTER TABLE {forum} ADD KEY nid (nid)");
742 $ret[] = update_sql("ALTER TABLE {files} ADD KEY fid (fid)");
743 $ret[] = update_sql("ALTER TABLE {files} ADD KEY vid (vid)");
744 $vid = db_next_id('{node}_nid');
745 $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{node_revisions}_vid', $vid)");
748 $ret[] = update_sql("CREATE TABLE {node_revisions} (
749 nid integer NOT NULL default '0',
750 vid integer NOT NULL default '0',
751 uid integer NOT NULL default '0',
752 title varchar(128) NOT NULL default '',
753 body text NOT NULL default '',
754 teaser text NOT NULL default '',
755 log text NOT NULL default '',
756 timestamp integer NOT NULL default '0',
757 format int NOT NULL default '0',
758 PRIMARY KEY (vid))");
759 $ret[] = update_sql("INSERT INTO {node_revisions} (nid, vid, uid, title, body, teaser, timestamp, format)
760 SELECT nid, nid AS vid, uid, title, body, teaser, changed AS timestamp, format
762 $ret[] = update_sql('CREATE INDEX {node_revisions}_nid_idx ON {node_revisions}(nid)');
763 $ret[] = update_sql('CREATE INDEX {node_revisions}_uid_idx ON {node_revisions}(uid)');
764 $vid = db_next_id('{node}_nid');
765 $ret[] = update_sql("CREATE SEQUENCE {node_revisions}_vid_seq INCREMENT 1 START $vid");
767 db_add_column($ret, 'node', 'vid', 'int', array('not null' => TRUE, 'default' => 0));
768 db_add_column($ret, 'files', 'vid', 'int', array('not null' => TRUE, 'default' => 0));
769 db_add_column($ret, 'book', 'vid', 'int', array('not null' => TRUE, 'default' => 0));
770 db_add_column($ret, 'forum', 'vid', 'int', array('not null' => TRUE, 'default' => 0));
772 $ret[] = update_sql("ALTER TABLE {book} DROP CONSTRAINT {book}_pkey");
773 $ret[] = update_sql("ALTER TABLE {forum} DROP CONSTRAINT {forum}_pkey");
774 $ret[] = update_sql("ALTER TABLE {files} DROP CONSTRAINT {files}_pkey");
776 $ret[] = update_sql("UPDATE {node} SET vid = nid");
777 $ret[] = update_sql("UPDATE {forum} SET vid = nid");
778 $ret[] = update_sql("UPDATE {book} SET vid = nid");
779 $ret[] = update_sql("UPDATE {files} SET vid = nid");
781 $ret[] = update_sql("ALTER TABLE {book} ADD PRIMARY KEY (vid)");
782 $ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY (vid)");
784 $ret[] = update_sql("CREATE TABLE {old_revisions} AS SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
786 $ret[] = update_sql('CREATE INDEX {node}_vid_idx ON {node}(vid)');
787 $ret[] = update_sql('CREATE INDEX {forum}_nid_idx ON {forum}(nid)');
788 $ret[] = update_sql('CREATE INDEX {files}_fid_idx ON {files}(fid)');
789 $ret[] = update_sql('CREATE INDEX {files}_vid_idx ON {files}(vid)');
793 $result = db_query("SELECT nid, log FROM {book} WHERE log != ''");
794 while ($row = db_fetch_object($result)) {
795 db_query("UPDATE {node_revisions} SET log = '%s' WHERE vid = %d", $row->log, $row->nid);
798 $ret[] = update_sql("ALTER TABLE {book} DROP log");
799 $ret[] = update_sql("ALTER TABLE {node} DROP teaser");
800 $ret[] = update_sql("ALTER TABLE {node} DROP body");
801 $ret[] = update_sql("ALTER TABLE {node} DROP format");
802 $ret[] = update_sql("ALTER TABLE {node} DROP revisions");
807 function system_update_147() {
810 // this update is mysql only, pgsql should get it right in the first try.
811 if ($GLOBALS['db_type'] == 'mysql') {
812 $ret[] = update_sql("ALTER TABLE {node_revisions} DROP type");
818 function system_update_148() {
821 // Add support for tracking users' session ids (useful for tracking anon users)
822 switch ($GLOBALS['db_type']) {
824 db_add_column($ret, 'accesslog', 'sid', 'varchar(32)', array('not null' => TRUE, 'default' => "''"));
828 $ret[] = update_sql("ALTER TABLE {accesslog} ADD sid varchar(32) NOT NULL default ''");
835 function system_update_149() {
838 switch ($GLOBALS['db_type']) {
840 db_add_column($ret, 'files', 'description', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
844 $ret[] = update_sql("ALTER TABLE {files} ADD COLUMN description VARCHAR(255) NOT NULL DEFAULT ''");
853 function system_update_150() {
856 $ret[] = update_sql("DELETE FROM {variable} WHERE name = 'node_cron_last'");
857 $ret[] = update_sql("DELETE FROM {variable} WHERE name = 'minimum_word_size'");
858 $ret[] = update_sql("DELETE FROM {variable} WHERE name = 'remove_short'");
860 $ret[] = update_sql("DELETE FROM {node_counter} WHERE nid = 0");
862 $ret[] = update_sql('DROP TABLE {search_index}');
863 $ret[] = update_sql('DROP TABLE {search_total}');
865 switch ($GLOBALS['db_type']) {
868 $ret[] = update_sql("CREATE TABLE {search_dataset} (
869 sid int(10) unsigned NOT NULL default '0',
870 type varchar(16) default NULL,
871 data longtext NOT NULL,
872 KEY sid_type (sid, type)
875 $ret[] = update_sql("CREATE TABLE {search_index} (
876 word varchar(50) NOT NULL default '',
877 sid int(10) unsigned NOT NULL default '0',
878 type varchar(16) default NULL,
879 fromsid int(10) unsigned NOT NULL default '0',
880 fromtype varchar(16) default NULL,
881 score float default NULL,
882 KEY sid_type (sid, type),
883 KEY from_sid_type (fromsid, fromtype),
887 $ret[] = update_sql("CREATE TABLE {search_total} (
888 word varchar(50) NOT NULL default '',
889 count float default NULL,
890 PRIMARY KEY word (word)
894 $ret[] = update_sql("CREATE TABLE {search_dataset} (
895 sid integer NOT NULL default '0',
896 type varchar(16) default NULL,
897 data text NOT NULL default '')");
898 $ret[] = update_sql("CREATE INDEX {search_dataset}_sid_type_idx ON {search_dataset}(sid, type)");
900 $ret[] = update_sql("CREATE TABLE {search_index} (
901 word varchar(50) NOT NULL default '',
902 sid integer NOT NULL default '0',
903 type varchar(16) default NULL,
904 fromsid integer NOT NULL default '0',
905 fromtype varchar(16) default NULL,
906 score float default NULL)");
907 $ret[] = update_sql("CREATE INDEX {search_index}_sid_type_idx ON {search_index}(sid, type)");
908 $ret[] = update_sql("CREATE INDEX {search_index}_fromsid_fromtype_idx ON {search_index}(fromsid, fromtype)");
909 $ret[] = update_sql("CREATE INDEX {search_index}_word_idx ON {search_index}(word)");
911 $ret[] = update_sql("CREATE TABLE {search_total} (
912 word varchar(50) NOT NULL default '',
913 count float default NULL,
914 PRIMARY KEY(word))");
922 function system_update_151() {
925 $ts = variable_get('theme_settings', null);
927 // set up data array so we can loop over both sets of links
928 $menus = array(0 => array('links_var' => 'primary_links',
929 'toggle_var' => 'toggle_primary_links',
930 'more_var' => 'primary_links_more',
931 'menu_name' => 'Primary links',
932 'menu_var' => 'menu_primary_menu',
934 1 => array('links_var' => 'secondary_links',
935 'toggle_var' => 'toggle_secondary_links',
936 'more_var' => 'secondary_links_more',
937 'menu_name' => 'Secondary links',
938 'menu_var' => 'menu_secondary_menu',
941 for ($loop = 0; $loop <= 1 ; $loop ++) {
942 // create new Primary and Secondary links menus
943 $menus[$loop]['pid'] = db_next_id('{menu}_mid');
944 $ret[] = update_sql("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) " .
945 "VALUES ({$menus[$loop]['pid']}, 0, '', '{$menus[$loop]['menu_name']}', '', 0, 115)");
947 // Gather links from various settings into a single array.
948 $phptemplate_links = variable_get("phptemplate_". $menus[$loop]['links_var'], array());
949 if (empty($phptemplate_links)) {
950 $phptemplate_links = array('text' => array(), 'link' => array());
952 if (isset($ts) && is_array($ts)) {
953 if (is_array($ts[$menus[$loop]['links_var']])) {
954 $theme_links = $ts[$menus[$loop]['links_var']];
957 // Convert old xtemplate style links.
958 preg_match_all('/<a\s+.*?href=[\"\'\s]?(.*?)[\"\'\s]?>(.*?)<\/a>/i', $ts[$menus[$loop]['links_var']], $urls);
959 $theme_links['text'] = $urls[2];
960 $theme_links['link'] = $urls[1];
964 $theme_links = array('text' => array(), 'link' => array());
966 $links['text'] = array_merge($phptemplate_links['text'], $theme_links['text']);
967 $links['link'] = array_merge($phptemplate_links['link'], $theme_links['link']);
969 // insert all entries from theme links into new menus
971 for ($i = 0; $i < count($links['text']); $i++) {
972 if ($links['text'][$i] != "" && $links['link'][$i] != "") {
974 $node_unalias = db_fetch_array(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $links['link'][$i]));
975 if (isset($node_unalias) && is_array($node_unalias)) {
976 $link_path = $node_unalias['src'];
979 $link_path = $links['link'][$i];
982 $mid = db_next_id('{menu}_mid');
983 $ret[] = update_sql("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) " .
984 "VALUES ($mid, {$menus[$loop]['pid']}, '" . db_escape_string($link_path) .
985 "', '" . db_escape_string($links['text'][$i]) .
986 "', '" . db_escape_string($links['description'][$i]) . "', 0, 118)");
989 // delete Secondary links if not populated.
990 if ($loop == 1 && $num_inserted == 0) {
991 db_query("DELETE FROM {menu} WHERE mid={$menus[$loop]['pid']}");
994 // Set menu_primary_menu and menu_primary_menu variables if links were
995 // imported. If the user had links but the toggle display was off, they
996 // will need to disable the new links manually in admins/settings/menu.
997 if ($num_inserted == 0) {
998 variable_set($menus[$loop]['menu_var'], 0);
1001 variable_set($menus[$loop]['menu_var'], $menus[$loop]['pid']);
1003 variable_del('phptemplate_' .$menus[$loop]['links_var']);
1004 variable_del('phptemplate_'. $menus[$loop]['links_var'] .'_more');
1005 variable_del($menus[$loop]['toggle_var']);
1006 variable_del($menus[$loop]['more_var']);
1007 // If user has old xtemplate links in a string, leave them in the var.
1008 if (isset($ts) && is_array($ts) && is_array($ts[$menus[$loop]['links_var']])) {
1009 variable_del($menus[$loop]['links_var']);
1013 if (isset($ts) && is_array($ts)) {
1014 variable_set('theme_settings', $ts);
1017 $ret[] = update_sql("UPDATE {system} SET status = 1 WHERE name = 'menu'");
1022 function system_update_152() {
1025 // Postgresql only update
1026 switch ($GLOBALS['db_type']) {
1028 $ret[] = update_sql("ALTER TABLE {forum} DROP shadow");
1038 function system_update_153(){
1040 switch ($GLOBALS['db_type']) {
1042 $ret[] = update_sql("ALTER TABLE {contact} DROP CONSTRAINT {contact}_pkey");
1043 $ret[] = update_sql("CREATE SEQUENCE {contact}_cid_seq");
1044 db_add_column($ret, 'contact', 'cid', 'int', array('not null' => TRUE, 'default' => "nextval('{contact}_cid_seq')"));
1045 $ret[] = update_sql("ALTER TABLE {contact} ADD PRIMARY KEY (cid)");
1046 $ret[] = update_sql("ALTER TABLE {contact} ADD CONSTRAINT {contact}_category_key UNIQUE (category)");
1050 $ret[] = update_sql("ALTER TABLE {contact} DROP PRIMARY KEY");
1051 $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN cid int(11) NOT NULL PRIMARY KEY auto_increment");
1052 $ret[] = update_sql("ALTER TABLE {contact} ADD UNIQUE KEY category (category)");
1058 function system_update_154() {
1060 switch ($GLOBALS['db_type']) {
1062 db_add_column($ret, 'contact', 'weight', 'smallint', array('not null' => TRUE, 'default' => 0));
1063 db_add_column($ret, 'contact', 'selected', 'smallint', array('not null' => TRUE, 'default' => 0));
1067 $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN weight tinyint(3) NOT NULL DEFAULT 0");
1068 $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN selected tinyint(1) NOT NULL DEFAULT 0");
1074 function system_update_155() {
1077 // Postgresql only update
1078 switch ($GLOBALS['db_type']) {
1080 $ret[] = update_sql("DROP TABLE {cache}");
1081 $ret[] = update_sql("CREATE TABLE {cache} (
1082 cid varchar(255) NOT NULL default '',
1083 data bytea default '',
1084 expire integer NOT NULL default '0',
1085 created integer NOT NULL default '0',
1086 headers text default '',
1089 $ret[] = update_sql("CREATE INDEX {cache}_expire_idx ON {cache}(expire)");
1099 function system_update_156() {
1101 $ret[] = update_sql("DELETE FROM {cache}");
1106 function system_update_157() {
1108 $ret[] = update_sql("DELETE FROM {url_alias} WHERE src = 'node/feed' AND dst = 'rss.xml'");
1109 $ret[] = update_sql("INSERT INTO {url_alias} (src, dst) VALUES ('rss.xml', 'node/feed')");
1113 function system_update_158() {
1116 switch ($GLOBALS['db_type']) {
1119 $ret[] = update_sql("ALTER TABLE {old_revisions} ADD done tinyint(1) NOT NULL DEFAULT 0");
1120 $ret[] = update_sql("ALTER TABLE {old_revisions} ADD INDEX (done)");
1124 db_add_column($ret, 'old_revisions', 'done', 'smallint', array('not null' => TRUE, 'default' => 0));
1125 $ret[] = update_sql('CREATE INDEX {old_revisions}_done_idx ON {old_revisions}(done)');
1133 * Retrieve data out of the old_revisions table and put into new revision
1136 * The old_revisions table is not deleted because any data which could not be
1137 * put into the new system is retained.
1139 function system_update_159() {
1142 $result = db_query_range("SELECT * FROM {old_revisions} WHERE done = 0 AND type IN ('page', 'story', 'poll', 'book', 'forum', 'blog') ORDER BY nid DESC", 0, 20);
1144 if (db_num_rows($result)) {
1145 $vid = db_next_id('{node_revisions}_vid');
1146 while ($node = db_fetch_object($result)) {
1147 $revisions = unserialize($node->revisions);
1148 if (isset($revisions) && is_array($revisions) && count($revisions) > 0) {
1149 $revisions_query = array();
1150 $revisions_args = array();
1151 $book_query = array();
1152 $book_args = array();
1153 $forum_query = array();
1154 $forum_args = array();
1155 foreach ($revisions as $version) {
1156 $revision = array();
1157 foreach ($version['node'] as $node_field => $node_value) {
1158 $revision[$node_field] = $node_value;
1160 $revision['uid'] = $version['uid'];
1161 $revision['timestamp'] = $version['timestamp'];
1163 $revisions_query[] = "(%d, %d, %d, '%s', '%s', '%s', '%s', %d, %d)";
1164 $revisions_args = array_merge($revisions_args, array($node->nid, $vid, $revision['uid'], $revision['title'], $revision['body'], $revision['teaser'], $revision['log'], $revision['timestamp'], $revision['format']));
1165 switch ($node->type) {
1167 if ($revision['tid'] > 0) {
1168 $forum_query[] = "(%d, %d, %d)";
1169 $forum_args = array_merge($forum_args, array($vid, $node->nid, $revision['tid']));
1174 $book_query[] = "(%d, %d, %d, %d)";
1175 $book_args = array_merge($book_args, array($vid, $node->nid, $revision['parent'], $revision['weight']));
1179 if (count($revisions_query)) {
1180 $revision_status = db_query("INSERT INTO {node_revisions} (nid, vid, uid, title, body, teaser, log, timestamp, format) VALUES ". implode(',', $revisions_query), $revisions_args);
1182 if (count($forum_query)) {
1183 $forum_status = db_query("INSERT INTO {forum} (vid, nid, tid) VALUES ". implode(',', $forum_query), $forum_args);
1185 if (count($book_query)) {
1186 $book_status = db_query("INSERT INTO {book} (vid, nid, parent, weight) VALUES ". implode(',', $book_query), $book_args);
1189 switch ($node->type) {
1191 if ($forum_status && $revision_status) {
1197 if ($book_status && $revision_status) {
1203 if ($revision_status) {
1210 db_query('DELETE FROM {old_revisions} WHERE nid = %d', $node->nid);
1213 db_query('UPDATE {old_revisions} SET done = 1 WHERE nid = %d', $node->nid);
1216 switch ($GLOBALS['db_type']) {
1219 $ret[] = update_sql("UPDATE {sequences} SET id = $vid WHERE name = '{node_revisions}_vid'");
1223 $ret[] = update_sql("SELECT setval('{node_revisions}_vid_seq', $vid)");
1228 db_query('UPDATE {old_revisions} SET done = 1 WHERE nid = %d', $node->nid);
1229 watchdog('php', "Recovering old revisions for node $node->nid failed.", WATCHDOG_WARNING);
1234 if (db_num_rows($result) < 20) {
1235 $ret[] = update_sql('ALTER TABLE {old_revisions} DROP done');
1238 $ret['#finished'] = FALSE;
1244 function system_update_160() {
1245 $types = module_invoke('node', 'get_types');
1246 if (is_array($types)) {
1247 foreach($types as $type) {
1248 if (!is_array(variable_get("node_options_$type", array()))) {
1249 variable_set("node_options_$type", array());
1256 function system_update_161() {
1257 variable_del('forum_icon_path');
1261 function system_update_162() {
1264 // PostgreSQL only update
1265 switch ($GLOBALS['db_type']) {
1268 $ret[] = update_sql('DROP INDEX {book}_parent');
1269 $ret[] = update_sql('CREATE INDEX {book}_parent_idx ON {book}(parent)');
1271 $ret[] = update_sql('DROP INDEX {node_comment_statistics}_timestamp_idx');
1272 $ret[] = update_sql('CREATE INDEX {node_comment_statistics}_last_comment_timestamp_idx ON {node_comment_statistics}(last_comment_timestamp)');
1274 $ret[] = update_sql('ALTER TABLE {filters} ALTER delta SET DEFAULT 0');
1275 $ret[] = update_sql('DROP INDEX {filters}_module_idx');
1277 $ret[] = update_sql('DROP INDEX {locales_target}_lid_idx');
1278 $ret[] = update_sql('DROP INDEX {locales_target}_lang_idx');
1279 $ret[] = update_sql('CREATE INDEX {locales_target}_locale_idx ON {locales_target}(locale)');
1281 $ret[] = update_sql('DROP INDEX {node}_created');
1282 $ret[] = update_sql('CREATE INDEX {node}_created_idx ON {node}(created)');
1283 $ret[] = update_sql('DROP INDEX {node}_changed');
1284 $ret[] = update_sql('CREATE INDEX {node}_changed_idx ON {node}(changed)');
1286 $ret[] = update_sql('DROP INDEX {profile_fields}_category');
1287 $ret[] = update_sql('CREATE INDEX {profile_fields}_category_idx ON {profile_fields}(category)');
1289 $ret[] = update_sql('DROP INDEX {url_alias}_dst_idx');
1290 $ret[] = update_sql('CREATE UNIQUE INDEX {url_alias}_dst_idx ON {url_alias}(dst)');
1292 $ret[] = update_sql('CREATE INDEX {sessions}_uid_idx ON {sessions}(uid)');
1293 $ret[] = update_sql('CREATE INDEX {sessions}_timestamp_idx ON {sessions}(timestamp)');
1295 $ret[] = update_sql('ALTER TABLE {accesslog} DROP mask');
1297 db_change_column($ret, 'accesslog', 'path', 'path', 'text');
1298 db_change_column($ret, 'accesslog', 'url', 'url', 'text');
1299 db_change_column($ret, 'watchdog', 'link', 'link', 'text', array('not null' => TRUE, 'default' => "''"));
1300 db_change_column($ret, 'watchdog', 'location', 'location', 'text', array('not null' => TRUE, 'default' => "''"));
1301 db_change_column($ret, 'watchdog', 'referer', 'referer', 'text', array('not null' => TRUE, 'default' => "''"));
1309 function system_update_163() {
1311 if ($GLOBALS['db_type'] == 'mysql' || $GLOBALS['db_type'] == 'mysqli') {
1312 $ret[] = update_sql('ALTER TABLE {cache} CHANGE data data LONGBLOB');
1317 function system_update_164() {
1320 switch ($GLOBALS['db_type']) {
1323 $ret[] = update_sql("CREATE TABLE {poll_votes} (
1324 nid int(10) unsigned NOT NULL,
1325 uid int(10) unsigned NOT NULL default 0,
1326 hostname varchar(128) NOT NULL default '',
1334 $ret[] = update_sql("CREATE TABLE {poll_votes} (
1336 uid int NOT NULL default 0,
1337 hostname varchar(128) NOT NULL default ''
1339 $ret[] = update_sql('CREATE INDEX {poll_votes}_nid_idx ON {poll_votes} (nid)');
1340 $ret[] = update_sql('CREATE INDEX {poll_votes}_uid_idx ON {poll_votes} (uid)');
1341 $ret[] = update_sql('CREATE INDEX {poll_votes}_hostname_idx ON {poll_votes} (hostname)');
1345 $result = db_query('SELECT nid, polled FROM {poll}');
1346 while ($poll = db_fetch_object($result)) {
1347 foreach (explode(' ', $poll->polled) as $polled) {
1348 if ($polled[0] == '_') {
1349 // $polled is a user id
1350 db_query('INSERT INTO {poll_votes} (nid, uid) VALUES (%d, %d)', $poll->nid, substr($polled, 1, -1));
1353 // $polled is a host
1354 db_query("INSERT INTO {poll_votes} (nid, hostname) VALUES (%d, '%s')", $poll->nid, $polled);
1359 $ret[] = update_sql('ALTER TABLE {poll} DROP polled');
1364 function system_update_165() {
1365 $cron_last = max(variable_get('drupal_cron_last', 0), variable_get('ping_cron_last', 0));
1366 variable_set('cron_last', $cron_last);
1367 variable_del('drupal_cron_last');
1368 variable_del('ping_cron_last');
1372 function system_update_166() {
1375 $ret[] = update_sql("DROP TABLE {directory}");
1376 switch ($GLOBALS['db_type']) {
1379 $ret[] = update_sql("CREATE TABLE {client} (
1380 cid int(10) unsigned NOT NULL auto_increment,
1381 link varchar(255) NOT NULL default '',
1382 name varchar(128) NOT NULL default '',
1383 mail varchar(128) NOT NULL default '',
1384 slogan longtext NOT NULL,
1385 mission longtext NOT NULL,
1386 users int(10) NOT NULL default '0',
1387 nodes int(10) NOT NULL default '0',
1388 version varchar(35) NOT NULL default'',
1389 created int(11) NOT NULL default '0',
1390 changed int(11) NOT NULL default '0',
1393 $ret[] = update_sql("CREATE TABLE {client_system} (
1394 cid int(10) NOT NULL default '0',
1395 name varchar(255) NOT NULL default '',
1396 type varchar(255) NOT NULL default '',
1397 PRIMARY KEY (cid,name)
1402 $ret[] = update_sql("CREATE TABLE {client} (
1404 link varchar(255) NOT NULL default '',
1405 name varchar(128) NOT NULL default '',
1406 mail varchar(128) NOT NULL default '',
1407 slogan text NOT NULL default '',
1408 mission text NOT NULL default '',
1409 users integer NOT NULL default '0',
1410 nodes integer NOT NULL default '0',
1411 version varchar(35) NOT NULL default'',
1412 created integer NOT NULL default '0',
1413 changed integer NOT NULL default '0',
1416 $ret[] = update_sql("CREATE TABLE {client_system} (
1417 cid integer NOT NULL,
1418 name varchar(255) NOT NULL default '',
1419 type varchar(255) NOT NULL default '',
1420 PRIMARY KEY (cid,name)
1428 function system_update_167() {
1431 switch ($GLOBALS['db_type']) {
1434 $ret[] = update_sql("ALTER TABLE {vocabulary_node_types} CHANGE type type varchar(32) NOT NULL default ''");
1437 db_change_column($ret, 'vocabulary_node_types', 'type', 'type', 'varchar(32)', array('not null' => TRUE, 'default' => "''"));
1438 $ret[] = update_sql("ALTER TABLE {vocabulary_node_types} ADD PRIMARY KEY (vid, type)");
1445 function system_update_168() {
1448 $ret[] = update_sql("ALTER TABLE {term_hierarchy} ADD PRIMARY KEY (tid, parent)");
1453 function system_update_169() {
1454 // Warn PGSQL admins if their database is set up incorrectly
1455 if ($GLOBALS['db_type'] == 'pgsql') {
1456 $encoding = db_result(db_query('SHOW server_encoding'));
1457 if (!in_array(strtolower($encoding), array('unicode', 'utf8'))) {
1458 $msg = 'Your PostgreSQL database is set up with the wrong character encoding ('. $encoding .'). It is possible it will not work as expected. It is advised to recreate it with UTF-8/Unicode encoding. More information can be found in the <a href="http://www.postgresql.org/docs/7.4/interactive/multibyte.html">PostgreSQL documentation</a>.';
1459 watchdog('php', $msg, WATCHDOG_WARNING);
1460 drupal_set_message($msg, 'status');
1464 // Note: 'access' table manually updated in update.php
1465 return _system_update_utf8(array(
1466 'accesslog', 'aggregator_category',
1467 'aggregator_category_feed', 'aggregator_category_item',
1468 'aggregator_feed', 'aggregator_item', 'authmap', 'blocks',
1469 'book', 'boxes', 'cache', 'comments', 'contact',
1470 'node_comment_statistics', 'client', 'client_system', 'files',
1471 'filter_formats', 'filters', 'flood', 'forum', 'history',
1472 'locales_meta', 'locales_source', 'locales_target', 'menu',
1473 'node', 'node_access', 'node_revisions', 'profile_fields',
1474 'profile_values', 'url_alias', 'permission', 'poll', 'poll_votes',
1475 'poll_choices', 'role', 'search_dataset', 'search_index',
1476 'search_total', 'sessions', 'sequences', 'node_counter',
1477 'system', 'term_data', 'term_hierarchy', 'term_node',
1478 'term_relation', 'term_synonym', 'users', 'users_roles', 'variable',
1479 'vocabulary', 'vocabulary_node_types', 'watchdog'
1484 * Converts a set of tables to UTF-8 encoding.
1486 * This update is designed to be re-usable by contrib modules and is
1487 * used by system_update_169().
1489 function _system_update_utf8($tables) {
1490 // Are we starting this update for the first time?
1491 if (!isset($_SESSION['update_utf8'])) {
1492 switch ($GLOBALS['db_type']) {
1493 // Only for MySQL 4.1+
1497 if (version_compare(mysql_get_server_info($GLOBALS['active_db']), '4.1.0', '<')) {
1505 // See if database uses UTF-8 already
1507 $url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url);
1508 $db_name = substr($url['path'], 1);
1509 $result = db_fetch_array(db_query('SHOW CREATE DATABASE `%s`', $db_name));
1510 if (preg_match('/utf8/i', array_pop($result))) {
1514 // Make list of tables to convert
1515 $_SESSION['update_utf8'] = $tables;
1516 // Keep track of total for progress bar
1517 $_SESSION['update_utf8_total'] = count($tables);
1520 // Fetch remaining tables list and convert next table
1521 $list = &$_SESSION['update_utf8'];
1523 $ret = update_convert_table_utf8(array_shift($list));
1526 if (count($list) == 0) {
1527 unset($_SESSION['update_utf8']);
1528 unset($_SESSION['update_utf8_total']);
1532 // Progress percentage
1533 $ret['#finished'] = 1 - (count($list) / $_SESSION['update_utf8_total']);
1537 function system_update_170() {
1538 if (!variable_get('update_170_done', false)) {
1539 switch ($GLOBALS['db_type']) {
1542 db_change_column($ret, 'system', 'schema_version', 'schema_version', 'smallint', array('not null' => TRUE, 'default' => -1));
1547 db_query('ALTER TABLE {system} CHANGE schema_version schema_version smallint(3) not null default -1');
1550 // Set schema version -1 (uninstalled) for disabled modules (only affects contrib).
1551 db_query('UPDATE {system} SET schema_version = -1 WHERE status = 0 AND schema_version = 0');
1556 function system_update_171() {
1558 $ret[] = update_sql('DELETE FROM {users_roles} WHERE rid IN ('. DRUPAL_ANONYMOUS_RID. ', '. DRUPAL_AUTHENTICATED_RID. ')');
1562 function system_update_172() {
1563 // Multi-part update
1564 if (!isset($_SESSION['system_update_172'])) {
1565 $_SESSION['system_update_172'] = 0;
1566 $_SESSION['system_update_172_max'] = db_result(db_query('SELECT MAX(cid) FROM {comments}'));
1569 include_once './modules/comment.module';
1572 $result = db_query_range("SELECT cid, thread FROM {comments} WHERE cid > %d ORDER BY cid ASC", $_SESSION['system_update_172'], 0, $limit);
1573 while ($comment = db_fetch_object($result)) {
1574 $_SESSION['system_update_172'] = $comment->cid;
1575 $thread = explode('.', rtrim($comment->thread, '/'));
1576 foreach ($thread as $i => $offset) {
1577 // Decode old-style comment codes: 1,2,...,9,90,91,92,...,99,990,991,...
1578 $thread[$i] = int2vancode((strlen($offset) - 1) * 10 + substr($offset, -1, 1));
1580 $thread = implode('.', $thread) .'/';
1581 db_query("UPDATE {comments} SET thread = '%s' WHERE cid = %d", $thread, $comment->cid);
1584 if ($_SESSION['system_update_172'] == $_SESSION['system_update_172_max']) {
1585 unset($_SESSION['system_update_172']);
1586 unset($_SESSION['system_update_172_max']);
1589 return array('#finished' => $_SESSION['system_update_172'] / $_SESSION['system_update_172_max']);
1592 function system_update_173() {
1594 // State tracker to determine whether we keep a backup of the files table or not.
1597 // PostgreSQL needs CREATE TABLE foobar _AS_ SELECT ...
1598 $AS = ($GLOBALS['db_type'] == 'pgsql') ? 'AS' : '';
1600 // Backup the files table.
1601 $ret[] = update_sql("CREATE TABLE {files_backup} $AS SELECT * FROM {files}");
1603 // Do some files table sanity checking and cleanup.
1604 $ret[] = update_sql('DELETE FROM {files} WHERE fid = 0');
1605 $ret[] = update_sql('UPDATE {files} SET vid = nid WHERE vid = 0');
1607 // Create a temporary table to build the new file_revisions and files tables from.
1608 $ret[] = update_sql("CREATE TABLE {files_tmp} $AS SELECT * FROM {files}");
1609 $ret[] = update_sql('DROP TABLE {files}');
1611 switch ($GLOBALS['db_type']) {
1613 // create file_revisions table
1614 $ret[] = update_sql("CREATE TABLE {file_revisions} (
1615 fid integer NOT NULL default 0,
1616 vid integer NOT NULL default 0,
1617 description varchar(255) NOT NULL default '',
1618 list smallint NOT NULL default 0,
1619 PRIMARY KEY (fid, vid))");
1620 $result = update_sql("INSERT INTO {file_revisions} SELECT DISTINCT ON (fid,vid) fid, vid, description, list FROM {files_tmp}");
1622 if ($result['success'] === FALSE) {
1626 // Create normalized files table
1627 $ret[] = update_sql("CREATE TABLE {files} (
1629 nid integer NOT NULL default 0,
1630 filename varchar(255) NOT NULL default '',
1631 filepath varchar(255) NOT NULL default '',
1632 filemime varchar(255) NOT NULL default '',
1633 filesize integer NOT NULL default 0,
1634 PRIMARY KEY (fid))");
1635 $result = update_sql("INSERT INTO {files} SELECT DISTINCT ON (fid) fid, nid, filename, filepath, filemime, filesize FROM {files_tmp}");
1637 if ($result['success'] === FALSE) {
1641 $ret[] = update_sql("SELECT setval('{files}_fid_seq', max(fid)) FROM {files}");
1647 // create file_revisions table
1648 $ret[] = update_sql("CREATE TABLE {file_revisions} (
1649 fid int(10) unsigned NOT NULL default 0,
1650 vid int(10) unsigned NOT NULL default 0,
1651 description varchar(255) NOT NULL default '',
1652 list tinyint(1) unsigned NOT NULL default 0,
1653 PRIMARY KEY (fid, vid)
1654 ) /*!40100 DEFAULT CHARACTER SET utf8 */");
1656 // Try as you might mysql only does distinct row if you are selecting more than 1 column.
1657 $result = update_sql('INSERT INTO {file_revisions} SELECT DISTINCT fid , vid, description, list FROM {files_tmp}');
1659 if ($result['success'] === FALSE) {
1663 $ret[] = update_sql("CREATE TABLE {files} (
1664 fid int(10) unsigned NOT NULL default 0,
1665 nid int(10) unsigned NOT NULL default 0,
1666 filename varchar(255) NOT NULL default '',
1667 filepath varchar(255) NOT NULL default '',
1668 filemime varchar(255) NOT NULL default '',
1669 filesize int(10) unsigned NOT NULL default 0,
1671 ) /*!40100 DEFAULT CHARACTER SET utf8 */");
1672 $result = update_sql("INSERT INTO {files} SELECT DISTINCT fid, nid, filename, filepath, filemime, filesize FROM {files_tmp}");
1674 if ($result['success'] === FALSE) {
1681 $ret[] = update_sql("DROP TABLE {files_tmp}");
1683 // Remove original files table if all went well. Otherwise preserve it and notify user.
1685 $ret[] = update_sql("DROP TABLE {files_backup}");
1688 drupal_set_message('Normalizing files table failed. A backup of the original table called {files_backup} remains in your database.');
1694 function system_update_174() {
1695 // This update (update comments system variables on upgrade) has been removed.
1699 function system_update_175() {
1700 $result = db_query('SELECT * FROM {url_alias}');
1701 while ($path = db_fetch_object($result)) {
1702 $path->src = urldecode($path->src);
1703 $path->dst = urldecode($path->dst);
1704 db_query("UPDATE {url_alias} SET dst = '%s', src = '%s' WHERE pid = %d", $path->dst, $path->src, $path->pid);
1709 function system_update_176() {
1711 $ret[] = update_sql('ALTER TABLE {filter_formats} ADD UNIQUE (name)');
1715 function system_update_177() {
1717 $message_ids = array(
1718 'welcome_subject' => 'Welcome subject',
1719 'welcome_body' => 'Welcome body text',
1720 'approval_subject' => 'Approval subject',
1721 'approval_body' => 'Approval body text',
1722 'pass_subject' => 'Password reset subject',
1723 'pass_body' => 'Password reset body text',
1725 foreach ($message_ids as $message_id => $message_text) {
1726 if ($admin_setting = variable_get('user_mail_'. $message_id, FALSE)) {
1727 // Insert newlines and escape for display as HTML
1728 $admin_setting = nl2br(check_plain($message_text ."\n\n". $admin_setting));
1729 watchdog('legacy', $admin_setting);
1730 $last = db_fetch_object(db_query('SELECT max(wid) AS wid FROM {watchdog}'));
1731 // Deleting is required, because _user_mail_text() checks for the existance of the variable.
1732 variable_del('user_mail_'. $message_id);
1734 'query' => strtr('The mail template %message_id has been reset to the default. The old template <a href="%url">has been saved</a>.', array('%message_id' => 'user_mail_'. $message_id, '%url' => url('admin/logs/event/'. $last->wid))),
1742 function _update_178_url_fix($text) {
1743 // Key is the attribute to replace.
1744 $urlpatterns['href'] = "/<a[^>]+href=\"([^\"]+)/i";
1745 $urlpatterns['src'] = "/<img[^>]+src=\"([^\"]+)/i";
1748 foreach ($urlpatterns as $type => $pattern) {
1749 if (preg_match_all($pattern, $text, $matches)) {
1750 foreach ($matches[1] as $url) {
1751 if ($url != '' && !strstr($url, 'mailto:') && !strstr($url, '://') && !strstr($url, '../') && !strstr($url, './') && $url[0] != '/' && $url[0] != '#') {
1752 $text = preg_replace('|'. $type .'\s*=\s*"'. preg_quote($url) .'\s*"|', $type. '="'.base_path(). $url .'"', $text);
1757 return $text != $old ? $text : FALSE;
1760 function _update_178_url_formats() {
1763 // Any format with the HTML filter in it
1764 $result = db_query("SELECT format FROM {filters} WHERE module = 'filter' AND delta = 0");
1765 while ($format = db_fetch_object($result)) {
1766 $formats[$format->format] = true;
1769 // Any format with only the linebreak filter in it
1770 $result = db_query("SELECT format FROM {filters} WHERE module = 'filter' AND delta = 2");
1771 while ($format = db_fetch_object($result)) {
1772 if (db_result(db_query('SELECT COUNT(*) FROM {filters} WHERE format = %d', $format->format)) == 1) {
1773 $formats[$format->format] = true;
1777 // Any format with 'HTML' in its name
1778 $result = db_query("SELECT format FROM {filter_formats} WHERE name LIKE '%HTML%'");
1779 while ($format = db_fetch_object($result)) {
1780 $formats[$format->format] = true;
1787 * Update base paths for relative URLs in node and comment content.
1789 function system_update_178() {
1791 if (variable_get('clean_url', 0) == 1) {
1792 // Multi-part update
1793 if (!isset($_SESSION['system_update_178_comment'])) {
1794 // Check which formats need to be converted
1795 $formats = _update_178_url_formats();
1796 if (count($formats) == 0) {
1800 // Build format query string
1801 $_SESSION['formats'] = array_keys($formats);
1802 $_SESSION['format_string'] = '('. substr(str_repeat('%d, ', count($formats)), 0, -2) .')';
1805 $_SESSION['system_update_178_comment'] = 0;
1806 $_SESSION['system_update_178_node'] = 0;
1807 $_SESSION['system_update_178_comment_max'] = db_result(db_query('SELECT MAX(cid) FROM {comments} WHERE format IN '. $_SESSION['format_string'], $_SESSION['formats']));
1808 $_SESSION['system_update_178_node_max'] = db_result(db_query('SELECT MAX(vid) FROM {node_revisions} WHERE format IN '. $_SESSION['format_string'], $_SESSION['formats']));
1814 if ($_SESSION['system_update_178_comment'] != $_SESSION['system_update_178_comment_max']) {
1815 $args = array_merge(array($_SESSION['system_update_178_comment']), $_SESSION['formats']);
1816 $result = db_query_range("SELECT cid, comment FROM {comments} WHERE cid > %d AND format IN ". $_SESSION['format_string'] .' ORDER BY cid ASC', $args, 0, $limit);
1817 while ($comment = db_fetch_object($result)) {
1818 $_SESSION['system_update_178_comment'] = $comment->cid;
1819 $comment->comment = _update_178_url_fix($comment->comment);
1820 if ($comment->comment !== FALSE) {
1821 db_query("UPDATE {comments} SET comment = '%s' WHERE cid = %d", $comment->comment, $comment->cid);
1827 $args = array_merge(array($_SESSION['system_update_178_node']), $_SESSION['formats']);
1828 $result = db_query_range("SELECT vid, teaser, body FROM {node_revisions} WHERE vid > %d AND format IN ". $_SESSION['format_string'] .' ORDER BY vid ASC', $args, 0, $limit);
1829 while ($node = db_fetch_object($result)) {
1830 $_SESSION['system_update_178_node'] = $node->vid;
1834 $node->teaser = _update_178_url_fix($node->teaser);
1835 if ($node->teaser !== FALSE) {
1836 $set[] = "teaser = '%s'";
1837 $args[] = $node->teaser;
1840 $node->body = _update_178_url_fix($node->body);
1841 if ($node->body !== FALSE) {
1842 $set[] = "body = '%s'";
1843 $args[] = $node->body;
1847 $args[] = $node->vid;
1848 db_query('UPDATE {node_revisions} SET '. implode(', ', $set) .' WHERE vid = %d', $args);
1853 if ($_SESSION['system_update_178_comment'] == $_SESSION['system_update_178_comment_max'] &&
1854 $_SESSION['system_update_178_node'] == $_SESSION['system_update_178_node_max']) {
1855 unset($_SESSION['system_update_178_comment']);
1856 unset($_SESSION['system_update_178_comment_max']);
1857 unset($_SESSION['system_update_178_node']);
1858 unset($_SESSION['system_update_178_node_max']);
1862 // Report percentage finished
1863 return array('#finished' =>
1864 ($_SESSION['system_update_178_comment'] + $_SESSION['system_update_178_node']) /
1865 ($_SESSION['system_update_178_comment_max'] + $_SESSION['system_update_178_node_max'])
1874 * Update base paths for relative URLs in custom blocks, profiles and various variables.
1876 function system_update_179() {
1878 if (variable_get('clean_url', 0) == 1) {
1879 // Multi-part update
1880 if (!isset($_SESSION['system_update_179_uid'])) {
1881 // Check which formats need to be converted
1882 $formats = _update_178_url_formats();
1883 if (count($formats) == 0) {
1887 // Custom Blocks (too small for multipart)
1888 $format_string = '('. substr(str_repeat('%d, ', count($formats)), 0, -2) .')';
1889 $result = db_query("SELECT bid, body FROM {boxes} WHERE format IN ". $format_string, array_keys($formats));
1890 while ($block = db_fetch_object($result)) {
1891 $block->body = _update_178_url_fix($block->body);
1892 if ($block->body !== FALSE) {
1893 db_query("UPDATE {boxes} SET body = '%s' WHERE bid = %d", $block->body, $block->bid);
1897 // Variables (too small for multipart)
1898 $vars = array('site_mission', 'site_footer', 'user_registration_help');
1899 foreach (node_get_types() as $type => $name) {
1900 $vars[] = $type .'_help';
1902 foreach ($vars as $var) {
1903 $value = variable_get($var, NULL);
1904 if (!is_null($value)) {
1905 $value = _update_178_url_fix($value);
1906 if ($value !== FALSE) {
1907 variable_set($var, $value);
1912 // See if profiles need to be updated: is the default format HTML?
1913 if (!isset($formats[variable_get('filter_default_format', 1)])) {
1916 $result = db_query("SELECT fid FROM {profile_fields} WHERE type = 'textarea'");
1918 while ($field = db_fetch_object($result)) {
1919 $fields[] = $field->fid;
1921 if (count($fields) == 0) {
1925 // Begin multi-part update for profiles
1926 $_SESSION['system_update_179_fields'] = $fields;
1927 $_SESSION['system_update_179_field_string'] = '('. substr(str_repeat('%d, ', count($fields)), 0, -2) .')';
1928 $_SESSION['system_update_179_uid'] = 0;
1929 $_SESSION['system_update_179_fid'] = 0;
1930 $_SESSION['system_update_179_max'] = db_result(db_query('SELECT MAX(uid) FROM {profile_values} WHERE fid IN '. $_SESSION['system_update_179_field_string'], $_SESSION['system_update_179_fields']));
1933 // Fetch next 20 profile values to convert
1935 $args = array_merge(array($_SESSION['system_update_179_uid'], $_SESSION['system_update_179_fid'], $_SESSION['system_update_179_uid']), $_SESSION['system_update_179_fields']);
1936 $result = db_query_range("SELECT fid, uid, value FROM {profile_values} WHERE ((uid = %d AND fid > %d) OR uid > %d) AND fid IN ". $_SESSION['system_update_179_field_string'] .' ORDER BY uid ASC, fid ASC', $args, 0, $limit);
1937 while ($field = db_fetch_object($result)) {
1938 $_SESSION['system_update_179_uid'] = $field->uid;
1939 $_SESSION['system_update_179_fid'] = $field->fid;
1940 $field->value = _update_178_url_fix($field->value);
1941 if ($field->value !== FALSE) {
1942 db_query("UPDATE {profile_values} SET value = '%s' WHERE uid = %d AND fid = %d", $field->value, $field->uid, $field->fid);
1948 if (db_num_rows($result) == 0) {
1949 unset($_SESSION['system_update_179_uid']);
1950 unset($_SESSION['system_update_179_fid']);
1951 unset($_SESSION['system_update_179_max']);
1955 // Report percentage finished
1956 // (Note: make sure we complete all fields for the last user by not reporting 100% too early)
1957 return array('#finished' => $_SESSION['system_update_179_uid'] / ($_SESSION['system_update_179_max'] + 1));
1964 function system_update_180() {
1967 switch ($GLOBALS['db_type']) {
1970 $ret[] = update_sql("ALTER TABLE {node} DROP PRIMARY KEY");
1971 $ret[] = update_sql("ALTER TABLE {node} ADD PRIMARY KEY (nid, vid)");
1972 $ret[] = update_sql("ALTER TABLE {node} ADD UNIQUE (vid)");
1973 $ret[] = update_sql("ALTER TABLE {node} ADD INDEX (nid)");
1975 $ret[] = update_sql("ALTER TABLE {node_counter} CHANGE nid nid INT(10) NOT NULL DEFAULT '0'");
1978 $ret[] = update_sql("ALTER TABLE {node} DROP CONSTRAINT {node}_pkey"); // Change PK
1979 $ret[] = update_sql("ALTER TABLE {node} ADD PRIMARY KEY (nid, vid)");
1980 $ret[] = update_sql('DROP INDEX {node}_vid_idx'); // Change normal index to UNIQUE index
1981 $ret[] = update_sql('CREATE UNIQUE INDEX {node}_vid_idx ON {node}(vid)');
1982 $ret[] = update_sql('CREATE INDEX {node}_nid_idx ON {node}(nid)'); // Add index on nid
1989 function system_update_181() {
1991 switch ($GLOBALS['db_type']) {
1994 $ret[] = update_sql("ALTER TABLE {profile_fields} ADD autocomplete TINYINT(1) NOT NULL AFTER visibility ;");
1997 db_add_column($ret, 'profile_fields', 'autocomplete', 'smallint', array('not null' => TRUE, 'default' => 0));
2004 * The lid field in pgSQL should not be UNIQUE, but an INDEX.
2006 function system_update_182() {
2009 if ($GLOBALS['db_type'] == 'pgsql') {
2010 $ret[] = update_sql('ALTER TABLE {locales_target} DROP CONSTRAINT {locales_target}_lid_key');
2011 $ret[] = update_sql('CREATE INDEX {locales_target}_lid_idx ON {locales_target} (lid)');