3 define( 'UPDATE_VERSION' , 1194 );
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 include/dbstructure.php to match the new schema.
30 * 2. If there is a need for a post procession, update this file by adding a new function at the end with the number of the current DB_UPDATE_VERSION.
31 * This function should perform some post procession steps but no database updates.
32 * 3. Increment the DB_UPDATE_VERSION in boot.php *AND* the UPDATE_VERSION in this file to match it
33 * 4. TEST the upgrade prior to checkin and filing a pull request.
36 * NEVER do a database change anymore in the update functions! Only do this in the file include/dbstructure.php!
41 function update_1000() {
43 q("ALTER TABLE `item` DROP `like`, DROP `dislike` ");
45 q("ALTER TABLE `item` ADD `verb` CHAR( 255 ) NOT NULL AFTER `body` ,
46 ADD `object-type` CHAR( 255 ) NOT NULL AFTER `verb` ,
47 ADD `object` TEXT NOT NULL AFTER `object-type` ");
49 q("ALTER TABLE `intro` ADD `duplex` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `knowyou` ");
50 q("ALTER TABLE `contact` ADD `duplex` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `rel` ");
51 q("ALTER TABLE `contact` CHANGE `issued-pubkey` `issued-pubkey` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
52 q("ALTER TABLE `contact` ADD `term-date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `avatar-date`");
55 function update_1001() {
56 q("ALTER TABLE `item` ADD `wall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `type` ");
57 q("ALTER TABLE `item` ADD INDEX ( `wall` )");
60 function update_1002() {
61 q("ALTER TABLE `item` ADD `gravity` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `wall` ");
64 function update_1003() {
65 q("ALTER TABLE `contact` DROP `issued-pubkey` , DROP `ret-id` , DROP `ret-pubkey` ");
66 q("ALTER TABLE `contact` ADD `usehub` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `ret-aes`");
67 q("ALTER TABLE `contact` ADD `hub-verify` CHAR( 255 ) NOT NULL AFTER `usehub`");
68 q("ALTER TABLE `contact` ADD INDEX ( `uid` ) , ADD INDEX ( `self` ), ADD INDEX ( `issued-id` ), ADD INDEX ( `dfrn-id` )");
69 q("ALTER TABLE `contact` ADD INDEX ( `blocked` ), ADD INDEX ( `readonly` )");
72 function update_1004() {
73 q("ALTER TABLE `contact` ADD `subhub` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `usehub`");
76 function update_1005() {
78 q("ALTER TABLE `user` ADD `spubkey` TEXT NOT NULL AFTER `prvkey` ,
79 ADD `sprvkey` TEXT NOT NULL AFTER `spubkey`");
83 function update_1006() {
85 // create 's' keys for everybody that does not have one
87 $r = q("SELECT * FROM `user` WHERE `spubkey` = '' ");
90 $sres=openssl_pkey_new(array('encrypt_key' => false ));
92 openssl_pkey_export($sres, $sprvkey);
93 $spkey = openssl_pkey_get_details($sres);
94 $spubkey = $spkey["key"];
95 $r = q("UPDATE `user` SET `spubkey` = '%s', `sprvkey` = '%s'
105 function update_1007() {
106 q("ALTER TABLE `user` ADD `page-flags` INT NOT NULL DEFAULT '0' AFTER `notify-flags`");
107 q("ALTER TABLE `user` ADD INDEX ( `nickname` )");
110 function update_1008() {
111 q("ALTER TABLE `profile` ADD `with` TEXT NOT NULL AFTER `marital` ");
114 function update_1009() {
115 q("ALTER TABLE `user` ADD `allow_location` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `default-location` ");
118 function update_1010() {
119 q("ALTER TABLE `contact` ADD `lrdd` CHAR( 255 ) NOT NULL AFTER `url` ");
122 function update_1011() {
123 q("ALTER TABLE `contact` ADD `nick` CHAR( 255 ) NOT NULL AFTER `name` ");
124 $r = q("SELECT * FROM `contact` WHERE 1");
127 q("UPDATE `contact` SET `nick` = '%s' WHERE `id` = %d",
128 dbesc(basename($rr['url'])),
135 function update_1012() {
136 q("ALTER TABLE `item` ADD `inform` MEDIUMTEXT NOT NULL AFTER `tag` ");
139 function update_1013() {
140 q("ALTER TABLE `item` ADD `target-type` CHAR( 255 ) NOT NULL
141 AFTER `object` , ADD `target` TEXT NOT NULL AFTER `target-type`");
144 function update_1014() {
145 require_once('include/Photo.php');
146 q("ALTER TABLE `contact` ADD `micro` TEXT NOT NULL AFTER `thumb` ");
147 $r = q("SELECT * FROM `photo` WHERE `scale` = 4");
150 $ph = new Photo($rr['data']);
151 if($ph->is_valid()) {
153 $ph->store($rr['uid'],$rr['contact-id'],$rr['resource-id'],$rr['filename'],$rr['album'],6,(($rr['profile']) ? 1 : 0));
157 $r = q("SELECT * FROM `contact` WHERE 1");
160 if(stristr($rr['thumb'],'avatar'))
161 q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d",
162 dbesc(str_replace('avatar','micro',$rr['thumb'])),
165 q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d",
166 dbesc(str_replace('5.jpg','6.jpg',$rr['thumb'])),
172 function update_1015() {
173 q("ALTER TABLE `item` CHANGE `body` `body` mediumtext NOT NULL");
176 function update_1016() {
177 q("ALTER TABLE `user` ADD `openid` CHAR( 255 ) NOT NULL AFTER `email` ");
180 function update_1017() {
182 q(" CREATE TABLE IF NOT EXISTS `clients` (
183 `client_id` VARCHAR( 20 ) NOT NULL ,
184 `pw` VARCHAR( 20 ) NOT NULL ,
185 `redirect_uri` VARCHAR( 200 ) NOT NULL ,
186 PRIMARY KEY ( `client_id` )
187 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
189 q(" CREATE TABLE IF NOT EXISTS `tokens` (
190 `id` VARCHAR( 40 ) NOT NULL ,
191 `client_id` VARCHAR( 20 ) NOT NULL ,
192 `expires` INT NOT NULL ,
193 `scope` VARCHAR( 200 ) NOT NULL ,
195 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
197 q("CREATE TABLE IF NOT EXISTS `auth_codes` (
198 `id` VARCHAR( 40 ) NOT NULL ,
199 `client_id` VARCHAR( 20 ) NOT NULL ,
200 `redirect_uri` VARCHAR( 200 ) NOT NULL ,
201 `expires` INT NOT NULL ,
202 `scope` VARCHAR( 250 ) NOT NULL ,
204 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
208 function update_1018() {
209 q("CREATE TABLE IF NOT EXISTS `queue` (
210 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
212 `created` DATETIME NOT NULL ,
213 `last` DATETIME NOT NULL ,
214 `content` MEDIUMTEXT NOT NULL
215 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
218 function update_1019() {
219 q("ALTER TABLE `mail` DROP `delivered`");
220 q("ALTER TABLE `profile` ADD `showwith` TINYINT(1) NOT NULL DEFAULT '0' AFTER `marital` ");
223 function update_1020() {
224 q("ALTER TABLE `profile` DROP `showwith`");
225 q("ALTER TABLE `item` ADD `thr-parent` CHAR( 255 ) NOT NULL AFTER `parent-uri` ");
228 function update_1021() {
229 q("ALTER TABLE `profile_check` ADD `sec` CHAR( 255 ) NOT NULL AFTER `dfrn_id` ");
230 q("ALTER TABLE `profile_check` ADD `cid` INT(10) unsigned NOT NULL DEFAULT '0' AFTER `uid`");
231 q("ALTER TABLE `item` ADD `private` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `deny_gid` ");
234 function update_1022() {
235 q("CREATE TABLE `pconfig` (
236 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
237 `uid` INT NOT NULL DEFAULT '0',
238 `cat` CHAR( 255 ) NOT NULL ,
239 `k` CHAR( 255 ) NOT NULL ,
240 `v` MEDIUMTEXT NOT NULL
241 ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci ");
244 function update_1023() {
245 q("ALTER TABLE `user` ADD `register_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `timezone` ,
246 ADD `login_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `register_date` ");
249 function update_1024() {
250 q("ALTER TABLE `profile` ADD `keywords` TEXT NOT NULL AFTER `religion` ");
253 function update_1025() {
254 q("ALTER TABLE `user` ADD `maxreq` int(11) NOT NULL DEFAULT '10' AFTER `pwdreset` ");
257 function update_1026() {
258 q("CREATE TABLE IF NOT EXISTS `hook` (
259 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
260 `hook` CHAR( 255 ) NOT NULL ,
261 `file` CHAR( 255 ) NOT NULL ,
262 `function` CHAR( 255 ) NOT NULL
263 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
267 function update_1027() {
268 q("CREATE TABLE IF NOT EXISTS `addon` (
269 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
270 `name` CHAR( 255 ) NOT NULL ,
271 `version` CHAR( 255 ) NOT NULL ,
272 `installed` TINYINT( 1 ) NOT NULL DEFAULT '0'
273 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
276 function update_1028() {
277 q("ALTER TABLE `user` ADD `openidserver` text NOT NULL AFTER `deny_gid` ");
280 function update_1029() {
281 q("ALTER TABLE `contact` ADD `info` MEDIUMTEXT NOT NULL AFTER `reason` ");
284 function update_1030() {
285 q("ALTER TABLE `contact` ADD `bdyear` CHAR( 4 ) NOT NULL COMMENT 'birthday notify flag' AFTER `profile-id` ");
287 q("CREATE TABLE IF NOT EXISTS `event` (
288 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
291 `created` DATETIME NOT NULL ,
292 `edited` DATETIME NOT NULL ,
293 `start` DATETIME NOT NULL ,
294 `finish` DATETIME NOT NULL ,
295 `desc` TEXT NOT NULL ,
296 `location` TEXT NOT NULL ,
297 `type` CHAR( 255 ) NOT NULL ,
298 `adjust` TINYINT( 1 ) NOT NULL DEFAULT '1',
299 `allow_cid` MEDIUMTEXT NOT NULL ,
300 `allow_gid` MEDIUMTEXT NOT NULL ,
301 `deny_cid` MEDIUMTEXT NOT NULL ,
302 `deny_gid` MEDIUMTEXT NOT NULL
303 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
308 function update_1031() {
309 // Repair any bad links that slipped into the item table
310 $r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' ");
311 if($r && count($r)) {
313 if(strstr($rr['object'],'type="http')) {
314 q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d",
315 dbesc(str_replace('type="http','href="http',$rr['object'])),
323 function update_1032() {
324 q("ALTER TABLE `profile` ADD `pdesc` CHAR( 255 ) NOT NULL AFTER `name` ");
327 function update_1033() {
328 q("CREATE TABLE IF NOT EXISTS `cache` (
329 `k` CHAR( 255 ) NOT NULL PRIMARY KEY ,
331 `updated` DATETIME NOT NULL
332 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
336 function update_1034() {
338 // If you have any of these parent-less posts they can cause problems, and
339 // we need to delete them. You can't see them anyway.
340 // Legitimate items will usually get re-created on the next
341 // pull from the hub.
342 // But don't get rid of a post that may have just come in
343 // and may not yet have the parent id set.
345 q("DELETE FROM `item` WHERE `parent` = 0 AND `created` < UTC_TIMESTAMP() - INTERVAL 2 MINUTE");
350 function update_1035() {
352 q("ALTER TABLE `contact` ADD `success_update` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `last-update` ");
356 function update_1036() {
358 $r = dbq("SELECT * FROM `contact` WHERE `network` = 'dfrn' && `photo` LIKE '%include/photo%' ");
361 q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `id` = %d",
362 dbesc(str_replace('include/photo','photo',$rr['photo'])),
363 dbesc(str_replace('include/photo','photo',$rr['thumb'])),
364 dbesc(str_replace('include/photo','photo',$rr['micro'])),
370 function update_1037() {
372 q("ALTER TABLE `contact` CHANGE `lrdd` `alias` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
376 function update_1038() {
377 q("ALTER TABLE `item` ADD `plink` CHAR( 255 ) NOT NULL AFTER `target` ");
380 function update_1039() {
381 q("ALTER TABLE `addon` ADD `timestamp` BIGINT NOT NULL DEFAULT '0'");
385 function update_1040() {
387 q("CREATE TABLE IF NOT EXISTS `fcontact` (
388 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
389 `url` CHAR( 255 ) NOT NULL ,
390 `name` CHAR( 255 ) NOT NULL ,
391 `photo` CHAR( 255 ) NOT NULL
392 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
394 q("CREATE TABLE IF NOT EXISTS `ffinder` (
395 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
396 `uid` INT UNSIGNED NOT NULL ,
397 `cid` INT UNSIGNED NOT NULL ,
398 `fid` INT UNSIGNED NOT NULL
399 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
403 function update_1041() {
404 q("ALTER TABLE `profile` CHANGE `keywords` `prv_keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
405 q("ALTER TABLE `profile` ADD `pub_keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `religion` ");
408 function update_1042() {
409 q("ALTER TABLE `user` ADD `expire` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `maxreq` ");
413 function update_1043() {
414 q("ALTER TABLE `user` ADD `blockwall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocked` ");
417 function update_1044() {
418 q("ALTER TABLE `profile` ADD FULLTEXT ( `pub_keywords` ) ");
419 q("ALTER TABLE `profile` ADD FULLTEXT ( `prv_keywords` ) ");
422 function update_1045() {
423 q("ALTER TABLE `user` ADD `language` CHAR( 16 ) NOT NULL DEFAULT 'en' AFTER `timezone` ");
426 function update_1046() {
427 q("ALTER TABLE `item` ADD `attach` MEDIUMTEXT NOT NULL AFTER `tag` ");
430 function update_1047() {
431 q("ALTER TABLE `contact` ADD `writable` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `readonly` ");
434 function update_1048() {
435 q("UPDATE `contact` SET `writable` = 1 WHERE `network` = 'stat' AND `notify` != '' ");
438 function update_1049() {
439 q("CREATE TABLE `mailacct` (
440 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
442 `server` CHAR( 255 ) NOT NULL ,
443 `user` CHAR( 255 ) NOT NULL ,
444 `pass` CHAR( 255 ) NOT NULL ,
445 `reply_to` CHAR( 255 ) NOT NULL ,
446 `last_check` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
447 ) ENGINE = MYISAM ");
450 function update_1050() {
451 q("CREATE TABLE `attach` (
452 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
454 `filetype` CHAR( 64 ) NOT NULL ,
455 `filesize` INT NOT NULL ,
456 `data` LONGBLOB NOT NULL ,
457 `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
458 `edited` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
459 `allow_cid` MEDIUMTEXT NOT NULL ,
460 `allow_gid` MEDIUMTEXT NOT NULL ,
461 `deny_cid` MEDIUMTEXT NOT NULL ,
462 `deny_gid` MEDIUMTEXT NOT NULL
463 ) ENGINE = MYISAM ");
467 function update_1051() {
468 q("ALTER TABLE `mailacct` ADD `port` INT NOT NULL AFTER `server` ,
469 ADD `ssltype` CHAR( 16 ) NOT NULL AFTER `port` ,
470 ADD `mailbox` CHAR( 255 ) NOT NULL AFTER `ssltype` ");
472 q("ALTER TABLE `contact` ADD `addr` CHAR( 255 ) NOT NULL AFTER `url` ");
475 function update_1052() {
476 q("ALTER TABLE `mailacct` CHANGE `pass` `pass` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
477 q("ALTER TABLE `mailacct` ADD `pubmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `reply_to` ");
478 q("ALTER TABLE `item` ADD `pubmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `private` ");
482 function update_1053() {
483 q("ALTER TABLE `item` ADD `extid` CHAR( 255 ) NOT NULL AFTER `parent-uri` , ADD INDEX ( `extid` ) ");
486 function update_1054() {
487 q("ALTER TABLE `register` ADD `language` CHAR( 16 ) NOT NULL AFTER `password` ");
490 function update_1055() {
491 q("ALTER TABLE `profile` ADD `hidewall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `hide-friends` ");
494 function update_1056() {
495 q("ALTER TABLE `attach` ADD `hash` CHAR( 64 ) NOT NULL AFTER `uid` ");
498 function update_1057() {
499 q("ALTER TABLE `attach` ADD `filename` CHAR( 255 ) NOT NULL AFTER `hash` ");
502 function update_1058() {
503 q("ALTER TABLE `item` ADD `event-id` INT NOT NULL AFTER `resource-id` ");
506 function update_1059() {
507 q("ALTER TABLE `queue` ADD `network` CHAR( 32 ) NOT NULL AFTER `cid` ");
510 function update_1060() {
511 q("ALTER TABLE `event` ADD `uri` CHAR( 255 ) NOT NULL AFTER `cid` ");
514 function update_1061() {
515 q("ALTER TABLE `event` ADD `nofinish` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `type` ");
518 function update_1062() {
519 q("ALTER TABLE `user` ADD `prvnets` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `page-flags` ");
521 function update_1063() {
522 q("ALTER TABLE `addon` ADD `plugin_admin` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `timestamp` ");
525 function update_1064() {
526 q("ALTER TABLE `item` ADD `app` CHAR( 255 ) NOT NULL AFTER `body` ");
529 function update_1065() {
530 q("ALTER TABLE `intro` ADD `fid` INT NOT NULL DEFAULT '0' AFTER `uid`");
533 function update_1066() {
534 $r = q("ALTER TABLE `item` ADD `received` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `edited` ");
536 q("ALTER TABLE `item` ADD INDEX ( `received` ) ");
538 $r = q("UPDATE `item` SET `received` = `edited` WHERE 1");
541 function update_1067() {
542 q("ALTER TABLE `ffinder` ADD `type` CHAR( 16 ) NOT NULL AFTER `id` ,
543 ADD `note` TEXT NOT NULL AFTER `type` ");
546 function update_1068() {
547 // 1067 was short-sighted. Undo it.
548 q("ALTER TABLE `ffinder` DROP `type` , DROP `note` ");
550 // and do this instead.
552 q("CREATE TABLE IF NOT EXISTS `fsuggest` (
553 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
556 `name` CHAR( 255 ) NOT NULL ,
557 `url` CHAR( 255 ) NOT NULL ,
558 `photo` CHAR( 255 ) NOT NULL ,
559 `note` TEXT NOT NULL ,
560 `created` DATETIME NOT NULL
561 ) ENGINE = MYISAM DEFAULT CHARSET=utf8");
565 function update_1069() {
566 q("ALTER TABLE `fsuggest` ADD `request` CHAR( 255 ) NOT NULL AFTER `url` ");
567 q("ALTER TABLE `fcontact` ADD `request` CHAR( 255 ) NOT NULL AFTER `photo` ");
570 // mail body needs to accomodate private photos
572 function update_1070() {
573 q("ALTER TABLE `mail` CHANGE `body` `body` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
576 function update_1071() {
577 q("ALTER TABLE `photo` ADD INDEX ( `uid` ) ");
578 q("ALTER TABLE `photo` ADD INDEX ( `resource-id` ) ");
579 q("ALTER TABLE `photo` ADD INDEX ( `album` ) ");
580 q("ALTER TABLE `photo` ADD INDEX ( `scale` ) ");
581 q("ALTER TABLE `photo` ADD INDEX ( `profile` ) ");
585 function update_1072() {
586 q("ALTER TABLE `item` ADD `starred` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` ");
587 q("ALTER TABLE `item` ADD INDEX ( `starred` ) ");
590 function update_1073() {
591 q("ALTER TABLE `contact` ADD `remote_self` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `self` ");
594 function update_1074() {
595 q("ALTER TABLE `user` ADD `hidewall` TINYINT( 1) NOT NULL DEFAULT '0' AFTER `blockwall` ");
596 $r = q("SELECT `uid` FROM `profile` WHERE `is-default` = 1 AND `hidewall` = 1");
599 q("UPDATE `user` SET `hidewall` = 1 WHERE `uid` = %d",
603 q("ALTER TABLE `profile` DROP `hidewall`");
606 function update_1075() {
607 q("ALTER TABLE `user` ADD `guid` CHAR( 16 ) NOT NULL AFTER `uid` ");
608 $r = q("SELECT `uid` FROM `user` WHERE 1");
613 $guid = substr(random_string(),0,16);
614 $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1",
619 } while ($found == true );
621 q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d",
629 function update_1076() {
630 q("CREATE TABLE `guid` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
631 `guid` CHAR( 16 ) NOT NULL , INDEX ( `guid` ) ) ENGINE = MYISAM ");
635 // There was a typo in 1076 so we'll try again in 1077 to make sure
636 // We'll also make it big enough to allow for future growth, I seriously
637 // doubt Diaspora will be able to leave guids at 16 bytes,
638 // and we can also use the same structure for our own larger guids
640 function update_1077() {
641 q("CREATE TABLE IF NOT EXISTS `guid` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
642 `guid` CHAR( 16 ) NOT NULL , INDEX ( `guid` ) ) ENGINE = MYISAM ");
644 q("ALTER TABLE `guid` CHANGE `guid` `guid` CHAR( 64 ) NOT NULL");
647 function update_1078() {
648 q("ALTER TABLE `item` ADD `guid` CHAR( 64 ) NOT NULL AFTER `id` , ADD INDEX ( `guid` ) ");
651 function update_1079() {
652 q("CREATE TABLE IF NOT EXISTS `sign` (
653 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
654 `iid` INT UNSIGNED NOT NULL ,
655 `signed_text` MEDIUMTEXT NOT NULL ,
656 `signature` TEXT NOT NULL ,
657 `signer` CHAR( 255 ) NOT NULL ,
659 ) ENGINE = MYISAM ");
661 q("ALTER TABLE `fcontact` ADD `nick` CHAR( 255 ) NOT NULL ,
662 ADD `addr` CHAR( 255 ) NOT NULL ,
663 ADD `notify` CHAR( 255 ) NOT NULL ,
664 ADD `poll` CHAR( 255 ) NOT NULL ,
665 ADD `confirm` CHAR( 255 ) NOT NULL ,
666 ADD `priority` TINYINT( 1 ) NOT NULL ,
667 ADD `network` CHAR( 32 ) NOT NULL ,
668 ADD `alias` CHAR( 255 ) NOT NULL ,
669 ADD `pubkey` TEXT NOT NULL ,
670 ADD INDEX ( `addr` ) ,
671 ADD INDEX ( `network` ) ");
675 function update_1080() {
676 q("ALTER TABLE `fcontact` ADD `updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'");
679 function update_1081() {
680 // there was a typo in update 1081 so it was corrected and moved up to 1082
683 function update_1082() {
684 q("ALTER TABLE `photo` ADD `guid` CHAR( 64 ) NOT NULL AFTER `contact-id`,
685 ADD INDEX ( `guid` ) ");
686 // make certain the following code is only executed once
687 $r = q("select `id` from `photo` where `guid` != '' limit 1");
690 $r = q("SELECT distinct(`resource-id`) FROM `photo` WHERE 1 group by `id`");
694 q("update `photo` set `guid` = '%s' where `resource-id` = '%s'",
696 dbesc($rr['resource-id'])
702 function update_1083() {
703 q("CREATE TABLE IF NOT EXISTS `deliverq` (
704 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
705 `cmd` CHAR( 32 ) NOT NULL ,
706 `item` INT NOT NULL ,
707 `contact` INT NOT NULL
708 ) ENGINE = MYISAM ");
712 function update_1084() {
713 q("ALTER TABLE `contact` ADD `attag` CHAR( 255 ) NOT NULL AFTER `nick` ");
716 function update_1085() {
717 q("CREATE TABLE IF NOT EXISTS `search` (
718 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
720 `term` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
723 ) ENGINE = MYISAM ");
726 function update_1086() {
727 q("ALTER TABLE `item` ADD `bookmark` tinyint(1) NOT NULL DEFAULT '0' AFTER `starred` ");
730 function update_1087() {
731 q("ALTER TABLE `item` ADD `commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `edited` ");
733 $r = q("SELECT `id` FROM `item` WHERE `parent` = `id` ");
736 $x = q("SELECT max(`created`) AS `cdate` FROM `item` WHERE `parent` = %d LIMIT 1",
740 q("UPDATE `item` SET `commented` = '%s' WHERE `id` = %d",
741 dbesc($x[0]['cdate']),
748 function update_1088() {
749 q("ALTER TABLE `user` ADD `account_expired` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `expire` ,
750 ADD `account_expires_on` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `account_expired` ,
751 ADD `expire_notification_sent` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `account_expires_on` ");
754 function update_1089() {
755 q("ALTER TABLE `user` ADD `blocktags` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `hidewall` ");
758 function update_1090() {
759 q("ALTER TABLE `contact` ADD `batch` char(255) NOT NULL AFTER `prvkey` ");
761 q("UPDATE `contact` SET `batch` = concat(substring_index(`url`,'/',3),'/receive/public') WHERE `network` = 'dspr' ");
765 function update_1091() {
767 // catch a few stragglers that may have crept in before we added this on remote connects
768 q("UPDATE `contact` SET `batch` = concat(substring_index(`url`,'/',3),'/receive/public') WHERE `network` = 'dspr' AND `batch` = '' ");
769 q("ALTER TABLE `queue` ADD `batch` TINYINT( 1 ) NOT NULL DEFAULT '0' ");
770 q("ALTER TABLE `fcontact` ADD `batch` char(255) NOT NULL AFTER `addr` ");
774 function update_1092() {
775 q("ALTER TABLE `user` ADD INDEX ( `login_date` ) ");
776 q("ALTER TABLE `user` ADD INDEX ( `account_expired` ) ");
779 function update_1093() {
780 q("CREATE TABLE IF NOT EXISTS `fserver` (
781 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
782 `server` CHAR( 255 ) NOT NULL ,
783 `posturl` CHAR( 255 ) NOT NULL ,
786 ) ENGINE = MYISAM ");
788 q("ALTER TABLE `group` ADD `visible` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `uid` ");
792 function update_1094() {
793 q("ALTER TABLE `item` ADD `postopts` TEXT NOT NULL AFTER `target` ");
796 function update_1095() {
797 q("ALTER TABLE `contact` ADD `bd` DATE NOT NULL AFTER `bdyear` ");
800 function update_1096() {
801 q("ALTER TABLE `item` ADD `origin` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `deleted` , ADD INDEX ( `origin` ) ");
804 function update_1097() {
805 q("ALTER TABLE `queue`
807 ADD INDEX (`created`),
809 ADD INDEX (`network`),
814 function update_1098() {
815 q("ALTER TABLE `contact`
816 ADD INDEX (`network`),
826 function update_1099() {
827 q("CREATE TABLE IF NOT EXISTS `gcontact` (
828 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
829 `name` CHAR( 255 ) NOT NULL ,
830 `url` CHAR( 255 ) NOT NULL ,
831 `nurl` CHAR( 255 ) NOT NULL ,
832 `photo` CHAR( 255 ) NOT NULL
833 ) ENGINE = MYISAM ");
835 q("CREATE TABLE IF NOT EXISTS `glink` (
836 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
840 `updated` DATETIME NOT NULL
841 ) ENGINE = MYISAM ");
843 q("ALTER TABLE `gcontact` ADD INDEX (`nurl`) ");
844 q("ALTER TABLE `glink` ADD INDEX (`cid`), ADD INDEX (`uid`), ADD INDEX (`gcid`), ADD INDEX (`updated`) ");
846 q("ALTER TABLE `contact` ADD `poco` TEXT NOT NULL AFTER `confirm` ");
850 function update_1100() {
851 q("ALTER TABLE `contact` ADD `nurl` CHAR( 255 ) NOT NULL AFTER `url` ");
852 q("alter table contact add index (`nurl`) ");
854 require_once('include/text.php');
856 $r = q("select id, url from contact where url != '' and nurl = '' ");
859 q("update contact set nurl = '%s' where id = %d",
860 dbesc(normalise_link($rr['url'])),
868 function update_1101() {
869 q("CREATE TABLE IF NOT EXISTS `gcign` (
870 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
873 ) ENGINE = MYISAM ");
875 q("ALTER TABLE `gcign` ADD INDEX (`uid`), ADD INDEX (`gcid`) ");
878 function update_1102() {
879 q("ALTER TABLE `clients` ADD `name` TEXT NULL DEFAULT NULL AFTER `redirect_uri` ");
880 q("ALTER TABLE `clients` ADD `icon` TEXT NULL DEFAULT NULL AFTER `name` ");
881 q("ALTER TABLE `clients` ADD `uid` INT NOT NULL DEFAULT 0 AFTER `icon` ");
883 q("ALTER TABLE `tokens` ADD `secret` TEXT NOT NULL AFTER `id` ");
884 q("ALTER TABLE `tokens` ADD `uid` INT NOT NULL AFTER `scope` ");
888 function update_1103() {
889 // q("ALTER TABLE `item` ADD INDEX ( `wall` ) ");
890 q("ALTER TABLE `item` ADD FULLTEXT ( `tag` ) ");
891 q("ALTER TABLE `contact` ADD INDEX ( `pending` ) ");
892 q("ALTER TABLE `user` ADD INDEX ( `hidewall` ) ");
893 q("ALTER TABLE `user` ADD INDEX ( `blockwall` ) ");
894 q("ALTER TABLE `user` ADD INDEX ( `blocked` ) ");
895 q("ALTER TABLE `user` ADD INDEX ( `verified` ) ");
899 function update_1104() {
900 q("ALTER TABLE `item` ADD `forum_mode` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `origin` , ADD INDEX ( `forum_mode` ) ");
904 function update_1105() {
905 q("ALTER TABLE `mail` ADD `convid` INT NOT NULL AFTER `contact-id` ");
906 q("ALTER TABLE `mail` ADD `guid` CHAR( 64 ) NOT NULL AFTER `uid` ");
908 q("CREATE TABLE IF NOT EXISTS `conv` (
909 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
910 `guid` CHAR( 64 ) NOT NULL ,
911 `recips` MEDIUMTEXT NOT NULL ,
913 ) ENGINE = MYISAM ");
917 function update_1106() {
918 q("ALTER TABLE `item` ADD INDEX ( `author-link` ) ");
922 function update_1107() {
923 q("ALTER TABLE `item` ADD INDEX ( `bookmark` ) ");
927 function update_1108() {
928 q("ALTER TABLE `contact` ADD `hidden` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `writable` ,
929 ADD INDEX ( `hidden` ) ");
933 function update_1109() {
934 q("ALTER TABLE `conv` ADD `creator` CHAR( 255 ) NOT NULL ,
935 ADD `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
936 ADD `updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
937 ADD `subject` MEDIUMTEXT NOT NULL,
938 ADD INDEX ( `created` ), ADD INDEX ( `updated` ) ");
941 function update_1110() {
942 q("ALTER TABLE `mail` ADD `reply` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `seen`,
943 ADD INDEX ( `reply` ), ADD INDEX ( `uid` ), ADD INDEX ( `guid` ), ADD INDEX ( `seen` ),
944 ADD INDEX ( `uri` ), ADD INDEX ( `parent-uri`), ADD INDEX ( `created` ), ADD INDEX ( `convid` ) ");
948 function update_1111() {
949 q("ALTER TABLE `gcontact` ADD `connect` CHAR( 255 ) NOT NULL ");
953 function update_1112() {
955 q("CREATE TABLE IF NOT EXISTS `notify` (
956 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
957 `type` INT( 11 ) NOT NULL ,
958 `name` CHAR( 255 ) NOT NULL ,
959 `url` CHAR( 255 ) NOT NULL ,
960 `photo` CHAR( 255 ) NOT NULL ,
961 `date` DATETIME NOT NULL ,
962 `msg` MEDIUMTEXT NOT NULL ,
964 `link` CHAR( 255 ) NOT NULL ,
965 `seen` TINYINT( 1 ) NOT NULL DEFAULT '0'
966 ) ENGINE = MYISAM ");
968 q("ALTER TABLE `notify` ADD INDEX ( `type` ), ADD INDEX ( `uid`), ADD INDEX (`seen`), ADD INDEX (`date`) ");
972 function update_1113() {
973 q("ALTER TABLE `notify` ADD `verb` CHAR( 255 ) NOT NULL ,
974 ADD `otype` CHAR( 16 ) NOT NULL");
977 function update_1114() {
978 q("CREATE TABLE IF NOT EXISTS `item_id` (
981 `face` CHAR( 255 ) NOT NULL ,
982 `dspr` CHAR( 255 ) NOT NULL ,
983 `twit` CHAR( 255 ) NOT NULL ,
984 `stat` CHAR( 255 ) NOT NULL ,
985 PRIMARY KEY ( `iid` ),
991 ) ENGINE = MYISAM ");
995 function update_1115() {
996 q("ALTER TABLE `item` ADD `moderated`
997 TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `pubmail`,
998 ADD INDEX (`moderated`) ");
1001 function update_1116() {
1002 //typo! corrected update was rolled forward
1005 function update_1117() {
1006 q("create table if not exists `manage` (
1007 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
1008 `uid` INT NOT NULL ,
1012 ) ENGINE = MYISAM ");
1016 function update_1118() {
1020 function update_1119() {
1021 q("ALTER TABLE `contact` ADD `closeness` TINYINT( 2 ) NOT NULL DEFAULT '99' AFTER `reason` , ADD INDEX (`closeness`) ");
1022 q("update contact set closeness = 0 where self = 1");
1023 q("ALTER TABLE `item` ADD `spam` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` , ADD INDEX (`spam`) ");
1027 function update_1120() {
1029 // item table update from 1119 did not get into database.sql file.
1030 // might be missing on new installs. We'll check.
1032 $r = q("describe item");
1033 if($r && count($r)) {
1035 if($rr['Field'] == 'spam')
1038 q("ALTER TABLE `item` ADD `spam` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` , ADD INDEX (`spam`) ");
1042 function update_1121() {
1043 q("CREATE TABLE IF NOT EXISTS `poll_result` (
1044 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
1045 `poll_id` INT NOT NULL ,
1046 `choice` INT NOT NULL ,
1047 INDEX ( `poll_id` ),
1049 ) ENGINE = MYISAM ");
1051 q("CREATE TABLE IF NOT EXISTS `poll` (
1052 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
1053 `uid` INT NOT NULL ,
1054 `q0` MEDIUMTEXT NOT NULL ,
1055 `q1` MEDIUMTEXT NOT NULL ,
1056 `q2` MEDIUMTEXT NOT NULL ,
1057 `q3` MEDIUMTEXT NOT NULL ,
1058 `q4` MEDIUMTEXT NOT NULL ,
1059 `q5` MEDIUMTEXT NOT NULL ,
1060 `q6` MEDIUMTEXT NOT NULL ,
1061 `q7` MEDIUMTEXT NOT NULL ,
1062 `q8` MEDIUMTEXT NOT NULL ,
1063 `q9` MEDIUMTEXT NOT NULL ,
1065 ) ENGINE = MYISAM ");
1069 function update_1122() {
1070 q("ALTER TABLE `notify` ADD `hash` CHAR( 64 ) NOT NULL AFTER `id` ,
1071 ADD INDEX ( `hash` ) ");
1074 function update_1123() {
1075 set_config('system','allowed_themes','dispy,quattro,testbubble,vier,darkbubble,darkzero,duepuntozero,greenzero,purplezero,quattro-green,slackr');
1078 function update_1124() {
1079 q("alter table item add index (`author-name`) ");
1082 function update_1125() {
1083 q("CREATE TABLE IF NOT EXISTS `notify-threads` (
1084 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
1085 `notify-id` INT NOT NULL,
1086 `master-parent-item` INT( 10 ) unsigned NOT NULL DEFAULT '0',
1087 `parent-item` INT( 10 ) unsigned NOT NULL DEFAULT '0',
1088 `receiver-uid` INT NOT NULL,
1089 INDEX ( `master-parent-item` ),
1090 INDEX ( `receiver-uid` )
1091 ) ENGINE = MyISAM DEFAULT CHARSET=utf8");
1094 function update_1126() {
1095 q("ALTER TABLE `mailacct` ADD `action` INT NOT NULL AFTER `pass`,
1096 ADD `movetofolder` CHAR(255) NOT NULL AFTER `action`");
1099 function update_1127() {
1100 q("CREATE TABLE IF NOT EXISTS `spam` (
1101 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
1103 `spam` INT NOT NULL DEFAULT '0',
1104 `ham` INT NOT NULL DEFAULT '0',
1105 `term` CHAR(255) NOT NULL,
1110 ) ENGINE = MyISAM DEFAULT CHARSET=utf8");
1114 function update_1128() {
1115 q("alter table spam add `date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `term` ");
1118 function update_1129() {
1119 q("ALTER TABLE `notify` ADD `parent` INT NOT NULL AFTER `link` , ADD INDEX ( `parent` ), ADD INDEX ( `link` ), ADD INDEX ( `otype` ) ");
1122 function update_1130() {
1123 q("ALTER TABLE `item` ADD `file` MEDIUMTEXT NOT NULL AFTER `inform`, ADD FULLTEXT KEY (`file`) ");
1126 function update_1131() {
1127 q("ALTER TABLE `contact` ADD `forum` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `writable` , ADD INDEX ( `forum` ) ");
1131 function update_1132() {
1132 q("CREATE TABLE IF NOT EXISTS `userd` (
1133 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
1134 `username` CHAR( 255 ) NOT NULL,
1135 INDEX ( `username` )
1136 ) ENGINE = MYISAM ");
1140 function update_1133() {
1141 q("ALTER TABLE `user` ADD `unkmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocktags` , ADD INDEX ( `unkmail` ) ");
1142 q("ALTER TABLE `user` ADD `cntunkmail` INT NOT NULL DEFAULT '10' AFTER `unkmail` , ADD INDEX ( `cntunkmail` ) ");
1143 q("ALTER TABLE `mail` ADD `unknown` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `replied` , ADD INDEX ( `unknown` ) ");
1146 function update_1134() {
1147 // faulty update merged forward
1148 // had a hardwired tablename of 'friendica' which isn't the right name on most systems
1151 function update_1135() {
1152 //there can't be indexes with more than 1000 bytes in mysql,
1153 //so change charset to be smaller
1154 q("ALTER TABLE `config` CHANGE `cat` `cat` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL ,
1155 CHANGE `k` `k` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL");
1157 //same thing for pconfig
1158 q("ALTER TABLE `pconfig` CHANGE `cat` `cat` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL ,
1159 CHANGE `k` `k` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL");
1160 // faulty update merged forward. Bad update in 1134 caused duplicate k,cat pairs
1161 // these have to be cleared before the unique keys can be added.
1164 function update_1136() {
1168 // order in reverse so that we save the newest entry
1170 $r = q("select * from config where 1 order by id desc");
1172 foreach($r as $rr) {
1174 foreach($arr as $x) {
1175 if($x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) {
1177 q("delete from config where id = %d",
1189 $r = q("select * from pconfig where 1 order by id desc");
1191 foreach($r as $rr) {
1193 foreach($arr as $x) {
1194 if($x['uid'] == $rr['uid'] && $x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) {
1196 q("delete from pconfig where id = %d",
1206 q("ALTER TABLE `config` ADD UNIQUE `access` ( `cat` , `k` ) ");
1207 q("ALTER TABLE `pconfig` ADD UNIQUE `access` ( `uid` , `cat` , `k` )");
1212 function update_1137() {
1213 q("alter table item_id DROP `face` , DROP `dspr` , DROP `twit` , DROP `stat` ");
1214 q("ALTER TABLE `item_id` ADD `sid` CHAR( 255 ) NOT NULL AFTER `uid` , ADD `service` CHAR( 255 ) NOT NULL AFTER `sid` , add index (`sid`), add index ( `service`) ");
1217 function update_1138() {
1218 q("alter table contact add archive tinyint(1) not null default '0' after hidden, add index (archive)");
1221 function update_1139() {
1222 $r = q("alter table user add account_removed tinyint(1) not null default '0' after expire, add index(account_removed) ");
1224 return UPDATE_FAILED ;
1225 return UPDATE_SUCCESS ;
1228 function update_1140() {
1229 $r = q("alter table addon add hidden tinyint(1) not null default '0' after installed, add index(hidden) ");
1231 return UPDATE_FAILED ;
1232 return UPDATE_SUCCESS ;
1235 function update_1141() {
1236 $r = q("alter table glink add zcid int(11) not null after gcid, add index(zcid) ");
1238 return UPDATE_FAILED ;
1239 return UPDATE_SUCCESS ;
1243 function update_1142() {
1244 $r = q("alter table user add service_class char(32) not null after expire_notification_sent, add index(service_class) ");
1246 return UPDATE_FAILED ;
1247 return UPDATE_SUCCESS ;
1250 function update_1143() {
1251 $r = q("alter table user add def_gid int(11) not null default '0' after service_class");
1253 return UPDATE_FAILED ;
1254 return UPDATE_SUCCESS ;
1257 function update_1144() {
1258 $r = q("alter table contact add prv tinyint(1) not null default '0' after forum");
1260 return UPDATE_FAILED ;
1261 return UPDATE_SUCCESS ;
1264 function update_1145() {
1265 $r = q("alter table profile add howlong datetime not null default '0000-00-00 00:00:00' after `with`");
1267 return UPDATE_FAILED ;
1268 return UPDATE_SUCCESS ;
1271 function update_1146() {
1272 $r = q("alter table profile add hometown char(255) not null after `country-name`, add index ( `hometown` ) ");
1274 return UPDATE_FAILED ;
1275 return UPDATE_SUCCESS ;
1278 function update_1147() {
1279 $r1 = q("ALTER TABLE `sign` ALTER `iid` SET DEFAULT '0'");
1280 $r2 = q("ALTER TABLE `sign` ADD `retract_iid` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `iid`");
1281 $r3 = q("ALTER TABLE `sign` ADD INDEX ( `retract_iid` )");
1282 if((! $r1) || (! $r2) || (! $r3))
1283 return UPDATE_FAILED ;
1284 return UPDATE_SUCCESS ;
1287 function update_1148() {
1288 $r = q("ALTER TABLE photo ADD type CHAR(128) NOT NULL DEFAULT 'image/jpeg' AFTER filename");
1290 return UPDATE_FAILED;
1291 return UPDATE_SUCCESS;
1295 function update_1149() {
1296 $r1 = q("ALTER TABLE profile ADD likes text NOT NULL after prv_keywords");
1297 $r2 = q("ALTER TABLE profile ADD dislikes text NOT NULL after likes");
1299 return UPDATE_FAILED;
1300 return UPDATE_SUCCESS;
1304 function update_1150() {
1305 $r = q("ALTER TABLE event ADD summary text NOT NULL after finish, add index ( uid ), add index ( cid ), add index ( uri ), add index ( `start` ), add index ( finish ), add index ( `type` ), add index ( adjust ) ");
1307 return UPDATE_FAILED;
1308 return UPDATE_SUCCESS;
1312 function update_1151() {
1313 $r = q("CREATE TABLE IF NOT EXISTS locks (
1314 id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
1315 name CHAR( 128 ) NOT NULL ,
1316 locked TINYINT( 1 ) NOT NULL DEFAULT '0'
1317 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
1319 return UPDATE_FAILED;
1320 return UPDATE_SUCCESS;
1323 function update_1152() {
1324 $r = q("CREATE TABLE IF NOT EXISTS `term` (
1325 `tid` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
1326 `oid` INT UNSIGNED NOT NULL ,
1327 `otype` TINYINT( 3 ) UNSIGNED NOT NULL ,
1328 `type` TINYINT( 3 ) UNSIGNED NOT NULL ,
1329 `term` CHAR( 255 ) NOT NULL ,
1330 `url` CHAR( 255 ) NOT NULL,
1331 KEY `oid` ( `oid` ),
1332 KEY `otype` ( `otype` ),
1333 KEY `type` ( `type` ),
1334 KEY `term` ( `term` )
1335 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
1337 return UPDATE_FAILED;
1338 return UPDATE_SUCCESS;
1341 function update_1153() {
1342 $r = q("ALTER TABLE `hook` ADD `priority` INT(11) UNSIGNED NOT NULL DEFAULT '0'");
1344 if(!$r) return UPDATE_FAILED;
1345 return UPDATE_SUCCESS;
1348 function update_1154() {
1349 $r = q("ALTER TABLE `event` ADD `ignore` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `adjust` , ADD INDEX ( `ignore` )");
1351 if(!$r) return UPDATE_FAILED;
1352 return UPDATE_SUCCESS;
1355 function update_1155() {
1356 $r1 = q("ALTER TABLE `item_id` DROP PRIMARY KEY");
1357 $r2 = q("ALTER TABLE `item_id` ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
1358 $r3 = q("ALTER TABLE `item_id` ADD INDEX ( `iid` ) ");
1360 if($r1 && $r2 && $r3)
1361 return UPDATE_SUCCESS;
1363 return UPDATE_FAILED;
1366 function update_1156() {
1367 $r = q("ALTER TABLE `photo` ADD `datasize` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `width` ,
1368 ADD INDEX ( `datasize` ) ");
1370 if(!$r) return UPDATE_FAILED;
1371 return UPDATE_SUCCESS;
1374 function update_1157() {
1375 $r = q("CREATE TABLE IF NOT EXISTS `dsprphotoq` (
1376 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
1377 `uid` int(11) NOT NULL,
1378 `msg` mediumtext NOT NULL,
1379 `attempt` tinyint(4) NOT NULL,
1381 ) ENGINE=MyISAM DEFAULT CHARSET=utf8"
1385 return UPDATE_SUCCESS;
1388 function update_1158() {
1389 set_config('system', 'maintenance', 1);
1391 // Wait for 15 seconds for current requests to
1392 // clear before locking up the database
1395 $r = q("CREATE INDEX event_id ON item(`event-id`)");
1396 set_config('system', 'maintenance', 0);
1399 return UPDATE_SUCCESS;
1401 return UPDATE_FAILED;
1404 function update_1159() {
1405 $r = q("ALTER TABLE `term` ADD `aid` int(10) unsigned NOT NULL DEFAULT '0',
1406 ADD `uid` int(10) unsigned NOT NULL DEFAULT '0',
1408 ADD INDEX (`aid`)");
1411 return UPDATE_FAILED;
1413 return UPDATE_SUCCESS;
1416 function update_1160() {
1417 set_config('system', 'maintenance', 1);
1419 // Wait for 15 seconds for current requests to
1420 // clear before locking up the database
1423 $r = q("ALTER TABLE `item` ADD `mention` TINYINT(1) NOT NULL DEFAULT '0', ADD INDEX (`mention`)");
1424 set_config('system', 'maintenance', 0);
1427 return UPDATE_FAILED;
1429 return UPDATE_SUCCESS;
1432 function update_1161() {
1433 $r = q("ALTER TABLE `pconfig` ADD INDEX (`cat`)");
1436 return UPDATE_FAILED;
1438 return UPDATE_SUCCESS;
1441 function update_1162() {
1442 require_once('include/tags.php');
1445 return UPDATE_SUCCESS;
1448 function update_1163() {
1449 set_config('system', 'maintenance', 1);
1451 $r = q("ALTER TABLE `item` ADD `network` char(32) NOT NULL");
1453 set_config('system', 'maintenance', 0);
1455 return UPDATE_FAILED;
1457 return UPDATE_SUCCESS;
1459 function update_1164() {
1460 set_config('system', 'maintenance', 1);
1462 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '' AND `contact`.`uid` = `item`.`uid`)",
1465 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
1466 NETWORK_DFRN, NETWORK_DFRN);
1468 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
1469 NETWORK_ZOT, NETWORK_ZOT);
1471 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
1472 NETWORK_OSTATUS, NETWORK_OSTATUS);
1474 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
1475 NETWORK_FEED, NETWORK_FEED);
1477 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
1478 NETWORK_DIASPORA, NETWORK_DIASPORA);
1480 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
1481 NETWORK_MAIL, NETWORK_MAIL);
1483 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
1484 NETWORK_MAIL2, NETWORK_MAIL2);
1486 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
1487 NETWORK_FACEBOOK, NETWORK_FACEBOOK);
1489 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
1490 NETWORK_LINKEDIN, NETWORK_LINKEDIN);
1492 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
1493 NETWORK_XMPP, NETWORK_XMPP);
1495 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
1496 NETWORK_MYSPACE, NETWORK_MYSPACE);
1498 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
1499 NETWORK_GPLUS, NETWORK_GPLUS);
1501 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
1502 NETWORK_PUMPIO, NETWORK_PUMPIO);
1504 $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)",
1505 NETWORK_TWITTER, NETWORK_TWITTER);
1507 set_config('system', 'maintenance', 0);
1509 return UPDATE_SUCCESS;
1512 function update_1165() {
1513 $r = q("CREATE TABLE IF NOT EXISTS `push_subscriber` (
1514 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
1516 `callback_url` CHAR( 255 ) NOT NULL,
1517 `topic` CHAR( 255 ) NOT NULL,
1518 `nickname` CHAR( 255 ) NOT NULL,
1519 `push` INT NOT NULL,
1520 `last_update` DATETIME NOT NULL,
1521 `secret` CHAR( 255 ) NOT NULL
1522 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
1524 return UPDATE_FAILED;
1526 return UPDATE_SUCCESS;
1529 function update_1166() {
1530 $r = q("CREATE TABLE IF NOT EXISTS `unique_contacts` (
1531 `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
1532 `url` CHAR(255) NOT NULL,
1533 `nick` CHAR(255) NOT NULL,
1534 `name` CHAR(255) NOT NULL,
1535 `avatar` CHAR(255) NOT NULL,
1537 ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
1539 return UPDATE_FAILED;
1541 return UPDATE_SUCCESS;
1544 function update_1167() {
1545 $r = q("ALTER TABLE `contact` ADD `notify_new_posts` TINYINT(1) NOT NULL DEFAULT '0'");
1547 return UPDATE_FAILED;
1549 return UPDATE_SUCCESS;
1552 function update_1168() {
1553 $r = q("ALTER TABLE `contact` ADD `fetch_further_information` TINYINT(1) NOT NULL DEFAULT '0'");
1555 return UPDATE_FAILED;
1557 return UPDATE_SUCCESS;
1560 function update_1169() {
1561 $r = q("CREATE TABLE IF NOT EXISTS `thread` (
1562 `iid` int(10) unsigned NOT NULL DEFAULT '0',
1563 `uid` int(10) unsigned NOT NULL DEFAULT '0',
1564 `contact-id` int(11) unsigned NOT NULL DEFAULT '0',
1565 `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
1566 `edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
1567 `commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
1568 `received` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
1569 `changed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
1570 `wall` tinyint(1) NOT NULL DEFAULT '0',
1571 `private` tinyint(1) NOT NULL DEFAULT '0',
1572 `pubmail` tinyint(1) NOT NULL DEFAULT '0',
1573 `moderated` tinyint(1) NOT NULL DEFAULT '0',
1574 `visible` tinyint(1) NOT NULL DEFAULT '0',
1575 `spam` tinyint(1) NOT NULL DEFAULT '0',
1576 `starred` tinyint(1) NOT NULL DEFAULT '0',
1577 `bookmark` tinyint(1) NOT NULL DEFAULT '0',
1578 `unseen` tinyint(1) NOT NULL DEFAULT '1',
1579 `deleted` tinyint(1) NOT NULL DEFAULT '0',
1580 `origin` tinyint(1) NOT NULL DEFAULT '0',
1581 `forum_mode` tinyint(1) NOT NULL DEFAULT '0',
1582 `mention` tinyint(1) NOT NULL DEFAULT '0',
1583 `network` char(32) NOT NULL,
1584 PRIMARY KEY (`iid`),
1585 KEY `created` (`created`),
1586 KEY `commented` (`commented`),
1587 KEY `uid_network_commented` (`uid`,`network`,`commented`),
1588 KEY `uid_network_created` (`uid`,`network`,`created`),
1589 KEY `uid_contactid_commented` (`uid`,`contact-id`,`commented`),
1590 KEY `uid_contactid_created` (`uid`,`contact-id`,`created`),
1591 KEY `wall_private_received` (`wall`,`private`,`received`),
1592 KEY `uid_created` (`uid`,`created`),
1593 KEY `uid_commented` (`uid`,`commented`)
1594 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
1596 return UPDATE_FAILED;
1598 proc_run('php',"include/threadupdate.php");
1600 return UPDATE_SUCCESS;
1608 All following update functions are ONLY for jobs that need to run AFTER the database changes are applied.
1610 Database changes are ONLY applied in the file include/dbstructure.php.
1613 function update_1177() {
1614 require_once("mod/profiles.php");
1616 $profiles = q("SELECT `uid`, `about`, `locality`, `pub_keywords`, `gender` FROM `profile` WHERE `is-default`");
1618 foreach ($profiles AS $profile) {
1619 if ($profile["about"].$profile["locality"].$profile["pub_keywords"].$profile["gender"] == "")
1622 $profile["pub_keywords"] = profile_clean_keywords($profile["pub_keywords"]);
1624 $r = q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `self` AND `uid` = %d",
1625 dbesc($profile["about"]),
1626 dbesc($profile["locality"]),
1627 dbesc($profile["pub_keywords"]),
1628 dbesc($profile["gender"]),
1629 intval($profile["uid"])
1634 function update_1178() {
1635 if (get_config('system','no_community_page'))
1636 set_config('system','community_page_style', CP_NO_COMMUNITY_PAGE);
1638 // Update the central item storage with uid=0
1639 proc_run('php',"include/threadupdate.php");
1641 return UPDATE_SUCCESS;
1644 function update_1180() {
1646 // Fill the new fields in the term table.
1647 proc_run('php',"include/tagupdate.php");
1649 return UPDATE_SUCCESS;
1652 function update_1188() {
1654 if (strlen(get_config('system','directory_submit_url')) AND
1655 !strlen(get_config('system','directory'))) {
1656 set_config('system','directory', dirname(get_config('system','directory_submit_url')));
1657 del_config('system','directory_submit_url');
1660 return UPDATE_SUCCESS;
1663 function update_1190() {
1665 require_once('include/plugin.php');
1667 set_config('system', 'maintenance', 1);
1669 if (plugin_enabled('forumlist')) {
1670 $plugin = 'forumlist';
1671 $plugins = get_config('system','addon');
1672 $plugins_arr = array();
1675 $plugins_arr = explode(",",str_replace(" ", "",$plugins));
1677 $idx = array_search($plugin, $plugins_arr);
1678 if ($idx !== false){
1679 unset($plugins_arr[$idx]);
1680 //delete forumlist manually from addon and hook table
1681 // since uninstall_plugin() don't work here
1682 q("DELETE FROM `addon` WHERE `name` = 'forumlist' ");
1683 q("DELETE FROM `hook` WHERE `file` = 'addon/forumlist/forumlist.php' ");
1684 set_config('system','addon', implode(", ",$plugins_arr));
1689 // select old formlist addon entries
1690 $r = q("SELECT `uid`, `cat`, `k`, `v` FROM `pconfig` WHERE `cat` = '%s' ",
1694 // convert old forumlist addon entries in new config entries
1696 foreach ($r as $rr) {
1698 $family = $rr['cat'];
1702 if ($key === 'randomise')
1703 del_pconfig($uid,$family,$key);
1705 if ($key === 'show_on_profile') {
1707 set_pconfig($uid,feature,forumlist_profile,$value);
1709 del_pconfig($uid,$family,$key);
1712 if ($key === 'show_on_network') {
1714 set_pconfig($uid,feature,forumlist_widget,$value);
1716 del_pconfig($uid,$family,$key);
1721 set_config('system', 'maintenance', 0);
1723 return UPDATE_SUCCESS;