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.
 
 
 
 
 
 

187 lines
4.9 KiB

  1. <?php
  2. use Friendica\Core\Addon;
  3. use Friendica\Core\Config;
  4. use Friendica\Core\PConfig;
  5. use Friendica\Core\Worker;
  6. use Friendica\Database\DBM;
  7. use Friendica\Model\User;
  8. require_once 'include/dba.php';
  9. /**
  10. *
  11. * update.php - automatic system update
  12. *
  13. * This function is responsible for doing post update changes to the data
  14. * (not the structure) in the database.
  15. *
  16. * Database structure changes are done in src/Database/DBStructure.php
  17. *
  18. * If there is a need for a post process to a structure change, update this file
  19. * by adding a new function at the end with the number of the new DB_UPDATE_VERSION.
  20. *
  21. * The numbered script in this file has to be exactly like the DB_UPDATE_VERSION
  22. *
  23. * Example:
  24. * You are currently on version 4711 and you are preparing changes that demand an update script.
  25. *
  26. * 1. Create a function "update_4712()" here in the update.php
  27. * 2. Apply the needed structural changes in src/Database/DBStructure.php
  28. * 3. Set DB_UPDATE_VERSION in boot.php to 4712.
  29. */
  30. function update_1178() {
  31. require_once 'mod/profiles.php';
  32. $profiles = q("SELECT `uid`, `about`, `locality`, `pub_keywords`, `gender` FROM `profile` WHERE `is-default`");
  33. foreach ($profiles AS $profile) {
  34. if ($profile["about"].$profile["locality"].$profile["pub_keywords"].$profile["gender"] == "")
  35. continue;
  36. $profile["pub_keywords"] = profile_clean_keywords($profile["pub_keywords"]);
  37. $r = q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `self` AND `uid` = %d",
  38. dbesc($profile["about"]),
  39. dbesc($profile["locality"]),
  40. dbesc($profile["pub_keywords"]),
  41. dbesc($profile["gender"]),
  42. intval($profile["uid"])
  43. );
  44. }
  45. }
  46. function update_1179() {
  47. if (Config::get('system','no_community_page'))
  48. Config::set('system','community_page_style', CP_NO_COMMUNITY_PAGE);
  49. // Update the central item storage with uid=0
  50. Worker::add(PRIORITY_LOW, "threadupdate");
  51. return UPDATE_SUCCESS;
  52. }
  53. function update_1181() {
  54. // Fill the new fields in the term table.
  55. Worker::add(PRIORITY_LOW, "TagUpdate");
  56. return UPDATE_SUCCESS;
  57. }
  58. function update_1189() {
  59. if (strlen(Config::get('system','directory_submit_url')) &&
  60. !strlen(Config::get('system','directory'))) {
  61. Config::set('system','directory', dirname(Config::get('system','directory_submit_url')));
  62. Config::delete('system','directory_submit_url');
  63. }
  64. return UPDATE_SUCCESS;
  65. }
  66. function update_1191() {
  67. Config::set('system', 'maintenance', 1);
  68. if (Addon::isEnabled('forumlist')) {
  69. $addon = 'forumlist';
  70. $addons = Config::get('system', 'addon');
  71. $addons_arr = [];
  72. if ($addons) {
  73. $addons_arr = explode(",",str_replace(" ", "", $addons));
  74. $idx = array_search($addon, $addons_arr);
  75. if ($idx !== false){
  76. unset($addons_arr[$idx]);
  77. //delete forumlist manually from addon and hook table
  78. // since Addon::uninstall() don't work here
  79. q("DELETE FROM `addon` WHERE `name` = 'forumlist' ");
  80. q("DELETE FROM `hook` WHERE `file` = 'addon/forumlist/forumlist.php' ");
  81. Config::set('system','addon', implode(", ", $addons_arr));
  82. }
  83. }
  84. }
  85. // select old formlist addon entries
  86. $r = q("SELECT `uid`, `cat`, `k`, `v` FROM `pconfig` WHERE `cat` = '%s' ",
  87. dbesc('forumlist')
  88. );
  89. // convert old forumlist addon entries in new config entries
  90. if (DBM::is_result($r)) {
  91. foreach ($r as $rr) {
  92. $uid = $rr['uid'];
  93. $family = $rr['cat'];
  94. $key = $rr['k'];
  95. $value = $rr['v'];
  96. if ($key === 'randomise')
  97. PConfig::delete($uid,$family,$key);
  98. if ($key === 'show_on_profile') {
  99. if ($value)
  100. PConfig::set($uid,feature,forumlist_profile,$value);
  101. PConfig::delete($uid,$family,$key);
  102. }
  103. if ($key === 'show_on_network') {
  104. if ($value)
  105. PConfig::set($uid,feature,forumlist_widget,$value);
  106. PConfig::delete($uid,$family,$key);
  107. }
  108. }
  109. }
  110. Config::set('system', 'maintenance', 0);
  111. return UPDATE_SUCCESS;
  112. }
  113. function update_1203() {
  114. $r = q("UPDATE `user` SET `account-type` = %d WHERE `page-flags` IN (%d, %d)",
  115. dbesc(ACCOUNT_TYPE_COMMUNITY), dbesc(PAGE_COMMUNITY), dbesc(PAGE_PRVGROUP));
  116. }
  117. function update_1244() {
  118. // Sets legacy_password for all legacy hashes
  119. dba::update('user', ['legacy_password' => true], ['SUBSTR(password, 1, 4) != "$2y$"']);
  120. // All legacy hashes are re-hashed using the new secure hashing function
  121. $stmt = dba::select('user', ['uid', 'password'], ['legacy_password' => true]);
  122. while($user = dba::fetch($stmt)) {
  123. dba::update('user', ['password' => User::hashPassword($user['password'])], ['uid' => $user['uid']]);
  124. }
  125. // Logged in users are forcibly logged out
  126. dba::delete('session', ['1 = 1']);
  127. return UPDATE_SUCCESS;
  128. }
  129. function update_1245() {
  130. $rino = Config::get('system', 'rino_encrypt');
  131. if (!$rino) {
  132. return UPDATE_SUCCESS;
  133. }
  134. Config::set('system', 'rino_encrypt', 1);
  135. return UPDATE_SUCCESS;
  136. }
  137. function update_1247() {
  138. // Removing hooks with the old name
  139. dba::e("DELETE FROM `hook`
  140. WHERE `hook` LIKE 'plugin_%'");
  141. // Make sure we install the new renamed ones
  142. Addon::reload();
  143. }