3 define( 'UPDATE_VERSION' , 1070 );
7 * update.php - automatic system update
9 * Automatically update database schemas and any other development changes such that
10 * copying the latest files from the source code repository will always perform a clean
11 * and painless upgrade.
13 * Each function in this file is named update_nnnn() where nnnn is an increasing number
14 * which began counting at 1000.
16 * At the top of the file "boot.php" is a define for DB_UPDATE_VERSION. Any time there is a change
17 * to the database schema or one which requires an upgrade path from the existing application,
18 * the DB_UPDATE_VERSION and the UPDATE_VERSION at the top of this file are incremented.
20 * The current DB_UPDATE_VERSION is stored in the config area of the database. If the application starts up
21 * and DB_UPDATE_VERSION is greater than the last stored build number, we will process every update function
22 * in order from the currently stored value to the new DB_UPDATE_VERSION. This is expected to bring the system
23 * up to current without requiring re-installation or manual intervention.
25 * Once the upgrade functions have completed, the current DB_UPDATE_VERSION is stored as the current value.
26 * The DB_UPDATE_VERSION will always be one greater than the last numbered script in this file.
28 * If you change the database schema, the following are required:
29 * 1. Update the file database.sql to match the new schema.
30 * 2. Update this file by adding a new function at the end with the number of the current DB_UPDATE_VERSION.
31 * This function should modify the current database schema and perform any other steps necessary
32 * to ensure that upgrade is silent and free from requiring interaction.
33 * 3. Increment the DB_UPDATE_VERSION in boot.php *AND* the UPDATE_VERSION in this file to match it
34 * 4. TEST the upgrade prior to checkin and filing a pull request.
40 function update_1000() {
42 q("ALTER TABLE `item` DROP `like`, DROP `dislike` ");
44 q("ALTER TABLE `item` ADD `verb` CHAR( 255 ) NOT NULL AFTER `body` ,
45 ADD `object-type` CHAR( 255 ) NOT NULL AFTER `verb` ,
46 ADD `object` TEXT NOT NULL AFTER `object-type` ");
48 q("ALTER TABLE `intro` ADD `duplex` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `knowyou` ");
49 q("ALTER TABLE `contact` ADD `duplex` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `rel` ");
50 q("ALTER TABLE `contact` CHANGE `issued-pubkey` `issued-pubkey` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
51 q("ALTER TABLE `contact` ADD `term-date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `avatar-date`");
54 function update_1001() {
55 q("ALTER TABLE `item` ADD `wall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `type` ");
56 q("ALTER TABLE `item` ADD INDEX ( `wall` )");
59 function update_1002() {
60 q("ALTER TABLE `item` ADD `gravity` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `wall` ");
63 function update_1003() {
64 q("ALTER TABLE `contact` DROP `issued-pubkey` , DROP `ret-id` , DROP `ret-pubkey` ");
65 q("ALTER TABLE `contact` ADD `usehub` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `ret-aes`");
66 q("ALTER TABLE `contact` ADD `hub-verify` CHAR( 255 ) NOT NULL AFTER `usehub`");
67 q("ALTER TABLE `contact` ADD INDEX ( `uid` ) , ADD INDEX ( `self` ), ADD INDEX ( `issued-id` ), ADD INDEX ( `dfrn-id` )");
68 q("ALTER TABLE `contact` ADD INDEX ( `blocked` ), ADD INDEX ( `readonly` )");
71 function update_1004() {
72 q("ALTER TABLE `contact` ADD `subhub` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `usehub`");
75 function update_1005() {
77 q("ALTER TABLE `user` ADD `spubkey` TEXT NOT NULL AFTER `prvkey` ,
78 ADD `sprvkey` TEXT NOT NULL AFTER `spubkey`");
82 function update_1006() {
84 // create 's' keys for everybody that does not have one
86 $r = q("SELECT * FROM `user` WHERE `spubkey` = '' ");
89 $sres=openssl_pkey_new(array('encrypt_key' => false ));
91 openssl_pkey_export($sres, $sprvkey);
92 $spkey = openssl_pkey_get_details($sres);
93 $spubkey = $spkey["key"];
94 $r = q("UPDATE `user` SET `spubkey` = '%s', `sprvkey` = '%s'
95 WHERE `uid` = %d LIMIT 1",
104 function update_1007() {
105 q("ALTER TABLE `user` ADD `page-flags` INT NOT NULL DEFAULT '0' AFTER `notify-flags`");
106 q("ALTER TABLE `user` ADD INDEX ( `nickname` )");
109 function update_1008() {
110 q("ALTER TABLE `profile` ADD `with` TEXT NOT NULL AFTER `marital` ");
113 function update_1009() {
114 q("ALTER TABLE `user` ADD `allow_location` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `default-location` ");
117 function update_1010() {
118 q("ALTER TABLE `contact` ADD `lrdd` CHAR( 255 ) NOT NULL AFTER `url` ");
121 function update_1011() {
122 q("ALTER TABLE `contact` ADD `nick` CHAR( 255 ) NOT NULL AFTER `name` ");
123 $r = q("SELECT * FROM `contact` WHERE 1");
126 q("UPDATE `contact` SET `nick` = '%s' WHERE `id` = %d LIMIT 1",
127 dbesc(basename($rr['url'])),
134 function update_1012() {
135 q("ALTER TABLE `item` ADD `inform` MEDIUMTEXT NOT NULL AFTER `tag` ");
138 function update_1013() {
139 q("ALTER TABLE `item` ADD `target-type` CHAR( 255 ) NOT NULL
140 AFTER `object` , ADD `target` TEXT NOT NULL AFTER `target-type`");
143 function update_1014() {
144 require_once('include/Photo.php');
145 q("ALTER TABLE `contact` ADD `micro` TEXT NOT NULL AFTER `thumb` ");
146 $r = q("SELECT * FROM `photo` WHERE `scale` = 4");
149 $ph = new Photo($rr['data']);
150 if($ph->is_valid()) {
152 $ph->store($rr['uid'],$rr['contact-id'],$rr['resource-id'],$rr['filename'],$rr['album'],6,(($rr['profile']) ? 1 : 0));
156 $r = q("SELECT * FROM `contact` WHERE 1");
159 if(stristr($rr['thumb'],'avatar'))
160 q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d LIMIT 1",
161 dbesc(str_replace('avatar','micro',$rr['thumb'])),
164 q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d LIMIT 1",
165 dbesc(str_replace('5.jpg','6.jpg',$rr['thumb'])),
171 function update_1015() {
172 q("ALTER TABLE `item` CHANGE `body` `body` mediumtext NOT NULL");
175 function update_1016() {
176 q("ALTER TABLE `user` ADD `openid` CHAR( 255 ) NOT NULL AFTER `email` ");
179 function update_1017() {
181 q(" CREATE TABLE IF NOT EXISTS `clients` (
182 `client_id` VARCHAR( 20 ) NOT NULL ,
183 `pw` VARCHAR( 20 ) NOT NULL ,
184 `redirect_uri` VARCHAR( 200 ) NOT NULL ,
185 PRIMARY KEY ( `client_id` )
186 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
188 q(" CREATE TABLE IF NOT EXISTS `tokens` (
189 `id` VARCHAR( 40 ) NOT NULL ,
190 `client_id` VARCHAR( 20 ) NOT NULL ,
191 `expires` INT NOT NULL ,
192 `scope` VARCHAR( 200 ) NOT NULL ,
194 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
196 q("CREATE TABLE IF NOT EXISTS `auth_codes` (
197 `id` VARCHAR( 40 ) NOT NULL ,
198 `client_id` VARCHAR( 20 ) NOT NULL ,
199 `redirect_uri` VARCHAR( 200 ) NOT NULL ,
200 `expires` INT NOT NULL ,
201 `scope` VARCHAR( 250 ) NOT NULL ,
203 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
207 function update_1018() {
208 q("CREATE TABLE IF NOT EXISTS `queue` (
209 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
211 `created` DATETIME NOT NULL ,
212 `last` DATETIME NOT NULL ,
213 `content` MEDIUMTEXT NOT NULL
214 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
217 function update_1019() {
218 q("ALTER TABLE `mail` DROP `delivered`");
219 q("ALTER TABLE `profile` ADD `showwith` TINYINT(1) NOT NULL DEFAULT '0' AFTER `marital` ");
222 function update_1020() {
223 q("ALTER TABLE `profile` DROP `showwith`");
224 q("ALTER TABLE `item` ADD `thr-parent` CHAR( 255 ) NOT NULL AFTER `parent-uri` ");
227 function update_1021() {
228 q("ALTER TABLE `profile_check` ADD `sec` CHAR( 255 ) NOT NULL AFTER `dfrn_id` ");
229 q("ALTER TABLE `profile_check` ADD `cid` INT(10) unsigned NOT NULL DEFAULT '0' AFTER `uid`");
230 q("ALTER TABLE `item` ADD `private` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `deny_gid` ");
233 function update_1022() {
234 q("CREATE TABLE `pconfig` (
235 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
236 `uid` INT NOT NULL DEFAULT '0',
237 `cat` CHAR( 255 ) NOT NULL ,
238 `k` CHAR( 255 ) NOT NULL ,
239 `v` MEDIUMTEXT NOT NULL
240 ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci ");
243 function update_1023() {
244 q("ALTER TABLE `user` ADD `register_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `timezone` ,
245 ADD `login_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `register_date` ");
248 function update_1024() {
249 q("ALTER TABLE `profile` ADD `keywords` TEXT NOT NULL AFTER `religion` ");
252 function update_1025() {
253 q("ALTER TABLE `user` ADD `maxreq` int(11) NOT NULL DEFAULT '10' AFTER `pwdreset` ");
256 function update_1026() {
257 q("CREATE TABLE IF NOT EXISTS `hook` (
258 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
259 `hook` CHAR( 255 ) NOT NULL ,
260 `file` CHAR( 255 ) NOT NULL ,
261 `function` CHAR( 255 ) NOT NULL
262 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
266 function update_1027() {
267 q("CREATE TABLE IF NOT EXISTS `addon` (
268 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
269 `name` CHAR( 255 ) NOT NULL ,
270 `version` CHAR( 255 ) NOT NULL ,
271 `installed` TINYINT( 1 ) NOT NULL DEFAULT '0'
272 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
275 function update_1028() {
276 q("ALTER TABLE `user` ADD `openidserver` text NOT NULL AFTER `deny_gid` ");
279 function update_1029() {
280 q("ALTER TABLE `contact` ADD `info` MEDIUMTEXT NOT NULL AFTER `reason` ");
283 function update_1030() {
284 q("ALTER TABLE `contact` ADD `bdyear` CHAR( 4 ) NOT NULL COMMENT 'birthday notify flag' AFTER `profile-id` ");
286 q("CREATE TABLE IF NOT EXISTS `event` (
287 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
290 `created` DATETIME NOT NULL ,
291 `edited` DATETIME NOT NULL ,
292 `start` DATETIME NOT NULL ,
293 `finish` DATETIME NOT NULL ,
294 `desc` TEXT NOT NULL ,
295 `location` TEXT NOT NULL ,
296 `type` CHAR( 255 ) NOT NULL ,
297 `adjust` TINYINT( 1 ) NOT NULL DEFAULT '1',
298 `allow_cid` MEDIUMTEXT NOT NULL ,
299 `allow_gid` MEDIUMTEXT NOT NULL ,
300 `deny_cid` MEDIUMTEXT NOT NULL ,
301 `deny_gid` MEDIUMTEXT NOT NULL
302 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
307 function update_1031() {
308 // Repair any bad links that slipped into the item table
309 $r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' ");
310 if($r && count($r)) {
312 if(strstr($rr['object'],'type="http')) {
313 q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d LIMIT 1",
314 dbesc(str_replace('type="http','href="http',$rr['object'])),
322 function update_1032() {
323 q("ALTER TABLE `profile` ADD `pdesc` CHAR( 255 ) NOT NULL AFTER `name` ");
326 function update_1033() {
327 q("CREATE TABLE IF NOT EXISTS `cache` (
328 `k` CHAR( 255 ) NOT NULL PRIMARY KEY ,
330 `updated` DATETIME NOT NULL
331 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
335 function update_1034() {
337 // If you have any of these parent-less posts they can cause problems, and
338 // we need to delete them. You can't see them anyway.
339 // Legitimate items will usually get re-created on the next
340 // pull from the hub.
341 // But don't get rid of a post that may have just come in
342 // and may not yet have the parent id set.
344 q("DELETE FROM `item` WHERE `parent` = 0 AND `created` < UTC_TIMESTAMP() - INTERVAL 2 MINUTE");
349 function update_1035() {
351 q("ALTER TABLE `contact` ADD `success_update` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `last-update` ");
355 function update_1036() {
357 $r = dbq("SELECT * FROM `contact` WHERE `network` = 'dfrn' && `photo` LIKE '%include/photo%' ");
360 q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `id` = %d LIMIT 1",
361 dbesc(str_replace('include/photo','photo',$rr['photo'])),
362 dbesc(str_replace('include/photo','photo',$rr['thumb'])),
363 dbesc(str_replace('include/photo','photo',$rr['micro'])),
369 function update_1037() {
371 q("ALTER TABLE `contact` CHANGE `lrdd` `alias` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
375 function update_1038() {
376 q("ALTER TABLE `item` ADD `plink` CHAR( 255 ) NOT NULL AFTER `target` ");
379 function update_1039() {
380 q("ALTER TABLE `addon` ADD `timestamp` BIGINT NOT NULL DEFAULT '0'");
384 function update_1040() {
386 q("CREATE TABLE IF NOT EXISTS `fcontact` (
387 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
388 `url` CHAR( 255 ) NOT NULL ,
389 `name` CHAR( 255 ) NOT NULL ,
390 `photo` CHAR( 255 ) NOT NULL
391 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
393 q("CREATE TABLE IF NOT EXISTS `ffinder` (
394 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
395 `uid` INT UNSIGNED NOT NULL ,
396 `cid` INT UNSIGNED NOT NULL ,
397 `fid` INT UNSIGNED NOT NULL
398 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
402 function update_1041() {
403 q("ALTER TABLE `profile` CHANGE `keywords` `prv_keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
404 q("ALTER TABLE `profile` ADD `pub_keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `religion` ");
407 function update_1042() {
408 q("ALTER TABLE `user` ADD `expire` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `maxreq` ");
412 function update_1043() {
413 q("ALTER TABLE `user` ADD `blockwall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocked` ");
416 function update_1044() {
417 q("ALTER TABLE `profile` ADD FULLTEXT ( `pub_keywords` ) ");
418 q("ALTER TABLE `profile` ADD FULLTEXT ( `prv_keywords` ) ");
421 function update_1045() {
422 q("ALTER TABLE `user` ADD `language` CHAR( 16 ) NOT NULL DEFAULT 'en' AFTER `timezone` ");
425 function update_1046() {
426 q("ALTER TABLE `item` ADD `attach` MEDIUMTEXT NOT NULL AFTER `tag` ");
429 function update_1047() {
430 q("ALTER TABLE `contact` ADD `writable` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `readonly` ");
433 function update_1048() {
434 q("UPDATE `contact` SET `writable` = 1 WHERE `network` = 'stat' AND `notify` != '' ");
437 function update_1049() {
438 q("CREATE TABLE `mailacct` (
439 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
441 `server` CHAR( 255 ) NOT NULL ,
442 `user` CHAR( 255 ) NOT NULL ,
443 `pass` CHAR( 255 ) NOT NULL ,
444 `reply_to` CHAR( 255 ) NOT NULL ,
445 `last_check` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
446 ) ENGINE = MYISAM ");
449 function update_1050() {
450 q("CREATE TABLE `attach` (
451 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
453 `filetype` CHAR( 64 ) NOT NULL ,
454 `filesize` INT NOT NULL ,
455 `data` LONGBLOB NOT NULL ,
456 `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
457 `edited` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
458 `allow_cid` MEDIUMTEXT NOT NULL ,
459 `allow_gid` MEDIUMTEXT NOT NULL ,
460 `deny_cid` MEDIUMTEXT NOT NULL ,
461 `deny_gid` MEDIUMTEXT NOT NULL
462 ) ENGINE = MYISAM ");
466 function update_1051() {
467 q("ALTER TABLE `mailacct` ADD `port` INT NOT NULL AFTER `server` ,
468 ADD `ssltype` CHAR( 16 ) NOT NULL AFTER `port` ,
469 ADD `mailbox` CHAR( 255 ) NOT NULL AFTER `ssltype` ");
471 q("ALTER TABLE `contact` ADD `addr` CHAR( 255 ) NOT NULL AFTER `url` ");
474 function update_1052() {
475 q("ALTER TABLE `mailacct` CHANGE `pass` `pass` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
476 q("ALTER TABLE `mailacct` ADD `pubmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `reply_to` ");
477 q("ALTER TABLE `item` ADD `pubmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `private` ");
481 function update_1053() {
482 q("ALTER TABLE `item` ADD `extid` CHAR( 255 ) NOT NULL AFTER `parent-uri` , ADD INDEX ( `extid` ) ");
485 function update_1054() {
486 q("ALTER TABLE `register` ADD `language` CHAR( 16 ) NOT NULL AFTER `password` ");
489 function update_1055() {
490 q("ALTER TABLE `profile` ADD `hidewall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `hide-friends` ");
493 function update_1056() {
494 q("ALTER TABLE `attach` ADD `hash` CHAR( 64 ) NOT NULL AFTER `uid` ");
497 function update_1057() {
498 q("ALTER TABLE `attach` ADD `filename` CHAR( 255 ) NOT NULL AFTER `hash` ");
501 function update_1058() {
502 q("ALTER TABLE `item` ADD `event-id` INT NOT NULL AFTER `resource-id` ");
505 function update_1059() {
506 q("ALTER TABLE `queue` ADD `network` CHAR( 32 ) NOT NULL AFTER `cid` ");
509 function update_1060() {
510 q("ALTER TABLE `event` ADD `uri` CHAR( 255 ) NOT NULL AFTER `cid` ");
513 function update_1061() {
514 q("ALTER TABLE `event` ADD `nofinish` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `type` ");
517 function update_1062() {
518 q("ALTER TABLE `user` ADD `prvnets` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `page-flags` ");
520 function update_1063() {
521 q("ALTER TABLE `addon` ADD `plugin_admin` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `timestamp` ");
524 function update_1064() {
525 q("ALTER TABLE `item` ADD `app` CHAR( 255 ) NOT NULL AFTER `body` ");
528 function update_1065() {
529 q("ALTER TABLE `intro` ADD `fid` INT NOT NULL DEFAULT '0' AFTER `uid`");
532 function update_1066() {
533 $r = q("ALTER TABLE `item` ADD `received` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `edited` ");
535 q("ALTER TABLE `item` ADD INDEX ( `received` ) ");
537 $r = q("UPDATE `item` SET `received` = `edited` WHERE 1");
540 function update_1067() {
541 q("ALTER TABLE `ffinder` ADD `type` CHAR( 16 ) NOT NULL AFTER `id` ,
542 ADD `note` TEXT NOT NULL AFTER `type` ");
545 function update_1068() {
546 // 1067 was short-sighted. Undo it.
547 q("ALTER TABLE `ffinder` DROP `type` , DROP `note` ");
549 // and do this instead.
551 q("CREATE TABLE IF NOT EXISTS `fsuggest` (
552 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
555 `name` CHAR( 255 ) NOT NULL ,
556 `url` CHAR( 255 ) NOT NULL ,
557 `photo` CHAR( 255 ) NOT NULL ,
558 `note` TEXT NOT NULL ,
559 `created` DATETIME NOT NULL
560 ) ENGINE = MYISAM DEFAULT CHARSET=utf8");
564 function update_1069() {
565 q("ALTER TABLE `fsuggest` ADD `request` CHAR( 255 ) NOT NULL AFTER `url` ");
566 q("ALTER TABLE `fcontact` ADD `request` CHAR( 255 ) NOT NULL AFTER `photo` ");