Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

776 lines
24 KiB

  1. <?php
  2. define( 'UPDATE_VERSION' , 1093 );
  3. /**
  4. *
  5. * update.php - automatic system update
  6. *
  7. * Automatically update database schemas and any other development changes such that
  8. * copying the latest files from the source code repository will always perform a clean
  9. * and painless upgrade.
  10. *
  11. * Each function in this file is named update_nnnn() where nnnn is an increasing number
  12. * which began counting at 1000.
  13. *
  14. * At the top of the file "boot.php" is a define for DB_UPDATE_VERSION. Any time there is a change
  15. * to the database schema or one which requires an upgrade path from the existing application,
  16. * the DB_UPDATE_VERSION and the UPDATE_VERSION at the top of this file are incremented.
  17. *
  18. * The current DB_UPDATE_VERSION is stored in the config area of the database. If the application starts up
  19. * and DB_UPDATE_VERSION is greater than the last stored build number, we will process every update function
  20. * in order from the currently stored value to the new DB_UPDATE_VERSION. This is expected to bring the system
  21. * up to current without requiring re-installation or manual intervention.
  22. *
  23. * Once the upgrade functions have completed, the current DB_UPDATE_VERSION is stored as the current value.
  24. * The DB_UPDATE_VERSION will always be one greater than the last numbered script in this file.
  25. *
  26. * If you change the database schema, the following are required:
  27. * 1. Update the file database.sql to match the new schema.
  28. * 2. Update this file by adding a new function at the end with the number of the current DB_UPDATE_VERSION.
  29. * This function should modify the current database schema and perform any other steps necessary
  30. * to ensure that upgrade is silent and free from requiring interaction.
  31. * 3. Increment the DB_UPDATE_VERSION in boot.php *AND* the UPDATE_VERSION in this file to match it
  32. * 4. TEST the upgrade prior to checkin and filing a pull request.
  33. *
  34. */
  35. function update_1000() {
  36. q("ALTER TABLE `item` DROP `like`, DROP `dislike` ");
  37. q("ALTER TABLE `item` ADD `verb` CHAR( 255 ) NOT NULL AFTER `body` ,
  38. ADD `object-type` CHAR( 255 ) NOT NULL AFTER `verb` ,
  39. ADD `object` TEXT NOT NULL AFTER `object-type` ");
  40. q("ALTER TABLE `intro` ADD `duplex` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `knowyou` ");
  41. q("ALTER TABLE `contact` ADD `duplex` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `rel` ");
  42. q("ALTER TABLE `contact` CHANGE `issued-pubkey` `issued-pubkey` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
  43. q("ALTER TABLE `contact` ADD `term-date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `avatar-date`");
  44. }
  45. function update_1001() {
  46. q("ALTER TABLE `item` ADD `wall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `type` ");
  47. q("ALTER TABLE `item` ADD INDEX ( `wall` )");
  48. }
  49. function update_1002() {
  50. q("ALTER TABLE `item` ADD `gravity` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `wall` ");
  51. }
  52. function update_1003() {
  53. q("ALTER TABLE `contact` DROP `issued-pubkey` , DROP `ret-id` , DROP `ret-pubkey` ");
  54. q("ALTER TABLE `contact` ADD `usehub` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `ret-aes`");
  55. q("ALTER TABLE `contact` ADD `hub-verify` CHAR( 255 ) NOT NULL AFTER `usehub`");
  56. q("ALTER TABLE `contact` ADD INDEX ( `uid` ) , ADD INDEX ( `self` ), ADD INDEX ( `issued-id` ), ADD INDEX ( `dfrn-id` )");
  57. q("ALTER TABLE `contact` ADD INDEX ( `blocked` ), ADD INDEX ( `readonly` )");
  58. }
  59. function update_1004() {
  60. q("ALTER TABLE `contact` ADD `subhub` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `usehub`");
  61. }
  62. function update_1005() {
  63. q("ALTER TABLE `user` ADD `spubkey` TEXT NOT NULL AFTER `prvkey` ,
  64. ADD `sprvkey` TEXT NOT NULL AFTER `spubkey`");
  65. }
  66. function update_1006() {
  67. // create 's' keys for everybody that does not have one
  68. $r = q("SELECT * FROM `user` WHERE `spubkey` = '' ");
  69. if(count($r)) {
  70. foreach($r as $rr) {
  71. $sres=openssl_pkey_new(array('encrypt_key' => false ));
  72. $sprvkey = '';
  73. openssl_pkey_export($sres, $sprvkey);
  74. $spkey = openssl_pkey_get_details($sres);
  75. $spubkey = $spkey["key"];
  76. $r = q("UPDATE `user` SET `spubkey` = '%s', `sprvkey` = '%s'
  77. WHERE `uid` = %d LIMIT 1",
  78. dbesc($spubkey),
  79. dbesc($sprvkey),
  80. intval($rr['uid'])
  81. );
  82. }
  83. }
  84. }
  85. function update_1007() {
  86. q("ALTER TABLE `user` ADD `page-flags` INT NOT NULL DEFAULT '0' AFTER `notify-flags`");
  87. q("ALTER TABLE `user` ADD INDEX ( `nickname` )");
  88. }
  89. function update_1008() {
  90. q("ALTER TABLE `profile` ADD `with` TEXT NOT NULL AFTER `marital` ");
  91. }
  92. function update_1009() {
  93. q("ALTER TABLE `user` ADD `allow_location` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `default-location` ");
  94. }
  95. function update_1010() {
  96. q("ALTER TABLE `contact` ADD `lrdd` CHAR( 255 ) NOT NULL AFTER `url` ");
  97. }
  98. function update_1011() {
  99. q("ALTER TABLE `contact` ADD `nick` CHAR( 255 ) NOT NULL AFTER `name` ");
  100. $r = q("SELECT * FROM `contact` WHERE 1");
  101. if(count($r)) {
  102. foreach($r as $rr) {
  103. q("UPDATE `contact` SET `nick` = '%s' WHERE `id` = %d LIMIT 1",
  104. dbesc(basename($rr['url'])),
  105. intval($rr['id'])
  106. );
  107. }
  108. }
  109. }
  110. function update_1012() {
  111. q("ALTER TABLE `item` ADD `inform` MEDIUMTEXT NOT NULL AFTER `tag` ");
  112. }
  113. function update_1013() {
  114. q("ALTER TABLE `item` ADD `target-type` CHAR( 255 ) NOT NULL
  115. AFTER `object` , ADD `target` TEXT NOT NULL AFTER `target-type`");
  116. }
  117. function update_1014() {
  118. require_once('include/Photo.php');
  119. q("ALTER TABLE `contact` ADD `micro` TEXT NOT NULL AFTER `thumb` ");
  120. $r = q("SELECT * FROM `photo` WHERE `scale` = 4");
  121. if(count($r)) {
  122. foreach($r as $rr) {
  123. $ph = new Photo($rr['data']);
  124. if($ph->is_valid()) {
  125. $ph->scaleImage(48);
  126. $ph->store($rr['uid'],$rr['contact-id'],$rr['resource-id'],$rr['filename'],$rr['album'],6,(($rr['profile']) ? 1 : 0));
  127. }
  128. }
  129. }
  130. $r = q("SELECT * FROM `contact` WHERE 1");
  131. if(count($r)) {
  132. foreach($r as $rr) {
  133. if(stristr($rr['thumb'],'avatar'))
  134. q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d LIMIT 1",
  135. dbesc(str_replace('avatar','micro',$rr['thumb'])),
  136. intval($rr['id']));
  137. else
  138. q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d LIMIT 1",
  139. dbesc(str_replace('5.jpg','6.jpg',$rr['thumb'])),
  140. intval($rr['id']));
  141. }
  142. }
  143. }
  144. function update_1015() {
  145. q("ALTER TABLE `item` CHANGE `body` `body` mediumtext NOT NULL");
  146. }
  147. function update_1016() {
  148. q("ALTER TABLE `user` ADD `openid` CHAR( 255 ) NOT NULL AFTER `email` ");
  149. }
  150. function update_1017() {
  151. q(" CREATE TABLE IF NOT EXISTS `clients` (
  152. `client_id` VARCHAR( 20 ) NOT NULL ,
  153. `pw` VARCHAR( 20 ) NOT NULL ,
  154. `redirect_uri` VARCHAR( 200 ) NOT NULL ,
  155. PRIMARY KEY ( `client_id` )
  156. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  157. q(" CREATE TABLE IF NOT EXISTS `tokens` (
  158. `id` VARCHAR( 40 ) NOT NULL ,
  159. `client_id` VARCHAR( 20 ) NOT NULL ,
  160. `expires` INT NOT NULL ,
  161. `scope` VARCHAR( 200 ) NOT NULL ,
  162. PRIMARY KEY ( `id` )
  163. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  164. q("CREATE TABLE IF NOT EXISTS `auth_codes` (
  165. `id` VARCHAR( 40 ) NOT NULL ,
  166. `client_id` VARCHAR( 20 ) NOT NULL ,
  167. `redirect_uri` VARCHAR( 200 ) NOT NULL ,
  168. `expires` INT NOT NULL ,
  169. `scope` VARCHAR( 250 ) NOT NULL ,
  170. PRIMARY KEY ( `id` )
  171. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  172. }
  173. function update_1018() {
  174. q("CREATE TABLE IF NOT EXISTS `queue` (
  175. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  176. `cid` INT NOT NULL ,
  177. `created` DATETIME NOT NULL ,
  178. `last` DATETIME NOT NULL ,
  179. `content` MEDIUMTEXT NOT NULL
  180. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  181. }
  182. function update_1019() {
  183. q("ALTER TABLE `mail` DROP `delivered`");
  184. q("ALTER TABLE `profile` ADD `showwith` TINYINT(1) NOT NULL DEFAULT '0' AFTER `marital` ");
  185. }
  186. function update_1020() {
  187. q("ALTER TABLE `profile` DROP `showwith`");
  188. q("ALTER TABLE `item` ADD `thr-parent` CHAR( 255 ) NOT NULL AFTER `parent-uri` ");
  189. }
  190. function update_1021() {
  191. q("ALTER TABLE `profile_check` ADD `sec` CHAR( 255 ) NOT NULL AFTER `dfrn_id` ");
  192. q("ALTER TABLE `profile_check` ADD `cid` INT(10) unsigned NOT NULL DEFAULT '0' AFTER `uid`");
  193. q("ALTER TABLE `item` ADD `private` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `deny_gid` ");
  194. }
  195. function update_1022() {
  196. q("CREATE TABLE `pconfig` (
  197. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  198. `uid` INT NOT NULL DEFAULT '0',
  199. `cat` CHAR( 255 ) NOT NULL ,
  200. `k` CHAR( 255 ) NOT NULL ,
  201. `v` MEDIUMTEXT NOT NULL
  202. ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci ");
  203. }
  204. function update_1023() {
  205. q("ALTER TABLE `user` ADD `register_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `timezone` ,
  206. ADD `login_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `register_date` ");
  207. }
  208. function update_1024() {
  209. q("ALTER TABLE `profile` ADD `keywords` TEXT NOT NULL AFTER `religion` ");
  210. }
  211. function update_1025() {
  212. q("ALTER TABLE `user` ADD `maxreq` int(11) NOT NULL DEFAULT '10' AFTER `pwdreset` ");
  213. }
  214. function update_1026() {
  215. q("CREATE TABLE IF NOT EXISTS `hook` (
  216. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  217. `hook` CHAR( 255 ) NOT NULL ,
  218. `file` CHAR( 255 ) NOT NULL ,
  219. `function` CHAR( 255 ) NOT NULL
  220. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  221. }
  222. function update_1027() {
  223. q("CREATE TABLE IF NOT EXISTS `addon` (
  224. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  225. `name` CHAR( 255 ) NOT NULL ,
  226. `version` CHAR( 255 ) NOT NULL ,
  227. `installed` TINYINT( 1 ) NOT NULL DEFAULT '0'
  228. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  229. }
  230. function update_1028() {
  231. q("ALTER TABLE `user` ADD `openidserver` text NOT NULL AFTER `deny_gid` ");
  232. }
  233. function update_1029() {
  234. q("ALTER TABLE `contact` ADD `info` MEDIUMTEXT NOT NULL AFTER `reason` ");
  235. }
  236. function update_1030() {
  237. q("ALTER TABLE `contact` ADD `bdyear` CHAR( 4 ) NOT NULL COMMENT 'birthday notify flag' AFTER `profile-id` ");
  238. q("CREATE TABLE IF NOT EXISTS `event` (
  239. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  240. `uid` INT NOT NULL ,
  241. `cid` INT NOT NULL ,
  242. `created` DATETIME NOT NULL ,
  243. `edited` DATETIME NOT NULL ,
  244. `start` DATETIME NOT NULL ,
  245. `finish` DATETIME NOT NULL ,
  246. `desc` TEXT NOT NULL ,
  247. `location` TEXT NOT NULL ,
  248. `type` CHAR( 255 ) NOT NULL ,
  249. `adjust` TINYINT( 1 ) NOT NULL DEFAULT '1',
  250. `allow_cid` MEDIUMTEXT NOT NULL ,
  251. `allow_gid` MEDIUMTEXT NOT NULL ,
  252. `deny_cid` MEDIUMTEXT NOT NULL ,
  253. `deny_gid` MEDIUMTEXT NOT NULL
  254. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  255. }
  256. function update_1031() {
  257. // Repair any bad links that slipped into the item table
  258. $r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' ");
  259. if($r && count($r)) {
  260. foreach($r as $rr) {
  261. if(strstr($rr['object'],'type=&quot;http')) {
  262. q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d LIMIT 1",
  263. dbesc(str_replace('type=&quot;http','href=&quot;http',$rr['object'])),
  264. intval($rr['id'])
  265. );
  266. }
  267. }
  268. }
  269. }
  270. function update_1032() {
  271. q("ALTER TABLE `profile` ADD `pdesc` CHAR( 255 ) NOT NULL AFTER `name` ");
  272. }
  273. function update_1033() {
  274. q("CREATE TABLE IF NOT EXISTS `cache` (
  275. `k` CHAR( 255 ) NOT NULL PRIMARY KEY ,
  276. `v` TEXT NOT NULL,
  277. `updated` DATETIME NOT NULL
  278. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  279. }
  280. function update_1034() {
  281. // If you have any of these parent-less posts they can cause problems, and
  282. // we need to delete them. You can't see them anyway.
  283. // Legitimate items will usually get re-created on the next
  284. // pull from the hub.
  285. // But don't get rid of a post that may have just come in
  286. // and may not yet have the parent id set.
  287. q("DELETE FROM `item` WHERE `parent` = 0 AND `created` < UTC_TIMESTAMP() - INTERVAL 2 MINUTE");
  288. }
  289. function update_1035() {
  290. q("ALTER TABLE `contact` ADD `success_update` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `last-update` ");
  291. }
  292. function update_1036() {
  293. $r = dbq("SELECT * FROM `contact` WHERE `network` = 'dfrn' && `photo` LIKE '%include/photo%' ");
  294. if(count($r)) {
  295. foreach($r as $rr) {
  296. q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `id` = %d LIMIT 1",
  297. dbesc(str_replace('include/photo','photo',$rr['photo'])),
  298. dbesc(str_replace('include/photo','photo',$rr['thumb'])),
  299. dbesc(str_replace('include/photo','photo',$rr['micro'])),
  300. intval($rr['id']));
  301. }
  302. }
  303. }
  304. function update_1037() {
  305. q("ALTER TABLE `contact` CHANGE `lrdd` `alias` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
  306. }
  307. function update_1038() {
  308. q("ALTER TABLE `item` ADD `plink` CHAR( 255 ) NOT NULL AFTER `target` ");
  309. }
  310. function update_1039() {
  311. q("ALTER TABLE `addon` ADD `timestamp` BIGINT NOT NULL DEFAULT '0'");
  312. }
  313. function update_1040() {
  314. q("CREATE TABLE IF NOT EXISTS `fcontact` (
  315. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  316. `url` CHAR( 255 ) NOT NULL ,
  317. `name` CHAR( 255 ) NOT NULL ,
  318. `photo` CHAR( 255 ) NOT NULL
  319. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  320. q("CREATE TABLE IF NOT EXISTS `ffinder` (
  321. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  322. `uid` INT UNSIGNED NOT NULL ,
  323. `cid` INT UNSIGNED NOT NULL ,
  324. `fid` INT UNSIGNED NOT NULL
  325. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  326. }
  327. function update_1041() {
  328. q("ALTER TABLE `profile` CHANGE `keywords` `prv_keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
  329. q("ALTER TABLE `profile` ADD `pub_keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `religion` ");
  330. }
  331. function update_1042() {
  332. q("ALTER TABLE `user` ADD `expire` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `maxreq` ");
  333. }
  334. function update_1043() {
  335. q("ALTER TABLE `user` ADD `blockwall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocked` ");
  336. }
  337. function update_1044() {
  338. q("ALTER TABLE `profile` ADD FULLTEXT ( `pub_keywords` ) ");
  339. q("ALTER TABLE `profile` ADD FULLTEXT ( `prv_keywords` ) ");
  340. }
  341. function update_1045() {
  342. q("ALTER TABLE `user` ADD `language` CHAR( 16 ) NOT NULL DEFAULT 'en' AFTER `timezone` ");
  343. }
  344. function update_1046() {
  345. q("ALTER TABLE `item` ADD `attach` MEDIUMTEXT NOT NULL AFTER `tag` ");
  346. }
  347. function update_1047() {
  348. q("ALTER TABLE `contact` ADD `writable` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `readonly` ");
  349. }
  350. function update_1048() {
  351. q("UPDATE `contact` SET `writable` = 1 WHERE `network` = 'stat' AND `notify` != '' ");
  352. }
  353. function update_1049() {
  354. q("CREATE TABLE `mailacct` (
  355. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  356. `uid` INT NOT NULL,
  357. `server` CHAR( 255 ) NOT NULL ,
  358. `user` CHAR( 255 ) NOT NULL ,
  359. `pass` CHAR( 255 ) NOT NULL ,
  360. `reply_to` CHAR( 255 ) NOT NULL ,
  361. `last_check` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
  362. ) ENGINE = MYISAM ");
  363. }
  364. function update_1050() {
  365. q("CREATE TABLE `attach` (
  366. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  367. `uid` INT NOT NULL ,
  368. `filetype` CHAR( 64 ) NOT NULL ,
  369. `filesize` INT NOT NULL ,
  370. `data` LONGBLOB NOT NULL ,
  371. `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  372. `edited` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  373. `allow_cid` MEDIUMTEXT NOT NULL ,
  374. `allow_gid` MEDIUMTEXT NOT NULL ,
  375. `deny_cid` MEDIUMTEXT NOT NULL ,
  376. `deny_gid` MEDIUMTEXT NOT NULL
  377. ) ENGINE = MYISAM ");
  378. }
  379. function update_1051() {
  380. q("ALTER TABLE `mailacct` ADD `port` INT NOT NULL AFTER `server` ,
  381. ADD `ssltype` CHAR( 16 ) NOT NULL AFTER `port` ,
  382. ADD `mailbox` CHAR( 255 ) NOT NULL AFTER `ssltype` ");
  383. q("ALTER TABLE `contact` ADD `addr` CHAR( 255 ) NOT NULL AFTER `url` ");
  384. }
  385. function update_1052() {
  386. q("ALTER TABLE `mailacct` CHANGE `pass` `pass` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
  387. q("ALTER TABLE `mailacct` ADD `pubmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `reply_to` ");
  388. q("ALTER TABLE `item` ADD `pubmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `private` ");
  389. }
  390. function update_1053() {
  391. q("ALTER TABLE `item` ADD `extid` CHAR( 255 ) NOT NULL AFTER `parent-uri` , ADD INDEX ( `extid` ) ");
  392. }
  393. function update_1054() {
  394. q("ALTER TABLE `register` ADD `language` CHAR( 16 ) NOT NULL AFTER `password` ");
  395. }
  396. function update_1055() {
  397. q("ALTER TABLE `profile` ADD `hidewall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `hide-friends` ");
  398. }
  399. function update_1056() {
  400. q("ALTER TABLE `attach` ADD `hash` CHAR( 64 ) NOT NULL AFTER `uid` ");
  401. }
  402. function update_1057() {
  403. q("ALTER TABLE `attach` ADD `filename` CHAR( 255 ) NOT NULL AFTER `hash` ");
  404. }
  405. function update_1058() {
  406. q("ALTER TABLE `item` ADD `event-id` INT NOT NULL AFTER `resource-id` ");
  407. }
  408. function update_1059() {
  409. q("ALTER TABLE `queue` ADD `network` CHAR( 32 ) NOT NULL AFTER `cid` ");
  410. }
  411. function update_1060() {
  412. q("ALTER TABLE `event` ADD `uri` CHAR( 255 ) NOT NULL AFTER `cid` ");
  413. }
  414. function update_1061() {
  415. q("ALTER TABLE `event` ADD `nofinish` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `type` ");
  416. }
  417. function update_1062() {
  418. q("ALTER TABLE `user` ADD `prvnets` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `page-flags` ");
  419. }
  420. function update_1063() {
  421. q("ALTER TABLE `addon` ADD `plugin_admin` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `timestamp` ");
  422. }
  423. function update_1064() {
  424. q("ALTER TABLE `item` ADD `app` CHAR( 255 ) NOT NULL AFTER `body` ");
  425. }
  426. function update_1065() {
  427. q("ALTER TABLE `intro` ADD `fid` INT NOT NULL DEFAULT '0' AFTER `uid`");
  428. }
  429. function update_1066() {
  430. $r = q("ALTER TABLE `item` ADD `received` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `edited` ");
  431. if($r)
  432. q("ALTER TABLE `item` ADD INDEX ( `received` ) ");
  433. $r = q("UPDATE `item` SET `received` = `edited` WHERE 1");
  434. }
  435. function update_1067() {
  436. q("ALTER TABLE `ffinder` ADD `type` CHAR( 16 ) NOT NULL AFTER `id` ,
  437. ADD `note` TEXT NOT NULL AFTER `type` ");
  438. }
  439. function update_1068() {
  440. // 1067 was short-sighted. Undo it.
  441. q("ALTER TABLE `ffinder` DROP `type` , DROP `note` ");
  442. // and do this instead.
  443. q("CREATE TABLE IF NOT EXISTS `fsuggest` (
  444. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  445. `uid` INT NOT NULL ,
  446. `cid` INT NOT NULL ,
  447. `name` CHAR( 255 ) NOT NULL ,
  448. `url` CHAR( 255 ) NOT NULL ,
  449. `photo` CHAR( 255 ) NOT NULL ,
  450. `note` TEXT NOT NULL ,
  451. `created` DATETIME NOT NULL
  452. ) ENGINE = MYISAM DEFAULT CHARSET=utf8");
  453. }
  454. function update_1069() {
  455. q("ALTER TABLE `fsuggest` ADD `request` CHAR( 255 ) NOT NULL AFTER `url` ");
  456. q("ALTER TABLE `fcontact` ADD `request` CHAR( 255 ) NOT NULL AFTER `photo` ");
  457. }
  458. // mail body needs to accomodate private photos
  459. function update_1070() {
  460. q("ALTER TABLE `mail` CHANGE `body` `body` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
  461. }
  462. function update_1071() {
  463. q("ALTER TABLE `photo` ADD INDEX ( `uid` ) ");
  464. q("ALTER TABLE `photo` ADD INDEX ( `resource-id` ) ");
  465. q("ALTER TABLE `photo` ADD INDEX ( `album` ) ");
  466. q("ALTER TABLE `photo` ADD INDEX ( `scale` ) ");
  467. q("ALTER TABLE `photo` ADD INDEX ( `profile` ) ");
  468. }
  469. function update_1072() {
  470. q("ALTER TABLE `item` ADD `starred` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` ");
  471. q("ALTER TABLE `item` ADD INDEX ( `starred` ) ");
  472. }
  473. function update_1073() {
  474. q("ALTER TABLE `contact` ADD `remote_self` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `self` ");
  475. }
  476. function update_1074() {
  477. q("ALTER TABLE `user` ADD `hidewall` TINYINT( 1) NOT NULL DEFAULT '0' AFTER `blockwall` ");
  478. $r = q("SELECT `uid` FROM `profile` WHERE `is-default` = 1 AND `hidewall` = 1");
  479. if(count($r)) {
  480. foreach($r as $rr)
  481. q("UPDATE `user` SET `hidewall` = 1 WHERE `uid` = %d LIMIT 1",
  482. intval($rr['uid'])
  483. );
  484. }
  485. q("ALTER TABLE `profile` DROP `hidewall`");
  486. }
  487. function update_1075() {
  488. q("ALTER TABLE `user` ADD `guid` CHAR( 16 ) NOT NULL AFTER `uid` ");
  489. $r = q("SELECT `uid` FROM `user` WHERE 1");
  490. if(count($r)) {
  491. foreach($r as $rr) {
  492. $found = true;
  493. do {
  494. $guid = substr(random_string(),0,16);
  495. $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1",
  496. dbesc($guid)
  497. );
  498. if(! count($x))
  499. $found = false;
  500. } while ($found == true );
  501. q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d LIMIT 1",
  502. dbesc($guid),
  503. intval($rr['uid'])
  504. );
  505. }
  506. }
  507. }
  508. function update_1076() {
  509. q("CREATE TABLE `guid` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  510. `guid` CHAR( 16 ) NOT NULL , INDEX ( `guid` ) ) ENGINE = MYISAM ");
  511. }
  512. // There was a typo in 1076 so we'll try again in 1077 to make sure
  513. // We'll also make it big enough to allow for future growth, I seriously
  514. // doubt Diaspora will be able to leave guids at 16 bytes,
  515. // and we can also use the same structure for our own larger guids
  516. function update_1077() {
  517. q("CREATE TABLE IF NOT EXISTS `guid` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  518. `guid` CHAR( 16 ) NOT NULL , INDEX ( `guid` ) ) ENGINE = MYISAM ");
  519. q("ALTER TABLE `guid` CHANGE `guid` `guid` CHAR( 64 ) NOT NULL");
  520. }
  521. function update_1078() {
  522. q("ALTER TABLE `item` ADD `guid` CHAR( 64 ) NOT NULL AFTER `id` , ADD INDEX ( `guid` ) ");
  523. }
  524. function update_1079() {
  525. q("CREATE TABLE IF NOT EXISTS `sign` (
  526. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  527. `iid` INT UNSIGNED NOT NULL ,
  528. `signed_text` MEDIUMTEXT NOT NULL ,
  529. `signature` TEXT NOT NULL ,
  530. `signer` CHAR( 255 ) NOT NULL ,
  531. INDEX ( `iid` )
  532. ) ENGINE = MYISAM ");
  533. q("ALTER TABLE `fcontact` ADD `nick` CHAR( 255 ) NOT NULL ,
  534. ADD `addr` CHAR( 255 ) NOT NULL ,
  535. ADD `notify` CHAR( 255 ) NOT NULL ,
  536. ADD `poll` CHAR( 255 ) NOT NULL ,
  537. ADD `confirm` CHAR( 255 ) NOT NULL ,
  538. ADD `priority` TINYINT( 1 ) NOT NULL ,
  539. ADD `network` CHAR( 32 ) NOT NULL ,
  540. ADD `alias` CHAR( 255 ) NOT NULL ,
  541. ADD `pubkey` TEXT NOT NULL ,
  542. ADD INDEX ( `addr` ) ,
  543. ADD INDEX ( `network` ) ");
  544. }
  545. function update_1080() {
  546. q("ALTER TABLE `fcontact` ADD `updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'");
  547. }
  548. function update_1081() {
  549. // there was a typo in update 1081 so it was corrected and moved up to 1082
  550. }
  551. function update_1082() {
  552. q("ALTER TABLE `photo` ADD `guid` CHAR( 64 ) NOT NULL AFTER `contact-id`,
  553. ADD INDEX ( `guid` ) ");
  554. // make certain the following code is only executed once
  555. $r = q("select `id` from `photo` where `guid` != '' limit 1");
  556. if($r && count($r))
  557. return;
  558. $r = q("SELECT distinct(`resource-id`) FROM `photo` WHERE 1 group by `id`");
  559. if(count($r)) {
  560. foreach($r as $rr) {
  561. $guid = get_guid();
  562. q("update `photo` set `guid` = '%s' where `resource-id` = '%s'",
  563. dbesc($guid),
  564. dbesc($rr['resource-id'])
  565. );
  566. }
  567. }
  568. }
  569. function update_1083() {
  570. q("CREATE TABLE IF NOT EXISTS `deliverq` (
  571. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  572. `cmd` CHAR( 32 ) NOT NULL ,
  573. `item` INT NOT NULL ,
  574. `contact` INT NOT NULL
  575. ) ENGINE = MYISAM ");
  576. }
  577. function update_1084() {
  578. q("ALTER TABLE `contact` ADD `attag` CHAR( 255 ) NOT NULL AFTER `nick` ");
  579. }
  580. function update_1085() {
  581. q("CREATE TABLE IF NOT EXISTS `search` (
  582. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  583. `uid` INT NOT NULL ,
  584. `term` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  585. INDEX ( `uid` ),
  586. INDEX ( `term` )
  587. ) ENGINE = MYISAM ");
  588. }
  589. function update_1086() {
  590. q("ALTER TABLE `item` ADD `bookmark` tinyint(1) NOT NULL DEFAULT '0' AFTER `starred` ");
  591. }
  592. function update_1087() {
  593. q("ALTER TABLE `item` ADD `commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `edited` ");
  594. $r = q("SELECT `id` FROM `item` WHERE `parent` = `id` ");
  595. if(count($r)) {
  596. foreach($r as $rr) {
  597. $x = q("SELECT max(`created`) AS `cdate` FROM `item` WHERE `parent` = %d LIMIT 1",
  598. intval($rr['id'])
  599. );
  600. if(count($x))
  601. q("UPDATE `item` SET `commented` = '%s' WHERE `id` = %d LIMIT 1",
  602. dbesc($x[0]['cdate']),
  603. intval($rr['id'])
  604. );
  605. }
  606. }
  607. }
  608. function update_1088() {
  609. q("ALTER TABLE `user` ADD `account_expired` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `expire` ,
  610. ADD `account_expires_on` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `account_expired` ,
  611. ADD `expire_notification_sent` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `account_expires_on` ");
  612. }
  613. function update_1089() {
  614. q("ALTER TABLE `user` ADD `blocktags` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `hidewall` ");
  615. }
  616. function update_1090() {
  617. q("ALTER TABLE `contact` ADD `batch` char(255) NOT NULL AFTER `prvkey` ");
  618. q("UPDATE `contact` SET `batch` = concat(substring_index(`url`,'/',3),'/receive/public') WHERE `network` = 'dspr' ");
  619. }
  620. function update_1091() {
  621. // catch a few stragglers that may have crept in before we added this on remote connects
  622. q("UPDATE `contact` SET `batch` = concat(substring_index(`url`,'/',3),'/receive/public') WHERE `network` = 'dspr' AND `batch` = '' ");
  623. q("ALTER TABLE `queue` ADD `batch` TINYINT( 1 ) NOT NULL DEFAULT '0' ");
  624. q("ALTER TABLE `fcontact` ADD `batch` char(255) NOT NULL AFTER `addr` ");
  625. }
  626. function update_1092() {
  627. q("ALTER TABLE `user` ADD INDEX ( `login_date` ) ");
  628. q("ALTER TABLE `user` ADD INDEX ( `account_expired` ) ");
  629. }