3 use Friendica\Core\Addon;
4 use Friendica\Core\Config;
5 use Friendica\Core\PConfig;
6 use Friendica\Core\Worker;
7 use Friendica\Database\DBM;
8 use Friendica\Model\Contact;
9 use Friendica\Model\Item;
10 use Friendica\Model\User;
11 use Friendica\Core\L10n;
13 require_once 'include/dba.php';
17 * update.php - automatic system update
19 * This function is responsible for doing post update changes to the data
20 * (not the structure) in the database.
22 * Database structure changes are done in src/Database/DBStructure.php
24 * If there is a need for a post process to a structure change, update this file
25 * by adding a new function at the end with the number of the new DB_UPDATE_VERSION.
27 * The numbered script in this file has to be exactly like the DB_UPDATE_VERSION
30 * You are currently on version 4711 and you are preparing changes that demand an update script.
32 * 1. Create a function "update_4712()" here in the update.php
33 * 2. Apply the needed structural changes in src/Database/DBStructure.php
34 * 3. Set DB_UPDATE_VERSION in boot.php to 4712.
37 function update_1178() {
38 require_once 'mod/profiles.php';
40 $profiles = q("SELECT `uid`, `about`, `locality`, `pub_keywords`, `gender` FROM `profile` WHERE `is-default`");
42 foreach ($profiles AS $profile) {
43 if ($profile["about"].$profile["locality"].$profile["pub_keywords"].$profile["gender"] == "")
46 $profile["pub_keywords"] = profile_clean_keywords($profile["pub_keywords"]);
48 $r = q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `self` AND `uid` = %d",
49 dbesc($profile["about"]),
50 dbesc($profile["locality"]),
51 dbesc($profile["pub_keywords"]),
52 dbesc($profile["gender"]),
53 intval($profile["uid"])
58 function update_1179() {
59 if (Config::get('system','no_community_page'))
60 Config::set('system','community_page_style', CP_NO_COMMUNITY_PAGE);
62 // Update the central item storage with uid=0
63 Worker::add(PRIORITY_LOW, "threadupdate");
65 return UPDATE_SUCCESS;
68 function update_1181() {
70 // Fill the new fields in the term table.
71 Worker::add(PRIORITY_LOW, "TagUpdate");
73 return UPDATE_SUCCESS;
76 function update_1189() {
78 if (strlen(Config::get('system','directory_submit_url')) &&
79 !strlen(Config::get('system','directory'))) {
80 Config::set('system','directory', dirname(Config::get('system','directory_submit_url')));
81 Config::delete('system','directory_submit_url');
84 return UPDATE_SUCCESS;
87 function update_1191() {
88 Config::set('system', 'maintenance', 1);
90 if (Addon::isEnabled('forumlist')) {
92 $addons = Config::get('system', 'addon');
96 $addons_arr = explode(",",str_replace(" ", "", $addons));
98 $idx = array_search($addon, $addons_arr);
100 unset($addons_arr[$idx]);
101 //delete forumlist manually from addon and hook table
102 // since Addon::uninstall() don't work here
103 q("DELETE FROM `addon` WHERE `name` = 'forumlist' ");
104 q("DELETE FROM `hook` WHERE `file` = 'addon/forumlist/forumlist.php' ");
105 Config::set('system','addon', implode(", ", $addons_arr));
110 // select old formlist addon entries
111 $r = q("SELECT `uid`, `cat`, `k`, `v` FROM `pconfig` WHERE `cat` = '%s' ",
115 // convert old forumlist addon entries in new config entries
116 if (DBM::is_result($r)) {
117 foreach ($r as $rr) {
119 $family = $rr['cat'];
123 if ($key === 'randomise')
124 PConfig::delete($uid,$family,$key);
126 if ($key === 'show_on_profile') {
128 PConfig::set($uid,feature,forumlist_profile,$value);
130 PConfig::delete($uid,$family,$key);
133 if ($key === 'show_on_network') {
135 PConfig::set($uid,feature,forumlist_widget,$value);
137 PConfig::delete($uid,$family,$key);
142 Config::set('system', 'maintenance', 0);
144 return UPDATE_SUCCESS;
147 function update_1203() {
148 $r = q("UPDATE `user` SET `account-type` = %d WHERE `page-flags` IN (%d, %d)",
149 dbesc(ACCOUNT_TYPE_COMMUNITY), dbesc(PAGE_COMMUNITY), dbesc(PAGE_PRVGROUP));
152 function update_1244() {
153 // Sets legacy_password for all legacy hashes
154 dba::update('user', ['legacy_password' => true], ['SUBSTR(password, 1, 4) != "$2y$"']);
156 // All legacy hashes are re-hashed using the new secure hashing function
157 $stmt = dba::select('user', ['uid', 'password'], ['legacy_password' => true]);
158 while($user = dba::fetch($stmt)) {
159 dba::update('user', ['password' => User::hashPassword($user['password'])], ['uid' => $user['uid']]);
162 // Logged in users are forcibly logged out
163 dba::delete('session', ['1 = 1']);
165 return UPDATE_SUCCESS;
168 function update_1245() {
169 $rino = Config::get('system', 'rino_encrypt');
172 return UPDATE_SUCCESS;
175 Config::set('system', 'rino_encrypt', 1);
177 return UPDATE_SUCCESS;
180 function update_1247() {
181 // Removing hooks with the old name
182 dba::e("DELETE FROM `hook`
183 WHERE `hook` LIKE 'plugin_%'");
185 // Make sure we install the new renamed ones
189 function update_1260() {
190 Config::set('system', 'maintenance', 1);
191 Config::set('system', 'maintenance_reason', L10n::t('%s: Updating author-id and owner-id in item and thread table. ', DBM::date().' '.date('e')));
193 $items = dba::p("SELECT `id`, `owner-link`, `owner-name`, `owner-avatar`, `network` FROM `item`
194 WHERE `owner-id` = 0 AND `owner-link` != ''");
195 while ($item = dba::fetch($items)) {
196 $contact = ['url' => $item['owner-link'], 'name' => $item['owner-name'],
197 'photo' => $item['owner-avatar'], 'network' => $item['network']];
198 $cid = Contact::getIdForURL($item['owner-link'], 0, false, $contact);
202 Item::update(['owner-id' => $cid], ['id' => $item['id']]);
206 dba::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id`
207 SET `thread`.`owner-id` = `item`.`owner-id` WHERE `thread`.`owner-id` = 0");
209 $items = dba::p("SELECT `id`, `author-link`, `author-name`, `author-avatar`, `network` FROM `item`
210 WHERE `author-id` = 0 AND `author-link` != ''");
211 while ($item = dba::fetch($items)) {
212 $contact = ['url' => $item['author-link'], 'name' => $item['author-name'],
213 'photo' => $item['author-avatar'], 'network' => $item['network']];
214 $cid = Contact::getIdForURL($item['author-link'], 0, false, $contact);
218 Item::update(['author-id' => $cid], ['id' => $item['id']]);
222 dba::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id`
223 SET `thread`.`author-id` = `item`.`author-id` WHERE `thread`.`author-id` = 0");
225 Config::set('system', 'maintenance', 0);
226 return UPDATE_SUCCESS;
229 function update_1261() {
230 // This fixes the results of an issue in the develop branch of 2018-05.
231 dba::update('contact', ['blocked' => false, 'pending' => false], ['uid' => 0, 'blocked' => true, 'pending' => true]);
232 return UPDATE_SUCCESS;
235 function update_1278() {
236 Config::set('system', 'maintenance', 1);
237 Config::set('system', 'maintenance_reason', L10n::t('%s: Updating post-type.', DBM::date().' '.date('e')));
239 Item::update(['post-type' => Item::PT_PAGE], ['bookmark' => true]);
240 Item::update(['post-type' => Item::PT_PERSONAL_NOTE], ['type' => 'note']);
242 Config::set('system', 'maintenance', 0);
244 return UPDATE_SUCCESS;