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.

1309 lines
38 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
  1. <?php
  2. define( 'UPDATE_VERSION' , 1151 );
  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. }
  630. function update_1093() {
  631. q("CREATE TABLE IF NOT EXISTS `fserver` (
  632. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  633. `server` CHAR( 255 ) NOT NULL ,
  634. `posturl` CHAR( 255 ) NOT NULL ,
  635. `key` TEXT NOT NULL,
  636. INDEX ( `server` )
  637. ) ENGINE = MYISAM ");
  638. q("ALTER TABLE `group` ADD `visible` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `uid` ");
  639. }
  640. function update_1094() {
  641. q("ALTER TABLE `item` ADD `postopts` TEXT NOT NULL AFTER `target` ");
  642. }
  643. function update_1095() {
  644. q("ALTER TABLE `contact` ADD `bd` DATE NOT NULL AFTER `bdyear` ");
  645. }
  646. function update_1096() {
  647. q("ALTER TABLE `item` ADD `origin` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `deleted` , ADD INDEX ( `origin` ) ");
  648. }
  649. function update_1097() {
  650. q("ALTER TABLE `queue`
  651. ADD INDEX (`cid`),
  652. ADD INDEX (`created`),
  653. ADD INDEX (`last`),
  654. ADD INDEX (`network`),
  655. ADD INDEX (`batch`)
  656. ");
  657. }
  658. function update_1098() {
  659. q("ALTER TABLE `contact`
  660. ADD INDEX (`network`),
  661. ADD INDEX (`name`),
  662. ADD INDEX (`nick`),
  663. ADD INDEX (`attag`),
  664. ADD INDEX (`url`),
  665. ADD INDEX (`addr`),
  666. ADD INDEX (`batch`)
  667. ");
  668. }
  669. function update_1099() {
  670. q("CREATE TABLE IF NOT EXISTS `gcontact` (
  671. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  672. `name` CHAR( 255 ) NOT NULL ,
  673. `url` CHAR( 255 ) NOT NULL ,
  674. `nurl` CHAR( 255 ) NOT NULL ,
  675. `photo` CHAR( 255 ) NOT NULL
  676. ) ENGINE = MYISAM ");
  677. q("CREATE TABLE IF NOT EXISTS `glink` (
  678. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  679. `cid` INT NOT NULL ,
  680. `uid` INT NOT NULL ,
  681. `gcid` INT NOT NULL,
  682. `updated` DATETIME NOT NULL
  683. ) ENGINE = MYISAM ");
  684. q("ALTER TABLE `gcontact` ADD INDEX (`nurl`) ");
  685. q("ALTER TABLE `glink` ADD INDEX (`cid`), ADD INDEX (`uid`), ADD INDEX (`gcid`), ADD INDEX (`updated`) ");
  686. q("ALTER TABLE `contact` ADD `poco` TEXT NOT NULL AFTER `confirm` ");
  687. }
  688. function update_1100() {
  689. q("ALTER TABLE `contact` ADD `nurl` CHAR( 255 ) NOT NULL AFTER `url` ");
  690. q("alter table contact add index (`nurl`) ");
  691. require_once('include/text.php');
  692. $r = q("select id, url from contact where url != '' and nurl = '' ");
  693. if(count($r)) {
  694. foreach($r as $rr) {
  695. q("update contact set nurl = '%s' where id = %d limit 1",
  696. dbesc(normalise_link($rr['url'])),
  697. intval($rr['id'])
  698. );
  699. }
  700. }
  701. }
  702. function update_1101() {
  703. q("CREATE TABLE IF NOT EXISTS `gcign` (
  704. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  705. `uid` INT NOT NULL ,
  706. `gcid` INT NOT NULL
  707. ) ENGINE = MYISAM ");
  708. q("ALTER TABLE `gcign` ADD INDEX (`uid`), ADD INDEX (`gcid`) ");
  709. }
  710. function update_1102() {
  711. q("ALTER TABLE `clients` ADD `name` TEXT NULL DEFAULT NULL AFTER `redirect_uri` ");
  712. q("ALTER TABLE `clients` ADD `icon` TEXT NULL DEFAULT NULL AFTER `name` ");
  713. q("ALTER TABLE `clients` ADD `uid` INT NOT NULL DEFAULT 0 AFTER `icon` ");
  714. q("ALTER TABLE `tokens` ADD `secret` TEXT NOT NULL AFTER `id` ");
  715. q("ALTER TABLE `tokens` ADD `uid` INT NOT NULL AFTER `scope` ");
  716. }
  717. function update_1103() {
  718. // q("ALTER TABLE `item` ADD INDEX ( `wall` ) ");
  719. q("ALTER TABLE `item` ADD FULLTEXT ( `tag` ) ");
  720. q("ALTER TABLE `contact` ADD INDEX ( `pending` ) ");
  721. q("ALTER TABLE `user` ADD INDEX ( `hidewall` ) ");
  722. q("ALTER TABLE `user` ADD INDEX ( `blockwall` ) ");
  723. q("ALTER TABLE `user` ADD INDEX ( `blocked` ) ");
  724. q("ALTER TABLE `user` ADD INDEX ( `verified` ) ");
  725. }
  726. function update_1104() {
  727. q("ALTER TABLE `item` ADD `forum_mode` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `origin` , ADD INDEX ( `forum_mode` ) ");
  728. }
  729. function update_1105() {
  730. q("ALTER TABLE `mail` ADD `convid` INT NOT NULL AFTER `contact-id` ");
  731. q("ALTER TABLE `mail` ADD `guid` CHAR( 64 ) NOT NULL AFTER `uid` ");
  732. q("CREATE TABLE IF NOT EXISTS `conv` (
  733. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  734. `guid` CHAR( 64 ) NOT NULL ,
  735. `recips` MEDIUMTEXT NOT NULL ,
  736. `uid` INT NOT NULL
  737. ) ENGINE = MYISAM ");
  738. }
  739. function update_1106() {
  740. q("ALTER TABLE `item` ADD INDEX ( `author-link` ) ");
  741. }
  742. function update_1107() {
  743. q("ALTER TABLE `item` ADD INDEX ( `bookmark` ) ");
  744. }
  745. function update_1108() {
  746. q("ALTER TABLE `contact` ADD `hidden` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `writable` ,
  747. ADD INDEX ( `hidden` ) ");
  748. }
  749. function update_1109() {
  750. q("ALTER TABLE `conv` ADD `creator` CHAR( 255 ) NOT NULL ,
  751. ADD `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  752. ADD `updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  753. ADD `subject` MEDIUMTEXT NOT NULL,
  754. ADD INDEX ( `created` ), ADD INDEX ( `updated` ) ");
  755. }
  756. function update_1110() {
  757. q("ALTER TABLE `mail` ADD `reply` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `seen`,
  758. ADD INDEX ( `reply` ), ADD INDEX ( `uid` ), ADD INDEX ( `guid` ), ADD INDEX ( `seen` ),
  759. ADD INDEX ( `uri` ), ADD INDEX ( `parent-uri`), ADD INDEX ( `created` ), ADD INDEX ( `convid` ) ");
  760. }
  761. function update_1111() {
  762. q("ALTER TABLE `gcontact` ADD `connect` CHAR( 255 ) NOT NULL ");
  763. }
  764. function update_1112() {
  765. q("CREATE TABLE IF NOT EXISTS `notify` (
  766. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  767. `type` INT( 11 ) NOT NULL ,
  768. `name` CHAR( 255 ) NOT NULL ,
  769. `url` CHAR( 255 ) NOT NULL ,
  770. `photo` CHAR( 255 ) NOT NULL ,
  771. `date` DATETIME NOT NULL ,
  772. `msg` MEDIUMTEXT NOT NULL ,
  773. `uid` INT NOT NULL ,
  774. `link` CHAR( 255 ) NOT NULL ,
  775. `seen` TINYINT( 1 ) NOT NULL DEFAULT '0'
  776. ) ENGINE = MYISAM ");
  777. q("ALTER TABLE `notify` ADD INDEX ( `type` ), ADD INDEX ( `uid`), ADD INDEX (`seen`), ADD INDEX (`date`) ");
  778. }
  779. function update_1113() {
  780. q("ALTER TABLE `notify` ADD `verb` CHAR( 255 ) NOT NULL ,
  781. ADD `otype` CHAR( 16 ) NOT NULL");
  782. }
  783. function update_1114() {
  784. q("CREATE TABLE IF NOT EXISTS `item_id` (
  785. `iid` INT NOT NULL ,
  786. `uid` INT NOT NULL ,
  787. `face` CHAR( 255 ) NOT NULL ,
  788. `dspr` CHAR( 255 ) NOT NULL ,
  789. `twit` CHAR( 255 ) NOT NULL ,
  790. `stat` CHAR( 255 ) NOT NULL ,
  791. PRIMARY KEY ( `iid` ),
  792. INDEX ( `uid` ),
  793. INDEX ( `face` ),
  794. INDEX ( `dspr` ),
  795. INDEX ( `twit` ),
  796. INDEX ( `stat` )
  797. ) ENGINE = MYISAM ");
  798. }
  799. function update_1115() {
  800. q("ALTER TABLE `item` ADD `moderated`
  801. TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `pubmail`,
  802. ADD INDEX (`moderated`) ");
  803. }
  804. function update_1116() {
  805. //typo! corrected update was rolled forward
  806. }
  807. function update_1117() {
  808. q("create table if not exists `manage` (
  809. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  810. `uid` INT NOT NULL ,
  811. `mid` INT NOT NULL,
  812. INDEX ( `uid` ),
  813. INDEX ( `mid` )
  814. ) ENGINE = MYISAM ");
  815. }
  816. function update_1118() {
  817. // rolled forward
  818. }
  819. function update_1119() {
  820. q("ALTER TABLE `contact` ADD `closeness` TINYINT( 2 ) NOT NULL DEFAULT '99' AFTER `reason` , ADD INDEX (`closeness`) ");
  821. q("update contact set closeness = 0 where self = 1");
  822. q("ALTER TABLE `item` ADD `spam` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` , ADD INDEX (`spam`) ");
  823. }
  824. function update_1120() {
  825. // item table update from 1119 did not get into database.sql file.
  826. // might be missing on new installs. We'll check.
  827. $r = q("describe item");
  828. if($r && count($r)) {
  829. foreach($r as $rr)
  830. if($rr['Field'] == 'spam')
  831. return;
  832. }
  833. q("ALTER TABLE `item` ADD `spam` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` , ADD INDEX (`spam`) ");
  834. }
  835. function update_1121() {
  836. q("CREATE TABLE IF NOT EXISTS `poll_result` (
  837. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  838. `poll_id` INT NOT NULL ,
  839. `choice` INT NOT NULL ,
  840. INDEX ( `poll_id` ),
  841. INDEX ( `choice` )
  842. ) ENGINE = MYISAM ");
  843. q("CREATE TABLE IF NOT EXISTS `poll` (
  844. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  845. `uid` INT NOT NULL ,
  846. `q0` MEDIUMTEXT NOT NULL ,
  847. `q1` MEDIUMTEXT NOT NULL ,
  848. `q2` MEDIUMTEXT NOT NULL ,
  849. `q3` MEDIUMTEXT NOT NULL ,
  850. `q4` MEDIUMTEXT NOT NULL ,
  851. `q5` MEDIUMTEXT NOT NULL ,
  852. `q6` MEDIUMTEXT NOT NULL ,
  853. `q7` MEDIUMTEXT NOT NULL ,
  854. `q8` MEDIUMTEXT NOT NULL ,
  855. `q9` MEDIUMTEXT NOT NULL ,
  856. INDEX ( `uid` )
  857. ) ENGINE = MYISAM ");
  858. }
  859. function update_1122() {
  860. q("ALTER TABLE `notify` ADD `hash` CHAR( 64 ) NOT NULL AFTER `id` ,
  861. ADD INDEX ( `hash` ) ");
  862. }
  863. function update_1123() {
  864. set_config('system','allowed_themes','dispy,quattro,testbubble,vier,darkbubble,darkzero,duepuntozero,greenzero,purplezero,quattro-green,slackr');
  865. }
  866. function update_1124() {
  867. q("alter table item add index (`author-name`) ");
  868. }
  869. function update_1125() {
  870. q("CREATE TABLE IF NOT EXISTS `notify-threads` (
  871. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  872. `notify-id` INT NOT NULL,
  873. `master-parent-item` INT( 10 ) unsigned NOT NULL DEFAULT '0',
  874. `parent-item` INT( 10 ) unsigned NOT NULL DEFAULT '0',
  875. `receiver-uid` INT NOT NULL,
  876. INDEX ( `master-parent-item` ),
  877. INDEX ( `receiver-uid` )
  878. ) ENGINE = MyISAM DEFAULT CHARSET=utf8");
  879. }
  880. function update_1126() {
  881. q("ALTER TABLE `mailacct` ADD `action` INT NOT NULL AFTER `pass`,
  882. ADD `movetofolder` CHAR(255) NOT NULL AFTER `action`");
  883. }
  884. function update_1127() {
  885. q("CREATE TABLE IF NOT EXISTS `spam` (
  886. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  887. `uid` INT NOT NULL,
  888. `spam` INT NOT NULL DEFAULT '0',
  889. `ham` INT NOT NULL DEFAULT '0',
  890. `term` CHAR(255) NOT NULL,
  891. INDEX ( `uid` ),
  892. INDEX ( `spam` ),
  893. INDEX ( `ham` ),
  894. INDEX ( `term` )
  895. ) ENGINE = MyISAM DEFAULT CHARSET=utf8");
  896. }
  897. function update_1128() {
  898. q("alter table spam add `date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `term` ");
  899. }
  900. function update_1129() {
  901. q("ALTER TABLE `notify` ADD `parent` INT NOT NULL AFTER `link` , ADD INDEX ( `parent` ), ADD INDEX ( `link` ), ADD INDEX ( `otype` ) ");
  902. }
  903. function update_1130() {
  904. q("ALTER TABLE `item` ADD `file` MEDIUMTEXT NOT NULL AFTER `inform`, ADD FULLTEXT KEY (`file`) ");
  905. }
  906. function update_1131() {
  907. q("ALTER TABLE `contact` ADD `forum` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `writable` , ADD INDEX ( `forum` ) ");
  908. }
  909. function update_1132() {
  910. q("CREATE TABLE IF NOT EXISTS `userd` (
  911. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  912. `username` CHAR( 255 ) NOT NULL,
  913. INDEX ( `username` )
  914. ) ENGINE = MYISAM ");
  915. }
  916. function update_1133() {
  917. q("ALTER TABLE `user` ADD `unkmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocktags` , ADD INDEX ( `unkmail` ) ");
  918. q("ALTER TABLE `user` ADD `cntunkmail` INT NOT NULL DEFAULT '10' AFTER `unkmail` , ADD INDEX ( `cntunkmail` ) ");
  919. q("ALTER TABLE `mail` ADD `unknown` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `replied` , ADD INDEX ( `unknown` ) ");
  920. }
  921. function update_1134() {
  922. // faulty update merged forward
  923. // had a hardwired tablename of 'friendica' which isn't the right name on most systems
  924. }
  925. function update_1135() {
  926. //there can't be indexes with more than 1000 bytes in mysql,
  927. //so change charset to be smaller
  928. q("ALTER TABLE `config` CHANGE `cat` `cat` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL ,
  929. CHANGE `k` `k` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL");
  930. //same thing for pconfig
  931. q("ALTER TABLE `pconfig` CHANGE `cat` `cat` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL ,
  932. CHANGE `k` `k` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL");
  933. // faulty update merged forward. Bad update in 1134 caused duplicate k,cat pairs
  934. // these have to be cleared before the unique keys can be added.
  935. }
  936. function update_1136() {
  937. $arr = array();
  938. // order in reverse so that we save the newest entry
  939. $r = q("select * from config where 1 order by id desc");
  940. if(count($r)) {
  941. foreach($r as $rr) {
  942. $found = false;
  943. foreach($arr as $x) {
  944. if($x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) {
  945. $found = true;
  946. q("delete from config where id = %d limit 1",
  947. intval($rr['id'])
  948. );
  949. }
  950. }
  951. if(! $found) {
  952. $arr[] = $rr;
  953. }
  954. }
  955. }
  956. $arr = array();
  957. $r = q("select * from pconfig where 1 order by id desc");
  958. if(count($r)) {
  959. foreach($r as $rr) {
  960. $found = false;
  961. foreach($arr as $x) {
  962. if($x['uid'] == $rr['uid'] && $x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) {
  963. $found = true;
  964. q("delete from pconfig where id = %d limit 1",
  965. intval($rr['id'])
  966. );
  967. }
  968. }
  969. if(! $found) {
  970. $arr[] = $rr;
  971. }
  972. }
  973. }
  974. q("ALTER TABLE `config` ADD UNIQUE `access` ( `cat` , `k` ) ");
  975. q("ALTER TABLE `pconfig` ADD UNIQUE `access` ( `uid` , `cat` , `k` )");
  976. }
  977. function update_1137() {
  978. q("alter table item_id DROP `face` , DROP `dspr` , DROP `twit` , DROP `stat` ");
  979. 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`) ");
  980. }
  981. function update_1138() {
  982. q("alter table contact add archive tinyint(1) not null default '0' after hidden, add index (archive)");
  983. }
  984. function update_1139() {
  985. $r = q("alter table user add account_removed tinyint(1) not null default '0' after expire, add index(account_removed) ");
  986. if(! $r)
  987. return UPDATE_FAILED ;
  988. return UPDATE_SUCCESS ;
  989. }
  990. function update_1140() {
  991. $r = q("alter table addon add hidden tinyint(1) not null default '0' after installed, add index(hidden) ");
  992. if(! $r)
  993. return UPDATE_FAILED ;
  994. return UPDATE_SUCCESS ;
  995. }
  996. function update_1141() {
  997. $r = q("alter table glink add zcid int(11) not null after gcid, add index(zcid) ");
  998. if(! $r)
  999. return UPDATE_FAILED ;
  1000. return UPDATE_SUCCESS ;
  1001. }
  1002. function update_1142() {
  1003. $r = q("alter table user add service_class char(32) not null after expire_notification_sent, add index(service_class) ");
  1004. if(! $r)
  1005. return UPDATE_FAILED ;
  1006. return UPDATE_SUCCESS ;
  1007. }
  1008. function update_1143() {
  1009. $r = q("alter table user add def_gid int(11) not null default '0' after service_class");
  1010. if(! $r)
  1011. return UPDATE_FAILED ;
  1012. return UPDATE_SUCCESS ;
  1013. }
  1014. function update_1144() {
  1015. $r = q("alter table contact add prv tinyint(1) not null default '0' after forum");
  1016. if(! $r)
  1017. return UPDATE_FAILED ;
  1018. return UPDATE_SUCCESS ;
  1019. }
  1020. function update_1145() {
  1021. $r = q("alter table profile add howlong datetime not null default '0000-00-00 00:00:00' after `with`");
  1022. if(! $r)
  1023. return UPDATE_FAILED ;
  1024. return UPDATE_SUCCESS ;
  1025. }
  1026. function update_1146() {
  1027. $r = q("alter table profile add hometown char(255) not null after `country-name`, add index ( `hometown` ) ");
  1028. if(! $r)
  1029. return UPDATE_FAILED ;
  1030. return UPDATE_SUCCESS ;
  1031. }
  1032. function update_1147() {
  1033. $r1 = q("ALTER TABLE `sign` ALTER `iid` SET DEFAULT '0'");
  1034. $r2 = q("ALTER TABLE `sign` ADD `retract_iid` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `iid`");
  1035. $r3 = q("ALTER TABLE `sign` ADD INDEX ( `retract_iid` )");
  1036. if((! $r1) || (! $r2) || (! $r3))
  1037. return UPDATE_FAILED ;
  1038. return UPDATE_SUCCESS ;
  1039. }
  1040. function update_1148() {
  1041. $r = q("ALTER TABLE photo ADD type CHAR(128) NOT NULL DEFAULT 'image/jpeg' AFTER filename");
  1042. if (!$r)
  1043. return UPDATE_FAILED;
  1044. return UPDATE_SUCCESS;
  1045. }
  1046. function update_1149() {
  1047. $r1 = q("ALTER TABLE profile ADD likes text NOT NULL after prv_keywords");
  1048. $r2 = q("ALTER TABLE profile ADD dislikes text NOT NULL after likes");
  1049. if (! ($r1 && $r2))
  1050. return UPDATE_FAILED;
  1051. return UPDATE_SUCCESS;
  1052. }
  1053. function update_1150() {
  1054. $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 ) ");
  1055. if(! $r)
  1056. return UPDATE_FAILED;
  1057. return UPDATE_SUCCESS;
  1058. }