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