Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 322 lines (284 sloc) 12.951 kb
0a4f99e - added update.php to replace the updates/* files to make future upgr…
Kjartan Mannes authored
1 <?php
2 include_once "includes/common.inc";
3
4 if (!get_cfg_var("safe_mode")) {
5 set_time_limit(180);
6 }
7
8 // Define the various updates in an array("date : comment" => "function");
9 $mysql_updates = array(
10 "2001-10-10" => "update_1",
11 "2001-10-12 : Pearification" => "update_2",
12 "2001-10-14" => "update_3",
13 "2001-10-16" => "update_4",
14 "2001-10-17" => "update_5",
15 "2001-10-22" => "update_6",
16 "2001-11-01" => "update_7",
17 "2001-11-02" => "update_8",
18 "2001-11-04" => "update_9",
cd2df44 @dbuytaert - update.php:
dbuytaert authored
19 "2001-11-17: distributed authentication" => "update_10",
5ecedf7 @dbuytaert user.module:
dbuytaert authored
20 "2001-12-01" => "update_11",
20b4b71 @dbuytaert - book.module:
dbuytaert authored
21 "2001-12-06" => "update_12",
0a4f99e - added update.php to replace the updates/* files to make future upgr…
Kjartan Mannes authored
22 );
23
24 // Update functions
25 function update_1() {
26 update_sql("ALTER TABLE users RENAME AS user;");
27 update_sql("ALTER TABLE user DROP INDEX real_email;");
28 update_sql("ALTER TABLE user DROP fake_email;");
29 update_sql("ALTER TABLE user DROP nodes;");
30 update_sql("ALTER TABLE user DROP bio;");
31 update_sql("ALTER TABLE user DROP hash;");
32 update_sql("ALTER TABLE user ADD session varchar(32) DEFAULT '' NOT NULL;");
33 update_sql("ALTER TABLE user ADD jabber varchar(128) DEFAULT '' NULL;");
34 update_sql("ALTER TABLE user ADD drupal varchar(128) DEFAULT '' NULL;");
35 update_sql("ALTER TABLE user ADD init varchar(64) DEFAULT '' NULL;");
36 update_sql("ALTER TABLE user CHANGE passwd pass varchar(24) DEFAULT '' NOT NULL;");
37 update_sql("ALTER TABLE user CHANGE real_email mail varchar(64) DEFAULT '' NULL;");
38 update_sql("ALTER TABLE user CHANGE last_access timestamp int(11) DEFAULT '0' NOT NULL;");
39 update_sql("ALTER TABLE user CHANGE last_host hostname varchar(128) DEFAULT '' NOT NULL;");
40 update_sql("ALTER TABLE user CHANGE id uid int(10) unsigned DEFAULT '0' NOT NULL auto_increment;");
41 update_sql("ALTER TABLE user CHANGE url homepage varchar(128) DEFAULT '' NOT NULL;");
42 update_sql("UPDATE user SET status = 1 WHERE status = 2;");
43 update_sql("UPDATE user SET name = userid;");
44 update_sql("ALTER TABLE user DROP userid;");
45 update_sql("UPDATE user SET init = mail;");
46 update_sql("DROP TABLE access;");
47 update_sql("CREATE TABLE access (aid tinyint(10) DEFAULT '0' NOT NULL auto_increment, mask varchar(255) DEFAULT '' NOT NULL, type varchar(255) DEFAULT '' NOT NULL, status tinyint(2) DEFAULT '0' NOT NULL, UNIQUE mask (mask), PRIMARY KEY (aid));");
48 update_sql("CREATE TABLE moderate (cid int(10) DEFAULT '0' NOT NULL, nid int(10) DEFAULT '0' NOT NULL, uid int(10) DEFAULT '0' NOT NULL, score int(2) DEFAULT '0' NOT NULL, timestamp int(11) DEFAULT '0' NOT NULL, INDEX (cid), INDEX (nid) );");
49 update_sql("ALTER TABLE comments DROP score;");
50 update_sql("ALTER TABLE comments DROP votes;");
51 update_sql("ALTER TABLE comments DROP users;");
52 }
53
54 function update_2() {
55 update_sql("ALTER TABLE user RENAME AS users;");
56 update_sql("ALTER TABLE users CHANGE pass pass varchar(32) DEFAULT '' NOT NULL;");
57 update_sql("ALTER TABLE watchdog CHANGE user userid int(10) DEFAULT '0' NOT NULL;");
58 update_sql("ALTER TABLE rating CHANGE user userid int(10) DEFAULT '0' NOT NULL;");
59 update_sql("ALTER TABLE layout CHANGE user userid int(10) DEFAULT '0' NOT NULL;");
60 update_sql("ALTER TABLE blocks CHANGE offset delta tinyint(2) DEFAULT '0' NOT NULL;");
61 foreach (module_list() as $name) {
62 if (module_hook($name, "node", "name")) {
63 $output .= "$name ...";
64 db_query("DROP TABLE IF EXISTS ". $name ."_seq");
65 db_query("CREATE TABLE ". $name ."_seq (id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY(id))");
66 $result = db_query("SELECT MAX(". ($name == "node" ? "nid" : "lid") .") FROM $name", 1);
67 $count = $result ? db_result($result, 0) : 0;
68 db_query("INSERT INTO ". $name ."_seq (id) VALUES ('$count')");
69 $output .= "done ($count)<br />";
70 }
71 }
72 print $output;
73 }
74
75 function update_3() {
76 update_sql("ALTER TABLE watchdog CHANGE id wid int(5) DEFAULT '0' NOT NULL auto_increment;");
77 update_sql("ALTER TABLE locales CHANGE id lid int(10) DEFAULT '0' NOT NULL auto_increment;");
78 update_sql("ALTER TABLE watchdog CHANGE userid uid int(10) DEFAULT '0' NOT NULL;");
79 update_sql("ALTER TABLE layout CHANGE userid uid int(10) DEFAULT '0' NOT NULL;");
80 update_sql("ALTER TABLE rating CHANGE userid uid int(10) DEFAULT '0' NOT NULL;");
81 }
82
83 function update_4() {
84 print 'remove the "auto_increment"s\:n';
85 update_sql("ALTER TABLE story CHANGE nid nid int(10) unsigned DEFAULT '0' NOT NULL;");
86 update_sql("ALTER TABLE blog CHANGE nid nid int(10) unsigned DEFAULT '0' NOT NULL;");
87 update_sql("ALTER TABLE page CHANGE nid nid int(10) unsigned DEFAULT '0' NOT NULL;");
88 update_sql("ALTER TABLE forum CHANGE nid nid int(10) unsigned DEFAULT '0' NOT NULL;");
89 update_sql("ALTER TABLE book CHANGE nid nid int(10) unsigned DEFAULT '0' NOT NULL;");
90
91 print 'drop the "lid"s:\n';
92 update_sql("ALTER TABLE story DROP lid;");
93 update_sql("ALTER TABLE blog DROP lid;");
94 update_sql("ALTER TABLE page DROP lid;");
95 update_sql("ALTER TABLE forum DROP lid;");
96 update_sql("ALTER TABLE book DROP lid;");
97
98 print 'rename "author" to "uid":\n';
99 update_sql("ALTER TABLE comments CHANGE author uid int(10) DEFAULT '0' NOT NULL;");
100 update_sql("ALTER TABLE node CHANGE author uid int(10) DEFAULT '0' NOT NULL;");
101 update_sql("ALTER TABLE node DROP KEY author;");
102 update_sql("ALTER TABLE node ADD KEY uid (uid);");
103
104 print 'resize some "id"s:\n';
105 update_sql("ALTER TABLE feed CHANGE fid fid int(10) NOT NULL auto_increment;");
106 update_sql("ALTER TABLE bundle CHANGE bid bid int(10) NOT NULL auto_increment;");
107 update_sql("ALTER TABLE item CHANGE iid iid int(10) NOT NULL auto_increment;");
108 update_sql("ALTER TABLE item CHANGE fid fid int(10) NOT NULL;");
109 update_sql("ALTER TABLE comments CHANGE cid cid int(10) NOT NULL auto_increment;");
110 update_sql("ALTER TABLE comments CHANGE pid pid int(10) NOT NULL;");
111 update_sql("ALTER TABLE comments CHANGE lid lid int(10) NOT NULL;");
112 }
113
114 function update_5() {
115 print 'add primary keys:\n';
116 update_sql("ALTER TABLE story ADD PRIMARY KEY nid (nid);");
117 update_sql("ALTER TABLE blog ADD PRIMARY KEY nid (nid);");
118 update_sql("ALTER TABLE page ADD PRIMARY KEY nid (nid);");
119 update_sql("ALTER TABLE forum ADD PRIMARY KEY nid (nid);");
120 update_sql("ALTER TABLE book ADD PRIMARY KEY nid (nid);");
121
122 }
123
124 function update_6() {
125 print 'add new field to blocks:\n';
126 update_sql("ALTER TABLE blocks ADD path varchar(255) NOT NULL DEFAULT '';");
127 }
128
129 function update_7() {
6fd5a8d @dbuytaert - update.php: discovered and fixed a small thinko in update function #7.
dbuytaert authored
130 print "updating the story table:\n";
131 update_sql("UPDATE story SET body = CONCAT(abstract, '\n\n', body)");
132 update_sql("ALTER TABLE story DROP abstract");
133
0a4f99e - added update.php to replace the updates/* files to make future upgr…
Kjartan Mannes authored
134 print 'rename the body fields:\n';
135 update_sql("ALTER TABLE story CHANGE body body_old TEXT DEFAULT '' NOT NULL;");
136 update_sql("ALTER TABLE page CHANGE body body_old TEXT DEFAULT '' NOT NULL;");
137 update_sql("ALTER TABLE blog CHANGE body body_old TEXT DEFAULT '' NOT NULL;");
138 update_sql("ALTER TABLE forum CHANGE body body_old TEXT DEFAULT '' NOT NULL;");
139 update_sql("ALTER TABLE book CHANGE body body_old TEXT DEFAULT '' NOT NULL;");
140
141 print 'update the node table:\n';
142 update_sql("ALTER TABLE node DROP lid;");
143 update_sql("ALTER TABLE node ADD teaser TEXT DEFAULT '' NOT NULL;");
144 update_sql("ALTER TABLE node ADD body TEXT DEFAULT '' NOT NULL;");
145 update_sql("ALTER TABLE node ADD changed int(11) DEFAULT '0' NOT NULL;");
146 update_sql("ALTER TABLE node CHANGE timestamp created int(11) DEFAULT '0' NOT NULL;");
147 update_sql("ALTER TABLE node CHANGE comment comment int(2) DEFAULT '0' NOT NULL;");
148 update_sql("ALTER TABLE node CHANGE promote promote int(2) DEFAULT '0' NOT NULL;");
149 update_sql("ALTER TABLE node CHANGE moderate moderate int(2) DEFAULT '0' NOT NULL;");
150 update_sql("ALTER TABLE node DROP timestamp_posted;");
151 update_sql("ALTER TABLE node DROP timestamp_queued;");
152 update_sql("ALTER TABLE node DROP timestamp_hidden;");
153 update_sql("UPDATE node SET status = 0 WHERE status = 1;");
154 update_sql("UPDATE node SET status = 0 WHERE status = 2;");
155 update_sql("UPDATE node SET status = 1 WHERE status = 3;");
156
157 $result = db_query("SELECT nid FROM node");
158
159 while ($object = db_fetch_object($result)) {
160
161 $node = node_load(array("nid" => $object->nid));
162
163 $body = db_result(db_query("SELECT body_old FROM $node->type WHERE nid = $node->nid"), 0);
164
165 switch ($node->type) {
166 case "forum":
167 case "story":
168 case "book":
169 case "page":
170 case "blog":
171 node_save($node, array("nid", "body" => $body, "teaser" => node_teaser($body)));
172 print "updated node $node->nid '$node->title' ($node->type)<br />";
173 break;
174 default:
175 print "unknown node $node->nid '$node->title' ($node->type)<br />";
176 }
177
178 unset($node);
179 unset($body);
180 }
181
182 update_sql("ALTER TABLE book DROP section;");
183 update_sql("ALTER TABLE users CHANGE session sid varchar(32) DEFAULT '' NOT NULL;");
184 }
185
186 function update_8() {
187 update_sql("ALTER TABLE node ADD revisions TEXT DEFAULT '' NOT NULL;");
188 }
189
190 function update_9() {
191 update_sql("ALTER TABLE book ADD revision int(2) DEFAULT '1' NOT NULL;");
192 update_sql("ALTER TABLE book DROP log;");
193 update_sql("ALTER TABLE book DROP pid;");
194
195 // remove book pages that used to be 'expired':
196 $result = db_query("SELECT n.nid, n.title FROM node n WHERE n.type = 'book' AND n.status = 0");
197 while ($node = db_fetch_object($result)) {
198 print "removing node $node->nid '$node->title' (dumped node)<br />";
199 db_query("DELETE FROM node WHERE nid = '$node->nid'");
200 db_query("DELETE FROM book WHERE nid = '$node->nid'");
201 db_query("DELETE FROM comments WHERE lid = '$node->nid'");
202 }
203 }
204
cd2df44 @dbuytaert - update.php:
dbuytaert authored
205 function update_10() {
206 // create a new table:
207 update_sql("CREATE TABLE authmap (
208 aid int(10) unsigned DEFAULT '0' NOT NULL auto_increment,
209 uid int(10) DEFAULT '' NOT NULL,
210 authname varchar(128) DEFAULT '' NOT NULL,
211 module varchar(128) DEFAULT '' NOT NULL,
212 UNIQUE authname (authname),
213 PRIMARY KEY (aid)
214 );");
215
216 // populate the new table:
217 $result = db_query("SELECT uid, name, jabber, drupal FROM users WHERE jabber != '' || drupal != ''");
218 while ($user = db_fetch_object($result)) {
219 if ($user->jabber) {
220 update_sql("INSERT INTO authmap (uid, authname, module) VALUES ('$user->uid', '$user->jabber', 'jabber')");
221 }
222 if ($user->drupal) {
223 update_sql("INSERT INTO authmap (uid, authname, module) VALUES ('$user->uid', '$user->drupal', 'drupal')");
224 }
225 }
226
227 // remove the old user-table leftovers:
228 update_sql("DELETE FROM variable WHERE name = 'user_jabber'");
229 update_sql("DELETE FROM variable WHERE name = 'user_drupal'");
230 update_sql("ALTER TABLE users DROP drupal");
231 update_sql("ALTER TABLE users DROP jabber");
232
233 // remove the old node-table leftovers:
234 update_sql("ALTER TABLE forum DROP body_old;");
235 update_sql("ALTER TABLE story DROP body_old;");
236 update_sql("ALTER TABLE book DROP body_old;");
237 update_sql("ALTER TABLE page DROP body_old;");
238 update_sql("ALTER TABLE blog DROP body_old;");
239 }
240
5ecedf7 @dbuytaert user.module:
dbuytaert authored
241 function update_11() {
242 update_sql("ALTER TABLE users ADD session TEXT;");
243 }
244
20b4b71 @dbuytaert - book.module:
dbuytaert authored
245 function update_12() {
246 update_sql("ALTER TABLE book DROP revision;");
247 update_sql("ALTER TABLE book ADD format tinyint(2) DEFAULT '0';");
248 }
249
0a4f99e - added update.php to replace the updates/* files to make future upgr…
Kjartan Mannes authored
250 // System functions
251 function update_sql($sql) {
252 global $edit;
253 print nl2br(check_output($sql)) ." ";
254 $result = db_query($sql);
255 if ($result) {
256 print "<font color=\"green\">OK</font>\n";
257 return 1;
258 }
259 else {
260 print "<font color=\"red\">FAILED</font>\n";
261 if ($edit["bail"]) {
262 die("Fatal error. Bailing");
263 }
264 return 0;
265 }
266 }
267
268 function update_data($start) {
269 global $mysql_updates;
270 $mysql_updates = array_slice($mysql_updates, ($start-- ? $start : 0));
271 foreach ($mysql_updates as $date=>$func) {
272 print "<b>$date</b><br />\n<pre>\n";
273 $func();
274 variable_set("update_start", $date);
275 print "</pre>\n";
276 }
277 }
278
279 function update_page() {
280 global $op, $edit, $user, $mysql_updates;
281
282 switch ($op) {
283 case "Update":
284 // make sure we have updates to run.
285 if ($edit["start"] == -1) {
286 print "No updates to perform.";
287 }
288 else {
289 update_data($edit["start"]);
290 }
291 break;
292 default:
293 $start = variable_get("update_start", 0);
294 $dates[] = "All";
295 $i = 1;
296 foreach ($mysql_updates as $date=>$sql) {
297 $dates[$i++] = $date;
298 if ($date == $start) {
299 $selected = $i;
300 }
301 }
302 $dates[$i] = "None";
303
304 // make update form and output it.
305 $form .= form_select("Perform updates since", "start", (isset($selected) ? $selected : -1), $dates);
306 $form .= form_select("Bail on errors", "bail", 0, array("Disabled", "Enabled"), "Don't forget to backup your database before performing an update.");
307 $form .= form_submit("Update");
308 print form($form);
309 break;
310 }
cd2df44 @dbuytaert - update.php:
dbuytaert authored
311
0a4f99e - added update.php to replace the updates/* files to make future upgr…
Kjartan Mannes authored
312 }
313
314 print "<html><h1>Drupal update</h1>";
315 if (user_access(NULL)) {
316 update_page();
317 }
318 else {
319 print message_access();
320 }
321 print "</html>";
322 ?>
Something went wrong with that request. Please try again.