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.
 
 
 
 
 
 

257 lines
8.0 KiB

  1. <?php
  2. use Friendica\Core\Addon;
  3. use Friendica\Core\Config;
  4. use Friendica\Core\L10n;
  5. use Friendica\Core\PConfig;
  6. use Friendica\Core\Update;
  7. use Friendica\Core\Worker;
  8. use Friendica\Database\DBA;
  9. use Friendica\Model\Contact;
  10. use Friendica\Model\Item;
  11. use Friendica\Model\User;
  12. use Friendica\Util\DateTimeFormat;
  13. /**
  14. *
  15. * update.php - automatic system update
  16. *
  17. * This function is responsible for doing post update changes to the data
  18. * (not the structure) in the database.
  19. *
  20. * Database structure changes are done in config/dbstructure.config.php
  21. *
  22. * If there is a need for a post process to a structure change, update this file
  23. * by adding a new function at the end with the number of the new DB_UPDATE_VERSION.
  24. *
  25. * The numbered script in this file has to be exactly like the DB_UPDATE_VERSION
  26. *
  27. * Example:
  28. * You are currently on version 4711 and you are preparing changes that demand an update script.
  29. *
  30. * 1. Create a function "update_4712()" here in the update.php
  31. * 2. Apply the needed structural changes in config/dbStructure.php
  32. * 3. Set DB_UPDATE_VERSION in config/dbstructure.config.php to 4712.
  33. *
  34. * If you need to run a script before the database update, name the function "pre_update_4712()"
  35. */
  36. function update_1178() {
  37. require_once 'mod/profiles.php';
  38. $profiles = q("SELECT `uid`, `about`, `locality`, `pub_keywords`, `gender` FROM `profile` WHERE `is-default`");
  39. foreach ($profiles AS $profile) {
  40. if ($profile["about"].$profile["locality"].$profile["pub_keywords"].$profile["gender"] == "")
  41. continue;
  42. $profile["pub_keywords"] = profile_clean_keywords($profile["pub_keywords"]);
  43. $r = q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `self` AND `uid` = %d",
  44. DBA::escape($profile["about"]),
  45. DBA::escape($profile["locality"]),
  46. DBA::escape($profile["pub_keywords"]),
  47. DBA::escape($profile["gender"]),
  48. intval($profile["uid"])
  49. );
  50. }
  51. }
  52. function update_1179() {
  53. if (Config::get('system','no_community_page'))
  54. Config::set('system','community_page_style', CP_NO_COMMUNITY_PAGE);
  55. // Update the central item storage with uid=0
  56. Worker::add(PRIORITY_LOW, "threadupdate");
  57. return Update::SUCCESS;
  58. }
  59. function update_1181() {
  60. // Fill the new fields in the term table.
  61. Worker::add(PRIORITY_LOW, "TagUpdate");
  62. return Update::SUCCESS;
  63. }
  64. function update_1189() {
  65. if (strlen(Config::get('system','directory_submit_url')) &&
  66. !strlen(Config::get('system','directory'))) {
  67. Config::set('system','directory', dirname(Config::get('system','directory_submit_url')));
  68. Config::delete('system','directory_submit_url');
  69. }
  70. return Update::SUCCESS;
  71. }
  72. function update_1191() {
  73. Config::set('system', 'maintenance', 1);
  74. if (Addon::isEnabled('forumlist')) {
  75. $addon = 'forumlist';
  76. $addons = Config::get('system', 'addon');
  77. $addons_arr = [];
  78. if ($addons) {
  79. $addons_arr = explode(",",str_replace(" ", "", $addons));
  80. $idx = array_search($addon, $addons_arr);
  81. if ($idx !== false){
  82. unset($addons_arr[$idx]);
  83. //delete forumlist manually from addon and hook table
  84. // since Addon::uninstall() don't work here
  85. q("DELETE FROM `addon` WHERE `name` = 'forumlist' ");
  86. q("DELETE FROM `hook` WHERE `file` = 'addon/forumlist/forumlist.php' ");
  87. Config::set('system','addon', implode(", ", $addons_arr));
  88. }
  89. }
  90. }
  91. // select old formlist addon entries
  92. $r = q("SELECT `uid`, `cat`, `k`, `v` FROM `pconfig` WHERE `cat` = '%s' ",
  93. DBA::escape('forumlist')
  94. );
  95. // convert old forumlist addon entries in new config entries
  96. if (DBA::isResult($r)) {
  97. foreach ($r as $rr) {
  98. $uid = $rr['uid'];
  99. $family = $rr['cat'];
  100. $key = $rr['k'];
  101. $value = $rr['v'];
  102. if ($key === 'randomise')
  103. PConfig::delete($uid,$family,$key);
  104. if ($key === 'show_on_profile') {
  105. if ($value)
  106. PConfig::set($uid,feature,forumlist_profile,$value);
  107. PConfig::delete($uid,$family,$key);
  108. }
  109. if ($key === 'show_on_network') {
  110. if ($value)
  111. PConfig::set($uid,feature,forumlist_widget,$value);
  112. PConfig::delete($uid,$family,$key);
  113. }
  114. }
  115. }
  116. Config::set('system', 'maintenance', 0);
  117. return Update::SUCCESS;
  118. }
  119. function update_1203() {
  120. $r = q("UPDATE `user` SET `account-type` = %d WHERE `page-flags` IN (%d, %d)",
  121. DBA::escape(Contact::ACCOUNT_TYPE_COMMUNITY), DBA::escape(Contact::PAGE_COMMUNITY), DBA::escape(Contact::PAGE_PRVGROUP));
  122. }
  123. function update_1244() {
  124. // Sets legacy_password for all legacy hashes
  125. DBA::update('user', ['legacy_password' => true], ['SUBSTR(password, 1, 4) != "$2y$"']);
  126. // All legacy hashes are re-hashed using the new secure hashing function
  127. $stmt = DBA::select('user', ['uid', 'password'], ['legacy_password' => true]);
  128. while($user = DBA::fetch($stmt)) {
  129. DBA::update('user', ['password' => User::hashPassword($user['password'])], ['uid' => $user['uid']]);
  130. }
  131. // Logged in users are forcibly logged out
  132. DBA::delete('session', ['1 = 1']);
  133. return Update::SUCCESS;
  134. }
  135. function update_1245() {
  136. $rino = Config::get('system', 'rino_encrypt');
  137. if (!$rino) {
  138. return Update::SUCCESS;
  139. }
  140. Config::set('system', 'rino_encrypt', 1);
  141. return Update::SUCCESS;
  142. }
  143. function update_1247() {
  144. // Removing hooks with the old name
  145. DBA::e("DELETE FROM `hook`
  146. WHERE `hook` LIKE 'plugin_%'");
  147. // Make sure we install the new renamed ones
  148. Addon::reload();
  149. }
  150. function update_1260() {
  151. Config::set('system', 'maintenance', 1);
  152. Config::set('system', 'maintenance_reason', L10n::t('%s: Updating author-id and owner-id in item and thread table. ', DateTimeFormat::utcNow().' '.date('e')));
  153. $items = DBA::p("SELECT `id`, `owner-link`, `owner-name`, `owner-avatar`, `network` FROM `item`
  154. WHERE `owner-id` = 0 AND `owner-link` != ''");
  155. while ($item = DBA::fetch($items)) {
  156. $contact = ['url' => $item['owner-link'], 'name' => $item['owner-name'],
  157. 'photo' => $item['owner-avatar'], 'network' => $item['network']];
  158. $cid = Contact::getIdForURL($item['owner-link'], 0, false, $contact);
  159. if (empty($cid)) {
  160. continue;
  161. }
  162. Item::update(['owner-id' => $cid], ['id' => $item['id']]);
  163. }
  164. DBA::close($items);
  165. DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id`
  166. SET `thread`.`owner-id` = `item`.`owner-id` WHERE `thread`.`owner-id` = 0");
  167. $items = DBA::p("SELECT `id`, `author-link`, `author-name`, `author-avatar`, `network` FROM `item`
  168. WHERE `author-id` = 0 AND `author-link` != ''");
  169. while ($item = DBA::fetch($items)) {
  170. $contact = ['url' => $item['author-link'], 'name' => $item['author-name'],
  171. 'photo' => $item['author-avatar'], 'network' => $item['network']];
  172. $cid = Contact::getIdForURL($item['author-link'], 0, false, $contact);
  173. if (empty($cid)) {
  174. continue;
  175. }
  176. Item::update(['author-id' => $cid], ['id' => $item['id']]);
  177. }
  178. DBA::close($items);
  179. DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id`
  180. SET `thread`.`author-id` = `item`.`author-id` WHERE `thread`.`author-id` = 0");
  181. Config::set('system', 'maintenance', 0);
  182. return Update::SUCCESS;
  183. }
  184. function update_1261() {
  185. // This fixes the results of an issue in the develop branch of 2018-05.
  186. DBA::update('contact', ['blocked' => false, 'pending' => false], ['uid' => 0, 'blocked' => true, 'pending' => true]);
  187. return Update::SUCCESS;
  188. }
  189. function update_1278() {
  190. Config::set('system', 'maintenance', 1);
  191. Config::set('system', 'maintenance_reason', L10n::t('%s: Updating post-type.', DateTimeFormat::utcNow().' '.date('e')));
  192. Item::update(['post-type' => Item::PT_PAGE], ['bookmark' => true]);
  193. Item::update(['post-type' => Item::PT_PERSONAL_NOTE], ['type' => 'note']);
  194. Config::set('system', 'maintenance', 0);
  195. return Update::SUCCESS;
  196. }
  197. function update_1288() {
  198. // Updates missing `uri-id` values
  199. DBA::e("UPDATE `item-activity` INNER JOIN `item` ON `item`.`iaid` = `item-activity`.`id` SET `item-activity`.`uri-id` = `item`.`uri-id` WHERE `item-activity`.`uri-id` IS NULL OR `item-activity`.`uri-id` = 0");
  200. DBA::e("UPDATE `item-content` INNER JOIN `item` ON `item`.`icid` = `item-content`.`id` SET `item-content`.`uri-id` = `item`.`uri-id` WHERE `item-content`.`uri-id` IS NULL OR `item-content`.`uri-id` = 0");
  201. return Update::SUCCESS;
  202. }