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.

239 lines
7.9 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 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 BUILD_ID. Any time there is a change
  14. * to the database schema or one which requires an upgrade path from the existing application,
  15. * the BUILD_ID is incremented.
  16. *
  17. * The current BUILD_ID is stored in the config area of the database. If the application starts up
  18. * and BUILD_ID 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 BUILD_ID. 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 BUILD_ID is stored as the current value.
  23. * The BUILD_ID 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 BUILD_ID.
  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 BUILD_ID 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. }