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.

485 lines
15 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
  1. <?php
  2. /**
  3. *
  4. * update.php - automatic system update
  5. *
  6. * Automatically update database schemas and any other development changes such that
  7. * copying the latest files from the source code repository will always perform a clean
  8. * and painless upgrade.
  9. *
  10. * Each function in this file is named update_nnnn() where nnnn is an increasing number
  11. * which began counting at 1000.
  12. *
  13. * At the top of the file "boot.php" is a define for DB_UPDATE_VERSION. Any time there is a change
  14. * to the database schema or one which requires an upgrade path from the existing application,
  15. * the DB_UPDATE_VERSION is incremented.
  16. *
  17. * The current DB_UPDATE_VERSION is stored in the config area of the database. If the application starts up
  18. * and DB_UPDATE_VERSION is greater than the last stored build number, we will process every update function
  19. * in order from the currently stored value to the new DB_UPDATE_VERSION. This is expected to bring the system
  20. * up to current without requiring re-installation or manual intervention.
  21. *
  22. * Once the upgrade functions have completed, the current DB_UPDATE_VERSION is stored as the current value.
  23. * The DB_UPDATE_VERSION will always be one greater than the last numbered script in this file.
  24. *
  25. * If you change the database schema, the following are required:
  26. * 1. Update the file database.sql to match the new schema.
  27. * 2. Update this file by adding a new function at the end with the number of the current DB_UPDATE_VERSION.
  28. * This function should modify the current database schema and perform any other steps necessary
  29. * to ensure that upgrade is silent and free from requiring interaction.
  30. * 3. Increment the DB_UPDATE_VERSION in boot.php
  31. * 4. TEST the upgrade prior to checkin and filing a pull request.
  32. *
  33. */
  34. function update_1000() {
  35. q("ALTER TABLE `item` DROP `like`, DROP `dislike` ");
  36. q("ALTER TABLE `item` ADD `verb` CHAR( 255 ) NOT NULL AFTER `body` ,
  37. ADD `object-type` CHAR( 255 ) NOT NULL AFTER `verb` ,
  38. ADD `object` TEXT NOT NULL AFTER `object-type` ");
  39. q("ALTER TABLE `intro` ADD `duplex` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `knowyou` ");
  40. q("ALTER TABLE `contact` ADD `duplex` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `rel` ");
  41. q("ALTER TABLE `contact` CHANGE `issued-pubkey` `issued-pubkey` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
  42. q("ALTER TABLE `contact` ADD `term-date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `avatar-date`");
  43. }
  44. function update_1001() {
  45. q("ALTER TABLE `item` ADD `wall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `type` ");
  46. q("ALTER TABLE `item` ADD INDEX ( `wall` )");
  47. }
  48. function update_1002() {
  49. q("ALTER TABLE `item` ADD `gravity` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `wall` ");
  50. }
  51. function update_1003() {
  52. q("ALTER TABLE `contact` DROP `issued-pubkey` , DROP `ret-id` , DROP `ret-pubkey` ");
  53. q("ALTER TABLE `contact` ADD `usehub` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `ret-aes`");
  54. q("ALTER TABLE `contact` ADD `hub-verify` CHAR( 255 ) NOT NULL AFTER `usehub`");
  55. q("ALTER TABLE `contact` ADD INDEX ( `uid` ) , ADD INDEX ( `self` ), ADD INDEX ( `issued-id` ), ADD INDEX ( `dfrn-id` )");
  56. q("ALTER TABLE `contact` ADD INDEX ( `blocked` ), ADD INDEX ( `readonly` )");
  57. }
  58. function update_1004() {
  59. q("ALTER TABLE `contact` ADD `subhub` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `usehub`");
  60. }
  61. function update_1005() {
  62. q("ALTER TABLE `user` ADD `spubkey` TEXT NOT NULL AFTER `prvkey` ,
  63. ADD `sprvkey` TEXT NOT NULL AFTER `spubkey`");
  64. }
  65. function update_1006() {
  66. // create 's' keys for everybody that does not have one
  67. $r = q("SELECT * FROM `user` WHERE `spubkey` = '' ");
  68. if(count($r)) {
  69. foreach($r as $rr) {
  70. $sres=openssl_pkey_new(array('encrypt_key' => false ));
  71. $sprvkey = '';
  72. openssl_pkey_export($sres, $sprvkey);
  73. $spkey = openssl_pkey_get_details($sres);
  74. $spubkey = $spkey["key"];
  75. $r = q("UPDATE `user` SET `spubkey` = '%s', `sprvkey` = '%s'
  76. WHERE `uid` = %d LIMIT 1",
  77. dbesc($spubkey),
  78. dbesc($sprvkey),
  79. intval($rr['uid'])
  80. );
  81. }
  82. }
  83. }
  84. function update_1007() {
  85. q("ALTER TABLE `user` ADD `page-flags` INT NOT NULL DEFAULT '0' AFTER `notify-flags`");
  86. q("ALTER TABLE `user` ADD INDEX ( `nickname` )");
  87. }
  88. function update_1008() {
  89. q("ALTER TABLE `profile` ADD `with` TEXT NOT NULL AFTER `marital` ");
  90. }
  91. function update_1009() {
  92. q("ALTER TABLE `user` ADD `allow_location` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `default-location` ");
  93. }
  94. function update_1010() {
  95. q("ALTER TABLE `contact` ADD `lrdd` CHAR( 255 ) NOT NULL AFTER `url` ");
  96. }
  97. function update_1011() {
  98. q("ALTER TABLE `contact` ADD `nick` CHAR( 255 ) NOT NULL AFTER `name` ");
  99. $r = q("SELECT * FROM `contact` WHERE 1");
  100. if(count($r)) {
  101. foreach($r as $rr) {
  102. q("UPDATE `contact` SET `nick` = '%s' WHERE `id` = %d LIMIT 1",
  103. dbesc(basename($rr['url'])),
  104. intval($rr['id'])
  105. );
  106. }
  107. }
  108. }
  109. function update_1012() {
  110. q("ALTER TABLE `item` ADD `inform` MEDIUMTEXT NOT NULL AFTER `tag` ");
  111. }
  112. function update_1013() {
  113. q("ALTER TABLE `item` ADD `target-type` CHAR( 255 ) NOT NULL
  114. AFTER `object` , ADD `target` TEXT NOT NULL AFTER `target-type`");
  115. }
  116. function update_1014() {
  117. require_once('include/Photo.php');
  118. q("ALTER TABLE `contact` ADD `micro` TEXT NOT NULL AFTER `thumb` ");
  119. $r = q("SELECT * FROM `photo` WHERE `scale` = 4");
  120. if(count($r)) {
  121. foreach($r as $rr) {
  122. $ph = new Photo($rr['data']);
  123. if($ph->is_valid()) {
  124. $ph->scaleImage(48);
  125. $ph->store($rr['uid'],$rr['contact-id'],$rr['resource-id'],$rr['filename'],$rr['album'],6,(($rr['profile']) ? 1 : 0));
  126. }
  127. }
  128. }
  129. $r = q("SELECT * FROM `contact` WHERE 1");
  130. if(count($r)) {
  131. foreach($r as $rr) {
  132. if(stristr($rr['thumb'],'avatar'))
  133. q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d LIMIT 1",
  134. dbesc(str_replace('avatar','micro',$rr['thumb'])),
  135. intval($rr['id']));
  136. else
  137. q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d LIMIT 1",
  138. dbesc(str_replace('5.jpg','6.jpg',$rr['thumb'])),
  139. intval($rr['id']));
  140. }
  141. }
  142. }
  143. function update_1015() {
  144. q("ALTER TABLE `item` CHANGE `body` `body` mediumtext NOT NULL");
  145. }
  146. function update_1016() {
  147. q("ALTER TABLE `user` ADD `openid` CHAR( 255 ) NOT NULL AFTER `email` ");
  148. }
  149. function update_1017() {
  150. q(" CREATE TABLE IF NOT EXISTS `clients` (
  151. `client_id` VARCHAR( 20 ) NOT NULL ,
  152. `pw` VARCHAR( 20 ) NOT NULL ,
  153. `redirect_uri` VARCHAR( 200 ) NOT NULL ,
  154. PRIMARY KEY ( `client_id` )
  155. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  156. q(" CREATE TABLE IF NOT EXISTS `tokens` (
  157. `id` VARCHAR( 40 ) NOT NULL ,
  158. `client_id` VARCHAR( 20 ) NOT NULL ,
  159. `expires` INT NOT NULL ,
  160. `scope` VARCHAR( 200 ) NOT NULL ,
  161. PRIMARY KEY ( `id` )
  162. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  163. q("CREATE TABLE IF NOT EXISTS `auth_codes` (
  164. `id` VARCHAR( 40 ) NOT NULL ,
  165. `client_id` VARCHAR( 20 ) NOT NULL ,
  166. `redirect_uri` VARCHAR( 200 ) NOT NULL ,
  167. `expires` INT NOT NULL ,
  168. `scope` VARCHAR( 250 ) NOT NULL ,
  169. PRIMARY KEY ( `id` )
  170. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  171. }
  172. function update_1018() {
  173. q("CREATE TABLE IF NOT EXISTS `queue` (
  174. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  175. `cid` INT NOT NULL ,
  176. `created` DATETIME NOT NULL ,
  177. `last` DATETIME NOT NULL ,
  178. `content` MEDIUMTEXT NOT NULL
  179. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  180. }
  181. function update_1019() {
  182. q("ALTER TABLE `mail` DROP `delivered`");
  183. q("ALTER TABLE `profile` ADD `showwith` TINYINT(1) NOT NULL DEFAULT '0' AFTER `marital` ");
  184. }
  185. function update_1020() {
  186. q("ALTER TABLE `profile` DROP `showwith`");
  187. q("ALTER TABLE `item` ADD `thr-parent` CHAR( 255 ) NOT NULL AFTER `parent-uri` ");
  188. }
  189. function update_1021() {
  190. q("ALTER TABLE `profile_check` ADD `sec` CHAR( 255 ) NOT NULL AFTER `dfrn_id` ");
  191. q("ALTER TABLE `profile_check` ADD `cid` INT(10) unsigned NOT NULL DEFAULT '0' AFTER `uid`");
  192. q("ALTER TABLE `item` ADD `private` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `deny_gid` ");
  193. }
  194. function update_1022() {
  195. q("CREATE TABLE `pconfig` (
  196. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  197. `uid` INT NOT NULL DEFAULT '0',
  198. `cat` CHAR( 255 ) NOT NULL ,
  199. `k` CHAR( 255 ) NOT NULL ,
  200. `v` MEDIUMTEXT NOT NULL
  201. ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci ");
  202. }
  203. function update_1023() {
  204. q("ALTER TABLE `user` ADD `register_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `timezone` ,
  205. ADD `login_date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `register_date` ");
  206. }
  207. function update_1024() {
  208. q("ALTER TABLE `profile` ADD `keywords` TEXT NOT NULL AFTER `religion` ");
  209. }
  210. function update_1025() {
  211. q("ALTER TABLE `user` ADD `maxreq` int(11) NOT NULL DEFAULT '10' AFTER `pwdreset` ");
  212. }
  213. function update_1026() {
  214. q("CREATE TABLE IF NOT EXISTS `hook` (
  215. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  216. `hook` CHAR( 255 ) NOT NULL ,
  217. `file` CHAR( 255 ) NOT NULL ,
  218. `function` CHAR( 255 ) NOT NULL
  219. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  220. }
  221. function update_1027() {
  222. q("CREATE TABLE IF NOT EXISTS `addon` (
  223. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  224. `name` CHAR( 255 ) NOT NULL ,
  225. `version` CHAR( 255 ) NOT NULL ,
  226. `installed` TINYINT( 1 ) NOT NULL DEFAULT '0'
  227. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  228. }
  229. function update_1028() {
  230. q("ALTER TABLE `user` ADD `openidserver` text NOT NULL AFTER `deny_gid` ");
  231. }
  232. function update_1029() {
  233. q("ALTER TABLE `contact` ADD `info` MEDIUMTEXT NOT NULL AFTER `reason` ");
  234. }
  235. function update_1030() {
  236. q("ALTER TABLE `contact` ADD `bdyear` CHAR( 4 ) NOT NULL COMMENT 'birthday notify flag' AFTER `profile-id` ");
  237. q("CREATE TABLE IF NOT EXISTS `event` (
  238. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  239. `uid` INT NOT NULL ,
  240. `cid` INT NOT NULL ,
  241. `created` DATETIME NOT NULL ,
  242. `edited` DATETIME NOT NULL ,
  243. `start` DATETIME NOT NULL ,
  244. `finish` DATETIME NOT NULL ,
  245. `desc` TEXT NOT NULL ,
  246. `location` TEXT NOT NULL ,
  247. `type` CHAR( 255 ) NOT NULL ,
  248. `adjust` TINYINT( 1 ) NOT NULL DEFAULT '1',
  249. `allow_cid` MEDIUMTEXT NOT NULL ,
  250. `allow_gid` MEDIUMTEXT NOT NULL ,
  251. `deny_cid` MEDIUMTEXT NOT NULL ,
  252. `deny_gid` MEDIUMTEXT NOT NULL
  253. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  254. }
  255. function update_1031() {
  256. // Repair any bad links that slipped into the item table
  257. $r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' ");
  258. if($r && count($r)) {
  259. foreach($r as $rr) {
  260. if(strstr($rr['object'],'type=&quot;http')) {
  261. q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d LIMIT 1",
  262. dbesc(str_replace('type=&quot;http','href=&quot;http',$rr['object'])),
  263. intval($rr['id'])
  264. );
  265. }
  266. }
  267. }
  268. }
  269. function update_1032() {
  270. q("ALTER TABLE `profile` ADD `pdesc` CHAR( 255 ) NOT NULL AFTER `name` ");
  271. }
  272. function update_1033() {
  273. q("CREATE TABLE IF NOT EXISTS `cache` (
  274. `k` CHAR( 255 ) NOT NULL PRIMARY KEY ,
  275. `v` TEXT NOT NULL,
  276. `updated` DATETIME NOT NULL
  277. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  278. }
  279. function update_1034() {
  280. // If you have any of these parent-less posts they can cause problems, and
  281. // we need to delete them. You can't see them anyway.
  282. // Legitimate items will usually get re-created on the next
  283. // pull from the hub.
  284. // But don't get rid of a post that may have just come in
  285. // and may not yet have the parent id set.
  286. q("DELETE FROM `item` WHERE `parent` = 0 AND `created` < UTC_TIMESTAMP() - INTERVAL 2 MINUTE");
  287. }
  288. function update_1035() {
  289. q("ALTER TABLE `contact` ADD `success_update` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `last-update` ");
  290. }
  291. function update_1036() {
  292. $r = dbq("SELECT * FROM `contact` WHERE `network` = 'dfrn' && `photo` LIKE '%include/photo%' ");
  293. if(count($r)) {
  294. foreach($r as $rr) {
  295. q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `id` = %d LIMIT 1",
  296. dbesc(str_replace('include/photo','photo',$rr['photo'])),
  297. dbesc(str_replace('include/photo','photo',$rr['thumb'])),
  298. dbesc(str_replace('include/photo','photo',$rr['micro'])),
  299. intval($rr['id']));
  300. }
  301. }
  302. }
  303. function update_1037() {
  304. q("ALTER TABLE `contact` CHANGE `lrdd` `alias` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
  305. }
  306. function update_1038() {
  307. q("ALTER TABLE `item` ADD `plink` CHAR( 255 ) NOT NULL AFTER `target` ");
  308. }
  309. function update_1039() {
  310. q("ALTER TABLE `addon` ADD `timestamp` BIGINT NOT NULL DEFAULT '0'");
  311. }
  312. function update_1040() {
  313. q("CREATE TABLE IF NOT EXISTS `fcontact` (
  314. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  315. `url` CHAR( 255 ) NOT NULL ,
  316. `name` CHAR( 255 ) NOT NULL ,
  317. `photo` CHAR( 255 ) NOT NULL
  318. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  319. q("CREATE TABLE IF NOT EXISTS `ffinder` (
  320. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  321. `uid` INT UNSIGNED NOT NULL ,
  322. `cid` INT UNSIGNED NOT NULL ,
  323. `fid` INT UNSIGNED NOT NULL
  324. ) ENGINE = MYISAM DEFAULT CHARSET=utf8 ");
  325. }
  326. function update_1041() {
  327. q("ALTER TABLE `profile` CHANGE `keywords` `prv_keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ");
  328. q("ALTER TABLE `profile` ADD `pub_keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `religion` ");
  329. }
  330. function update_1042() {
  331. q("ALTER TABLE `user` ADD `expire` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `maxreq` ");
  332. }
  333. function update_1043() {
  334. q("ALTER TABLE `user` ADD `blockwall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocked` ");
  335. }
  336. function update_1044() {
  337. q("ALTER TABLE `profile` ADD FULLTEXT ( `pub_keywords` ) ");
  338. q("ALTER TABLE `profile` ADD FULLTEXT ( `prv_keywords` ) ");
  339. }
  340. function update_1045() {
  341. q("ALTER TABLE `user` ADD `language` CHAR( 16 ) NOT NULL DEFAULT 'en' AFTER `timezone` ");
  342. }
  343. function update_1046() {
  344. q("ALTER TABLE `item` ADD `attach` MEDIUMTEXT NOT NULL AFTER `tag` ");
  345. }
  346. function update_1047() {
  347. q("ALTER TABLE `contact` ADD `writable` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `readonly` ");
  348. }
  349. function update_1048() {
  350. q("UPDATE `contact` SET `writable` = 1 WHERE `network` = 'stat' AND `notify` != '' ");
  351. }
  352. function update_1049() {
  353. q("CREATE TABLE `mailacct` (
  354. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  355. `uid` INT NOT NULL,
  356. `server` CHAR( 255 ) NOT NULL ,
  357. `user` CHAR( 255 ) NOT NULL ,
  358. `pass` CHAR( 255 ) NOT NULL ,
  359. `reply_to` CHAR( 255 ) NOT NULL ,
  360. `last_check` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
  361. ) ENGINE = MYISAM ");
  362. }
  363. function update_1050() {
  364. q("CREATE TABLE `attach` (
  365. `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  366. `uid` INT NOT NULL ,
  367. `filetype` CHAR( 64 ) NOT NULL ,
  368. `filesize` INT NOT NULL ,
  369. `data` LONGBLOB NOT NULL ,
  370. `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  371. `edited` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
  372. `allow_cid` MEDIUMTEXT NOT NULL ,
  373. `allow_gid` MEDIUMTEXT NOT NULL ,
  374. `deny_cid` MEDIUMTEXT NOT NULL ,
  375. `deny_gid` MEDIUMTEXT NOT NULL
  376. ) ENGINE = MYISAM ");
  377. }
  378. function update_1051() {
  379. q("ALTER TABLE `mailacct` ADD `port` INT NOT NULL AFTER `server` ,
  380. ADD `ssltype` CHAR( 16 ) NOT NULL AFTER `port` ,
  381. ADD `mailbox` CHAR( 255 ) NOT NULL AFTER `ssltype` ");
  382. q("ALTER TABLE `contact` ADD `addr` CHAR( 255 ) NOT NULL AFTER `url` ");
  383. }
  384. function update_1052() {
  385. q("ALTER TABLE `mailacct` CHANGE `pass` `pass` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL");
  386. q("ALTER TABLE `mailacct` ADD `pubmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `reply_to` ");
  387. q("ALTER TABLE `item` ADD `pubmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `private` ");
  388. }
  389. function update_1053() {
  390. q("ALTER TABLE `item` ADD `extid` CHAR( 255 ) NOT NULL AFTER `parent-uri` , ADD INDEX ( `extid` ) ");
  391. }
  392. function update_1054() {
  393. q("ALTER TABLE `register` ADD `language` CHAR( 16 ) NOT NULL AFTER `password` ");
  394. }