]> git.mxchange.org Git - friendica.git/blob - update.php
Fix off-by-one error in Message ID header count check in Util\Emailer
[friendica.git] / update.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  * Automatic post-database structure change updates
21  *
22  * These functions are responsible for doing critical post update changes to the data (not the structure) in the database.
23  *
24  * Database structure changes are done in static/dbstructure.config.php
25  *
26  * For non-critical database migrations, please add a method in the Database\PostUpdate class
27  *
28  * If there is a need for a post update to a structure change, update this file
29  * by adding a new function at the end with the number of the new DB_UPDATE_VERSION.
30  *
31  * The numbered script in this file has to be exactly like the DB_UPDATE_VERSION
32  *
33  * Example:
34  * You are currently on version 4711 and you are preparing changes that demand an update script.
35  *
36  * 1. Create a function "update_4712()" here in the update.php
37  * 2. Apply the needed structural changes in static/dbStructure.php
38  * 3. Set DB_UPDATE_VERSION in static/dbstructure.config.php to 4712.
39  *
40  * If you need to run a script before the database update, name the function "pre_update_4712()"
41  */
42
43 use Friendica\Core\Config\ValueObject\Cache;
44 use Friendica\Core\Logger;
45 use Friendica\Core\Storage\Capability\ICanReadFromStorage;
46 use Friendica\Core\Storage\Type\Database as DatabaseStorage;
47 use Friendica\Core\Update;
48 use Friendica\Core\Worker;
49 use Friendica\Database\Database;
50 use Friendica\Database\DBA;
51 use Friendica\Database\DBStructure;
52 use Friendica\DI;
53 use Friendica\Model\Contact;
54 use Friendica\Model\Item;
55 use Friendica\Model\ItemURI;
56 use Friendica\Model\Notification;
57 use Friendica\Model\Photo;
58 use Friendica\Model\Post;
59 use Friendica\Model\Profile;
60 use Friendica\Model\User;
61 use Friendica\Security\PermissionSet\Repository\PermissionSet;
62 use Friendica\Worker\Delivery;
63
64 // Post-update script of PR 5751
65 function update_1298()
66 {
67         $keys = ['gender', 'marital', 'sexual'];
68         foreach ($keys as $translateKey) {
69                 $allData = DBA::select('profile', ['id', $translateKey]);
70                 $allLangs = DI::l10n()->getAvailableLanguages();
71                 $success = 0;
72                 $fail = 0;
73                 foreach ($allData as $key => $data) {
74                         $toTranslate = $data[$translateKey];
75                         if ($toTranslate != '') {
76                                 foreach ($allLangs as $key => $lang) {
77                                         $a = new \stdClass();
78                                         $a->strings = [];
79
80                                         // First we get the the localizations
81                                         if (file_exists("view/lang/$lang/strings.php")) {
82                                                 include "view/lang/$lang/strings.php";
83                                         }
84                                         if (file_exists("addon/morechoice/lang/$lang/strings.php")) {
85                                                 include "addon/morechoice/lang/$lang/strings.php";
86                                         }
87
88                                         $localizedStrings = $a->strings;
89                                         unset($a);
90
91                                         $key = array_search($toTranslate, $localizedStrings);
92                                         if ($key !== false) {
93                                                 break;
94                                         }
95
96                                         // defaulting to empty string
97                                         $key = '';
98                                 }
99
100                                 if ($key == '') {
101                                         $fail++;
102                                 } else {
103                                         DBA::update('profile', [$translateKey => $key], ['id' => $data['id']]);
104                                         Logger::notice('Updated contact', ['action' => 'update', 'contact' => $data['id'], "$translateKey" => $key,
105                                                 'was' => $data[$translateKey]]);
106
107                                         Contact::updateSelfFromUserID($data['id']);
108                                         Profile::publishUpdate($data['id']);
109                                         $success++;
110                                 }
111                         }
112                 }
113
114                 Logger::notice($translateKey . " fix completed", ['action' => 'update', 'translateKey' => $translateKey, 'Success' => $success, 'Fail' => $fail ]);
115         }
116         return Update::SUCCESS;
117 }
118
119 function update_1309()
120 {
121         $queue = DBA::select('queue', ['id', 'cid', 'guid']);
122         while ($entry = DBA::fetch($queue)) {
123                 $contact = DBA::selectFirst('contact', ['uid'], ['id' => $entry['cid']]);
124                 if (!DBA::isResult($contact)) {
125                         continue;
126                 }
127
128                 $item = Post::selectFirst(['id', 'gravity'], ['uid' => $contact['uid'], 'guid' => $entry['guid']]);
129                 if (!DBA::isResult($item)) {
130                         continue;
131                 }
132
133                 $deliver_options = ['priority' => PRIORITY_MEDIUM, 'dont_fork' => true];
134                 Worker::add($deliver_options, 'Delivery', Delivery::POST, $item['id'], $entry['cid']);
135                 Logger::info('Added delivery worker', ['item' => $item['id'], 'contact' => $entry['cid']]);
136                 DBA::delete('queue', ['id' => $entry['id']]);
137         }
138         return Update::SUCCESS;
139 }
140
141 function update_1315()
142 {
143         if (DBStructure::existsTable('item-delivery-data')) {
144                 DBA::delete('item-delivery-data', ['postopts' => '', 'inform' => '', 'queue_count' => 0, 'queue_done' => 0]);
145         }
146         return Update::SUCCESS;
147 }
148
149 function update_1318()
150 {
151         DBA::update('profile', ['marital' => "In a relation"], ['marital' => "Unavailable"]);
152         DBA::update('profile', ['marital' => "Single"], ['marital' => "Available"]);
153
154         Worker::add(PRIORITY_LOW, 'ProfileUpdate');
155         return Update::SUCCESS;
156 }
157
158 function update_1323()
159 {
160         $users = DBA::select('user', ['uid']);
161         while ($user = DBA::fetch($users)) {
162                 if (Contact::updateSelfFromUserID($user['uid'])) {
163                         Profile::publishUpdate($user['uid']);
164                 }
165         }
166         DBA::close($users);
167
168         return Update::SUCCESS;
169 }
170
171 function update_1327()
172 {
173         $contacts = DBA::select('contact', ['uid', 'id', 'blocked', 'readonly'], ["`uid` != ? AND (`blocked` OR `readonly`) AND NOT `pending`", 0]);
174         while ($contact = DBA::fetch($contacts)) {
175                 Contact\User::setBlocked($contact['id'], $contact['uid'], $contact['blocked']);
176                 Contact\User::setIgnored($contact['id'], $contact['uid'], $contact['readonly']);
177         }
178         DBA::close($contacts);
179
180         return Update::SUCCESS;
181 }
182
183 function update_1330()
184 {
185         $currStorage = DI::config()->get('storage', 'class', '');
186
187         // set the name of the storage instead of the classpath as config
188         if (!empty($currStorage)) {
189                 /** @var ICanReadFromStorage $currStorage */
190                 if (!DI::config()->set('storage', 'name', $currStorage::getName())) {
191                         return Update::FAILED;
192                 }
193
194                 // try to delete the class since it isn't needed. This won't work with config files
195                 DI::config()->delete('storage', 'class');
196         }
197
198         // Update attachments and photos
199         if (!DBA::e("UPDATE `photo` SET `photo`.`backend-class` = SUBSTR(`photo`.`backend-class`, 25) WHERE `photo`.`backend-class` LIKE 'Friendica\\\Model\\\Storage\\\%' ESCAPE '|'") ||
200             !DBA::e("UPDATE `attach` SET `attach`.`backend-class` = SUBSTR(`attach`.`backend-class`, 25) WHERE `attach`.`backend-class` LIKE 'Friendica\\\Model\\\Storage\\\%' ESCAPE '|'")) {
201                 return Update::FAILED;
202         };
203
204         return Update::SUCCESS;
205 }
206
207 function update_1332()
208 {
209         $condition = ["`is-default` IS NOT NULL"];
210         $profiles = DBA::select('profile', [], $condition);
211
212         while ($profile = DBA::fetch($profiles)) {
213                 Profile::migrate($profile);
214         }
215         DBA::close($profiles);
216
217         DBA::update('contact', ['profile-id' => null], ['`profile-id` IS NOT NULL']);
218
219         return Update::SUCCESS;
220 }
221
222 function update_1347()
223 {
224         foreach (Item::ACTIVITIES as $index => $activity) {
225                 DBA::insert('verb', ['id' => $index + 1, 'name' => $activity], Database::INSERT_IGNORE);
226         }
227
228         return Update::SUCCESS;
229 }
230
231 function pre_update_1348()
232 {
233         if (!DBA::exists('contact', ['id' => 0])) {
234                 DBA::insert('contact', ['nurl' => '']);
235                 $lastid = DBA::lastInsertId();
236                 if ($lastid != 0) {
237                         DBA::update('contact', ['id' => 0], ['id' => $lastid]);
238                 }
239         }
240
241         // The tables "permissionset" and "tag" could or could not exist during the update.
242         // This depends upon the previous version. Depending upon this situation we have to add
243         // the "0" values before adding the foreign keys - or after would be sufficient.
244
245         update_1348();
246
247         if (DBStructure::existsTable('auth_codes') && DBStructure::existsTable('clients')) {
248                 DBA::e("DELETE FROM `auth_codes` WHERE NOT `client_id` IN (SELECT `client_id` FROM `clients`)");
249         }
250         if (DBStructure::existsTable('tokens') && DBStructure::existsTable('clients')) {
251                 DBA::e("DELETE FROM `tokens` WHERE NOT `client_id` IN (SELECT `client_id` FROM `clients`)");
252         }
253         return Update::SUCCESS;
254 }
255
256 function update_1348()
257 {
258         // Insert a permissionset with id=0
259         // Inserting it without an ID and then changing the value to 0 tricks the auto increment
260         if (!DBA::exists('permissionset', ['id' => 0])) {
261                 DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']);
262                 $lastid = DBA::lastInsertId();
263                 if ($lastid != 0) {
264                         DBA::update('permissionset', ['id' => 0], ['id' => $lastid]);
265                 }
266         }
267
268         if (!DBA::exists('tag', ['id' => 0])) {
269                 DBA::insert('tag', ['name' => '']);
270                 $lastid = DBA::lastInsertId();
271                 if ($lastid != 0) {
272                         DBA::update('tag', ['id' => 0], ['id' => $lastid]);
273                 }
274         }
275
276         return Update::SUCCESS;
277 }
278
279 function update_1349()
280 {
281         if (!DBStructure::existsTable('item-activity')) {
282                 return Update::SUCCESS;
283         }
284
285         $correct = true;
286         foreach (Item::ACTIVITIES as $index => $activity) {
287                 if (!DBA::exists('verb', ['id' => $index + 1, 'name' => $activity])) {
288                         $correct = false;
289                 }
290         }
291
292         if (!$correct) {
293                 // The update failed - but it cannot be recovered, since the data doesn't match our expectation
294                 // This means that we can't use this "shortcut" to fill the "vid" field and we have to rely upon
295                 // the postupdate. This is not fatal, but means that it will take some longer time for the system
296                 // to fill all data.
297                 return Update::SUCCESS;
298         }
299
300         if (!DBA::e("UPDATE `item` INNER JOIN `item-activity` ON `item`.`uri-id` = `item-activity`.`uri-id`
301                 SET `vid` = `item-activity`.`activity` + 1 WHERE `gravity` = ? AND (`vid` IS NULL OR `vid` = 0)", GRAVITY_ACTIVITY)) {
302                 return Update::FAILED;
303         }
304
305         return Update::SUCCESS;
306 }
307
308 function update_1351()
309 {
310         if (DBStructure::existsTable('thread') && !DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id` SET `thread`.`uri-id` = `item`.`uri-id`")) {
311                 return Update::FAILED;
312         }
313
314         return Update::SUCCESS;
315 }
316
317 function pre_update_1354()
318 {
319         if (DBStructure::existsColumn('contact', ['ffi_keyword_blacklist'])
320                 && !DBStructure::existsColumn('contact', ['ffi_keyword_denylist'])
321                 && !DBA::e("ALTER TABLE `contact` CHANGE `ffi_keyword_blacklist` `ffi_keyword_denylist` text null")) {
322                 return Update::FAILED;
323         }
324         return Update::SUCCESS;
325 }
326
327 function update_1354()
328 {
329         if (DBStructure::existsColumn('contact', ['ffi_keyword_blacklist'])
330                 && DBStructure::existsColumn('contact', ['ffi_keyword_denylist'])) {
331                 if (!DBA::e("UPDATE `contact` SET `ffi_keyword_denylist` = `ffi_keyword_blacklist`")) {
332                         return Update::FAILED;
333                 }
334
335                 // When the data had been copied then the main task is done.
336                 // Having the old field removed is only beauty but not crucial.
337                 // So we don't care if this was successful or not.
338                 DBA::e("ALTER TABLE `contact` DROP `ffi_keyword_blacklist`");
339         }
340         return Update::SUCCESS;
341 }
342
343 function update_1357()
344 {
345         if (!DBA::e("UPDATE `contact` SET `failed` = true WHERE `success_update` < `failure_update` AND `failed` IS NULL")) {
346                 return Update::FAILED;
347         }
348
349         if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `success_update` > `failure_update` AND `failed` IS NULL")) {
350                 return Update::FAILED;
351         }
352
353         if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `updated` > `failure_update` AND `failed` IS NULL")) {
354                 return Update::FAILED;
355         }
356
357         if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `last-item` > `failure_update` AND `failed` IS NULL")) {
358                 return Update::FAILED;
359         }
360
361         if (!DBA::e("UPDATE `gserver` SET `failed` = true WHERE `last_contact` < `last_failure` AND `failed` IS NULL")) {
362                 return Update::FAILED;
363         }
364
365         if (!DBA::e("UPDATE `gserver` SET `failed` = false WHERE `last_contact` > `last_failure` AND `failed` IS NULL")) {
366                 return Update::FAILED;
367         }
368
369         return Update::SUCCESS;
370 }
371
372 function pre_update_1358()
373 {
374         if (!DBA::e("DELETE FROM `contact-relation` WHERE NOT `relation-cid` IN (SELECT `id` FROM `contact`) OR NOT `cid` IN (SELECT `id` FROM `contact`)")) {
375                 return Update::FAILED;
376         }
377
378         return Update::SUCCESS;
379 }
380
381 function pre_update_1363()
382 {
383         Photo::delete(["`contact-id` != ? AND NOT `contact-id` IN (SELECT `id` FROM `contact`)", 0]);
384         return Update::SUCCESS;
385 }
386
387 function pre_update_1364()
388 {
389         if (!DBA::e("DELETE FROM `2fa_recovery_codes` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
390                 return Update::FAILED;
391         }
392
393         if (!DBA::e("DELETE FROM `2fa_app_specific_password` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
394                 return Update::FAILED;
395         }
396
397         if (!DBA::e("DELETE FROM `attach` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
398                 return Update::FAILED;
399         }
400
401         if (DBStructure::existsTable('clients') && !DBA::e("DELETE FROM `clients` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
402                 return Update::FAILED;
403         }
404
405         if (!DBA::e("DELETE FROM `conv` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
406                 return Update::FAILED;
407         }
408
409         if (!DBA::e("DELETE FROM `fsuggest` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
410                 return Update::FAILED;
411         }
412
413         if (!DBA::e("DELETE FROM `group` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
414                 return Update::FAILED;
415         }
416
417         if (!DBA::e("DELETE FROM `intro` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
418                 return Update::FAILED;
419         }
420
421         if (!DBA::e("DELETE FROM `manage` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
422                 return Update::FAILED;
423         }
424
425         if (!DBA::e("DELETE FROM `manage` WHERE NOT `mid` IN (SELECT `uid` FROM `user`)")) {
426                 return Update::FAILED;
427         }
428
429         if (!DBA::e("DELETE FROM `mail` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
430                 return Update::FAILED;
431         }
432
433         if (!DBA::e("DELETE FROM `mailacct` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
434                 return Update::FAILED;
435         }
436
437         if (!DBA::e("DELETE FROM `notify` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
438                 return Update::FAILED;
439         }
440
441         if (!DBA::e("DELETE FROM `openwebauth-token` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
442                 return Update::FAILED;
443         }
444
445         if (!DBA::e("DELETE FROM `pconfig` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
446                 return Update::FAILED;
447         }
448
449         if (!DBA::e("DELETE FROM `profile` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
450                 return Update::FAILED;
451         }
452
453         if (DBStructure::existsTable('profile_check') && !DBA::e("DELETE FROM `profile_check` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
454                 return Update::FAILED;
455         }
456
457         if (!DBA::e("DELETE FROM `profile_field` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
458                 return Update::FAILED;
459         }
460
461         if (!DBA::e("DELETE FROM `push_subscriber` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
462                 return Update::FAILED;
463         }
464
465         if (!DBA::e("DELETE FROM `register` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
466                 return Update::FAILED;
467         }
468
469         if (!DBA::e("DELETE FROM `search` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
470                 return Update::FAILED;
471         }
472
473         if (DBStructure::existsTable('tokens') && !DBA::e("DELETE FROM `tokens` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
474                 return Update::FAILED;
475         }
476
477         if (!DBA::e("DELETE FROM `user-contact` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
478                 return Update::FAILED;
479         }
480
481         if (DBStructure::existsTable('user-item') && !DBA::e("DELETE FROM `user-item` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
482                 return Update::FAILED;
483         }
484
485         if (!DBA::e("DELETE FROM `notify-threads` WHERE NOT `receiver-uid` IN (SELECT `uid` FROM `user`)")) {
486                 return Update::FAILED;
487         }
488
489         if (!DBA::e("DELETE FROM `event` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
490                 return Update::FAILED;
491         }
492
493         if (!DBA::e("DELETE FROM `fsuggest` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
494                 return Update::FAILED;
495         }
496
497         if (!DBA::e("DELETE FROM `group_member` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
498                 return Update::FAILED;
499         }
500
501         if (!DBA::e("DELETE FROM `intro` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
502                 return Update::FAILED;
503         }
504
505         if (DBStructure::existsTable('profile_check') && !DBA::e("DELETE FROM `profile_check` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
506                 return Update::FAILED;
507         }
508
509         if (!DBA::e("DELETE FROM `user-contact` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
510                 return Update::FAILED;
511         }
512
513         if (!DBA::e("DELETE FROM `group_member` WHERE NOT `gid` IN (SELECT `id` FROM `group`)")) {
514                 return Update::FAILED;
515         }
516
517         if (!DBA::e("DELETE FROM `gserver-tag` WHERE NOT `gserver-id` IN (SELECT `id` FROM `gserver`)")) {
518                 return Update::FAILED;
519         }
520
521         if (DBStructure::existsTable('user-item') && !DBA::e("DELETE FROM `user-item` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) {
522                 return Update::FAILED;
523         }
524
525         return Update::SUCCESS;
526 }
527
528 function pre_update_1365()
529 {
530         if (!DBA::e("DELETE FROM `notify-threads` WHERE NOT `notify-id` IN (SELECT `id` FROM `notify`)")) {
531                 return Update::FAILED;
532         }
533
534         if (DBStructure::existsTable('thread') && !DBA::e("DELETE FROM `thread` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) {
535                 return Update::FAILED;
536         }
537
538         return Update::SUCCESS;
539 }
540
541 function update_1375()
542 {
543         if (!DBA::e("UPDATE `item` SET `thr-parent` = `parent-uri`, `thr-parent-id` = `parent-uri-id` WHERE `thr-parent` = ''")) {
544                 return Update::FAILED;
545         }
546
547         return Update::SUCCESS;
548 }
549
550 function pre_update_1376()
551 {
552         // Insert a user with uid=0
553         DBStructure::checkInitialValues();
554
555         if (!DBA::e("DELETE FROM `item` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
556                 return Update::FAILED;
557         }
558
559         if (!DBA::e("DELETE FROM `event` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
560                 return Update::FAILED;
561         }
562
563         if (DBStructure::existsTable('thread') && !DBA::e("DELETE FROM `thread` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
564                 return Update::FAILED;
565         }
566
567         if (!DBA::e("DELETE FROM `permissionset` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
568                 return Update::FAILED;
569         }
570
571         if (!DBA::e("DELETE FROM `openwebauth-token` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
572                 return Update::FAILED;
573         }
574
575         if (!DBA::e("DELETE FROM `post-category` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
576                 return Update::FAILED;
577         }
578
579         Photo::delete(["NOT `uid` IN (SELECT `uid` FROM `user`)"]);
580
581         if (!DBA::e("DELETE FROM `contact` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
582                 return Update::FAILED;
583         }
584
585         return Update::SUCCESS;
586 }
587
588 function pre_update_1377()
589 {
590         DBStructure::checkInitialValues();
591
592         if (!DBA::e("DELETE FROM `item` WHERE NOT `author-id` IN (SELECT `id` FROM `contact`)")) {
593                 return Update::FAILED;
594         }
595
596         if (!DBA::e("DELETE FROM `item` WHERE NOT `owner-id` IN (SELECT `id` FROM `contact`)")) {
597                 return Update::FAILED;
598         }
599
600         if (!DBA::e("UPDATE `item` SET `contact-id` = `owner-id` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
601                 return Update::FAILED;
602         }
603
604         if (DBStructure::existsTable('thread') && !DBA::e("DELETE FROM `thread` WHERE NOT `author-id` IN (SELECT `id` FROM `contact`)")) {
605                 return Update::FAILED;
606         }
607
608         if (DBStructure::existsTable('thread') && !DBA::e("DELETE FROM `thread` WHERE NOT `owner-id` IN (SELECT `id` FROM `contact`)")) {
609                 return Update::FAILED;
610         }
611
612         if (DBStructure::existsTable('thread') && !DBA::e("UPDATE `thread` SET `contact-id` = `owner-id` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
613                 return Update::FAILED;
614         }
615
616         if (!DBA::e("UPDATE `notify` SET `uri-id` = NULL WHERE `uri-id` = 0")) {
617                 return Update::FAILED;
618         }
619
620         if (DBStructure::existsTable('diaspora-interaction') && !DBA::e("DELETE FROM `diaspora-interaction` WHERE `uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
621                 return Update::FAILED;
622         }
623
624         if (DBStructure::existsTable('item-activity') && !DBA::e("DELETE FROM `item-activity` WHERE `uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
625                 return Update::FAILED;
626         }
627
628         if (DBStructure::existsTable('item-content') && !DBA::e("DELETE FROM `item-content` WHERE `uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
629                 return Update::FAILED;
630         }
631
632         if (!DBA::e("DELETE FROM `notify` WHERE `uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
633                 return Update::FAILED;
634         }
635
636         if (!DBA::e("UPDATE `notify` SET `parent-uri-id` = NULL WHERE `parent-uri-id` = 0")) {
637                 return Update::FAILED;
638         }
639         if (!DBA::e("DELETE FROM `notify` WHERE `parent-uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
640                 return Update::FAILED;
641         }
642
643         if (!DBA::e("UPDATE `notify-threads` SET `master-parent-uri-id` = NULL WHERE `master-parent-uri-id` = 0")) {
644                 return Update::FAILED;
645         }
646
647         if (!DBA::e("DELETE FROM `notify-threads` WHERE `master-parent-uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
648                 return Update::FAILED;
649         }
650
651         if (!DBA::e("DELETE FROM `notify-threads` WHERE `master-parent-item` NOT IN (SELECT `id` FROM `item`)")) {
652                 return Update::FAILED;
653         }
654
655         return Update::SUCCESS;
656 }
657
658 function update_1380()
659 {
660         if (!DBA::e("UPDATE `notify` INNER JOIN `item` ON `item`.`id` = `notify`.`iid` SET `notify`.`uri-id` = `item`.`uri-id` WHERE `notify`.`uri-id` IS NULL AND `notify`.`otype` IN (?, ?)",
661                 Notification\ObjectType::ITEM, Notification\ObjectType::PERSON)) {
662                 return Update::FAILED;
663         }
664
665         if (!DBA::e("UPDATE `notify` INNER JOIN `item` ON `item`.`id` = `notify`.`parent` SET `notify`.`parent-uri-id` = `item`.`uri-id` WHERE `notify`.`parent-uri-id` IS NULL AND `notify`.`otype` IN (?, ?)",
666                 Notification\ObjectType::ITEM, Notification\ObjectType::PERSON)) {
667                 return Update::FAILED;
668         }
669
670         return Update::SUCCESS;
671 }
672
673 function pre_update_1395()
674 {
675         if (DBStructure::existsTable('post-user') && !DBStructure::existsColumn('post-user', ['id']) && !DBA::e("DROP TABLE `post-user`")) {
676                 return Update::FAILED;
677         }
678         return Update::SUCCESS;
679 }
680
681 function update_1395()
682 {
683         if (!DBA::e("INSERT INTO `post-user`(`id`, `uri-id`, `uid`, `contact-id`, `unseen`, `origin`, `psid`)
684                 SELECT `id`, `uri-id`, `uid`, `contact-id`, `unseen`, `origin`, `psid` FROM `item`
685                 ON DUPLICATE KEY UPDATE `contact-id` = `item`.`contact-id`, `unseen` = `item`.`unseen`, `origin` = `item`.`origin`, `psid` = `item`.`psid`")) {
686                 return Update::FAILED;
687         }
688
689         if (DBStructure::existsTable('user-item') && !DBA::e("INSERT INTO `post-user`(`uri-id`, `uid`, `hidden`, `notification-type`)
690                 SELECT `uri-id`, `user-item`.`uid`, `hidden`,`notification-type` FROM `user-item`
691                         INNER JOIN `item` ON `item`.`id` = `user-item`.`iid`
692                 ON DUPLICATE KEY UPDATE `hidden` = `user-item`.`hidden`, `notification-type` = `user-item`.`notification-type`")) {
693                 return Update::FAILED;
694         }
695         return Update::SUCCESS;
696 }
697
698 function update_1396()
699 {
700         if (!DBStructure::existsTable('item-content')) {
701                 return Update::SUCCESS;
702         }
703
704         if (DBStructure::existsColumn('item-content', ['raw-body'])) {
705                 if (!DBA::e("INSERT IGNORE INTO `post-content`(`uri-id`, `title`, `content-warning`, `body`, `raw-body`,
706                         `location`, `coord`, `language`, `app`, `rendered-hash`, `rendered-html`,
707                         `object-type`, `object`, `target-type`, `target`, `resource-id`, `plink`)
708                         SELECT `item-content`.`uri-id`, `item-content`.`title`, `item-content`.`content-warning`,
709                                 `item-content`.`body`, `item-content`.`raw-body`, `item-content`.`location`, `item-content`.`coord`,
710                                 `item-content`.`language`, `item-content`.`app`, `item-content`.`rendered-hash`,
711                                 `item-content`.`rendered-html`, `item-content`.`object-type`, `item-content`.`object`,
712                                 `item-content`.`target-type`, `item-content`.`target`, `item`.`resource-id`, `item-content`.`plink`
713                                 FROM `item-content` INNER JOIN `item` ON `item`.`uri-id` = `item-content`.`uri-id`")) {
714                         return Update::FAILED;
715                 }
716         } else {
717                 if (!DBA::e("INSERT IGNORE INTO `post-content`(`uri-id`, `title`, `content-warning`, `body`,
718                         `location`, `coord`, `language`, `app`, `rendered-hash`, `rendered-html`,
719                         `object-type`, `object`, `target-type`, `target`, `resource-id`, `plink`)
720                         SELECT `item-content`.`uri-id`, `item-content`.`title`, `item-content`.`content-warning`,
721                                 `item-content`.`body`, `item-content`.`location`, `item-content`.`coord`,
722                                 `item-content`.`language`, `item-content`.`app`, `item-content`.`rendered-hash`,
723                                 `item-content`.`rendered-html`, `item-content`.`object-type`, `item-content`.`object`,
724                                 `item-content`.`target-type`, `item-content`.`target`, `item`.`resource-id`, `item-content`.`plink`
725                                 FROM `item-content` INNER JOIN `item` ON `item`.`uri-id` = `item-content`.`uri-id`")) {
726                         return Update::FAILED;
727                 }
728         }
729         return Update::SUCCESS;
730 }
731
732 function update_1397()
733 {
734         if (!DBA::e("INSERT INTO `post-user-notification`(`uri-id`, `uid`, `notification-type`)
735                 SELECT `uri-id`, `uid`, `notification-type` FROM `post-user` WHERE `notification-type` != 0
736                 ON DUPLICATE KEY UPDATE `uri-id` = `post-user`.`uri-id`, `uid` = `post-user`.`uid`, `notification-type` = `post-user`.`notification-type`")) {
737                 return Update::FAILED;
738         }
739
740         if (!DBStructure::existsTable('user-item')) {
741                 return Update::SUCCESS;
742         }
743
744         if (!DBA::e("INSERT INTO `post-user-notification`(`uri-id`, `uid`, `notification-type`)
745                 SELECT `uri-id`, `user-item`.`uid`, `notification-type` FROM `user-item`
746                         INNER JOIN `item` ON `item`.`id` = `user-item`.`iid` WHERE `notification-type` != 0
747                 ON DUPLICATE KEY UPDATE `notification-type` = `user-item`.`notification-type`")) {
748                 return Update::FAILED;
749         }
750
751         if (!DBStructure::existsTable('thread')) {
752                 return Update::SUCCESS;
753         }
754
755         if (!DBA::e("INSERT IGNORE INTO `post-thread-user`(`uri-id`, `uid`, `pinned`, `starred`, `ignored`, `wall`, `pubmail`, `forum_mode`)
756                 SELECT `thread`.`uri-id`, `thread`.`uid`, `user-item`.`pinned`, `thread`.`starred`,
757                         `thread`.`ignored`, `thread`.`wall`, `thread`.`pubmail`, `thread`.`forum_mode`
758                 FROM `thread` LEFT JOIN `user-item` ON `user-item`.`iid` = `thread`.`iid`")) {
759                 return Update::FAILED;
760         }
761
762         return Update::SUCCESS;
763 }
764
765 function update_1398()
766 {
767         if (!DBStructure::existsTable('thread')) {
768                 return Update::SUCCESS;
769         }
770
771         if (!DBA::e("INSERT IGNORE INTO `post-thread` (`uri-id`, `owner-id`, `author-id`, `network`, `created`, `received`, `changed`, `commented`)
772                 SELECT `uri-id`, `owner-id`, `author-id`, `network`, `created`, `received`, `changed`, `commented` FROM `thread`")) {
773                         return Update::FAILED;
774         }
775
776         if (!DBStructure::existsTable('thread')) {
777                 return Update::SUCCESS;
778         }
779
780         if (!DBA::e("UPDATE `post-thread-user` INNER JOIN `thread` ON `thread`.`uid` = `post-thread-user`.`uid` AND `thread`.`uri-id` = `post-thread-user`.`uri-id`
781                 SET `post-thread-user`.`mention` = `thread`.`mention`")) {
782                         return Update::FAILED;
783         }
784
785         return Update::SUCCESS;
786 }
787
788 function update_1399()
789 {
790         if (!DBA::e("UPDATE `post-thread-user` INNER JOIN `post-user` ON `post-user`.`uid` = `post-thread-user`.`uid` AND `post-user`.`uri-id` = `post-thread-user`.`uri-id`
791                 SET `post-thread-user`.`contact-id` = `post-user`.`contact-id`, `post-thread-user`.`unseen` = `post-user`.`unseen`,
792                 `post-thread-user`.`hidden` = `post-user`.`hidden`, `post-thread-user`.`origin` = `post-user`.`origin`,
793                 `post-thread-user`.`psid` = `post-user`.`psid`, `post-thread-user`.`post-user-id` = `post-user`.`id`")) {
794                         return Update::FAILED;
795         }
796
797         return Update::SUCCESS;
798 }
799
800 function update_1400()
801 {
802         if (!DBA::e("INSERT IGNORE INTO `post` (`uri-id`, `parent-uri-id`, `thr-parent-id`, `owner-id`, `author-id`, `network`,
803                 `created`, `received`, `edited`, `gravity`, `causer-id`, `post-type`, `vid`, `private`, `visible`, `deleted`, `global`)
804                 SELECT `uri-id`, `parent-uri-id`, `thr-parent-id`, `owner-id`, `author-id`, `network`, `created`, `received`, `edited`,
805                         `gravity`, `causer-id`, `post-type`, `vid`, `private`, `visible`, `deleted`, `global` FROM `item`")) {
806                         return Update::FAILED;
807         }
808
809         if (!DBA::e("UPDATE `post-user` INNER JOIN `item` ON `item`.`uri-id` = `post-user`.`uri-id` AND `item`.`uid` = `post-user`.`uid`
810                 INNER JOIN `event` ON `item`.`event-id` = `event`.`id` AND `event`.`id` != 0
811                 SET `post-user`.`event-id` = `item`.`event-id`")) {
812                 return Update::FAILED;
813         }
814
815         if (!DBA::e("UPDATE `post-user` INNER JOIN `item` ON `item`.`uri-id` = `post-user`.`uri-id` AND `item`.`uid` = `post-user`.`uid`
816                 SET `post-user`.`wall` = `item`.`wall`, `post-user`.`parent-uri-id` = `item`.`parent-uri-id`,
817                 `post-user`.`thr-parent-id` = `item`.`thr-parent-id`,
818                 `post-user`.`created` = `item`.`created`, `post-user`.`edited` = `item`.`edited`,
819                 `post-user`.`received` = `item`.`received`, `post-user`.`gravity` = `item`.`gravity`,
820                 `post-user`.`network` = `item`.`network`, `post-user`.`owner-id` = `item`.`owner-id`,
821                 `post-user`.`author-id` = `item`.`author-id`, `post-user`.`causer-id` = `item`.`causer-id`,
822                 `post-user`.`post-type` = `item`.`post-type`, `post-user`.`vid` = `item`.`vid`,
823                 `post-user`.`private` = `item`.`private`, `post-user`.`global` = `item`.`global`,
824                 `post-user`.`visible` = `item`.`visible`, `post-user`.`deleted` = `item`.`deleted`")) {
825                 return Update::FAILED;
826         }
827
828         if (!DBA::e("INSERT IGNORE INTO `post-thread-user` (`uri-id`, `owner-id`, `author-id`, `causer-id`, `network`,
829                 `created`, `received`, `changed`, `commented`, `uid`,  `wall`, `contact-id`, `unseen`, `hidden`, `origin`, `psid`, `post-user-id`)
830                 SELECT `uri-id`, `owner-id`, `author-id`, `causer-id`, `network`, `created`, `received`, `received`, `received`,
831                         `uid`, `wall`, `contact-id`, `unseen`, `hidden`, `origin`, `psid`, `id`
832                 FROM `post-user` WHERE `gravity` = 0 AND NOT EXISTS(SELECT `uri-id` FROM `post-thread-user` WHERE `post-user-id` = `post-user`.id)")) {
833                 return Update::FAILED;
834         }
835
836         if (!DBA::e("UPDATE `post-thread-user` INNER JOIN `post-thread` ON `post-thread-user`.`uri-id` = `post-thread`.`uri-id`
837                 SET `post-thread-user`.`owner-id` = `post-thread`.`owner-id`, `post-thread-user`.`author-id` = `post-thread`.`author-id`,
838                 `post-thread-user`.`causer-id` = `post-thread`.`causer-id`, `post-thread-user`.`network` = `post-thread`.`network`,
839                 `post-thread-user`.`created` = `post-thread`.`created`, `post-thread-user`.`received` = `post-thread`.`received`,
840                 `post-thread-user`.`changed` = `post-thread`.`changed`, `post-thread-user`.`commented` = `post-thread`.`commented`")) {
841                 return Update::FAILED;
842         }
843
844         return Update::SUCCESS;
845 }
846
847 function pre_update_1403()
848 {
849         // Necessary before a primary key change
850         if (DBStructure::existsTable('parsed_url') && !DBA::e("DROP TABLE `parsed_url`")) {
851                 return Update::FAILED;
852         }
853
854         return Update::SUCCESS;
855 }
856
857 function update_1404()
858 {
859         $tasks = DBA::select('workerqueue', ['id', 'command', 'parameter'], ['command' => ['notifier', 'delivery', 'apdelivery', 'done' => false]]);
860         while ($task = DBA::fetch($tasks)) {
861                 $parameters = json_decode($task['parameter'], true);
862
863                 if (is_array($parameters) && count($parameters) && in_array($parameters[0], [Delivery::MAIL, Delivery::SUGGESTION, Delivery::REMOVAL, Delivery::RELOCATION])) {
864                         continue;
865                 }
866
867                 switch (strtolower($task['command'])) {
868                         case 'notifier':
869                                 if (count($parameters) == 3) {
870                                         continue 2;
871                                 }
872                                 $item = DBA::selectFirst('item', ['uid', 'uri-id'], ['id' => $parameters[1]]);
873                                 if (!DBA::isResult($item)) {
874                                         continue 2;
875                                 }
876
877                                 $parameters[1] = $item['uri-id'];
878                                 $parameters[2] = $item['uid'];
879                                 break;
880                         case 'delivery':
881                                 if (count($parameters) == 4) {
882                                         continue 2;
883                                 }
884                                 $item = DBA::selectFirst('item', ['uid', 'uri-id'], ['id' => $parameters[1]]);
885                                 if (!DBA::isResult($item)) {
886                                         continue 2;
887                                 }
888
889                                 $parameters[1] = $item['uri-id'];
890                                 $parameters[3] = $item['uid'];
891                                 break;
892                         case 'apdelivery':
893                                 if (count($parameters) == 6) {
894                                         continue 2;
895                                 }
896
897                                 if (empty($parameters[4])) {
898                                         $parameters[4] = [];
899                                 }
900
901                                 $item = DBA::selectFirst('item', ['uri-id'], ['id' => $parameters[1]]);
902                                 if (!DBA::isResult($item)) {
903                                         continue 2;
904                                 }
905
906                                 $parameters[5] = $item['uri-id'];
907                                 break;
908                         default:
909                                 continue 2;
910                 }
911                 DBA::update('workerqueue', ['parameter' => json_encode($parameters)], ['id' => $task['id']]);
912
913                 return Update::SUCCESS;
914         }
915 }
916
917 function update_1407()
918 {
919         if (!DBA::e("UPDATE `post` SET `causer-id` = NULL WHERE `causer-id` = 0")) {
920                 return Update::FAILED;
921         }
922         if (!DBA::e("UPDATE `post-user` SET `causer-id` = NULL WHERE `causer-id` = 0")) {
923                 return Update::FAILED;
924         }
925         if (!DBA::e("UPDATE `post-thread` SET `causer-id` = NULL WHERE `causer-id` = 0")) {
926                 return Update::FAILED;
927         }
928         if (!DBA::e("UPDATE `post-thread-user` SET `causer-id` = NULL WHERE `causer-id` = 0")) {
929                 return Update::FAILED;
930         }
931
932         return Update::SUCCESS;
933 }
934
935 function update_1413()
936 {
937         if (!DBA::e("UPDATE `post-user` SET `post-reason` = `post-type` WHERE `post-type` >= 64 and `post-type` <= 75")) {
938                 return Update::FAILED;
939         }
940 }
941
942 function update_1419()
943 {
944         $mails = DBA::select('mail', ['id', 'from-url', 'uri', 'parent-uri', 'guid'], [], ['order' => ['id']]);
945         while ($mail = DBA::fetch($mails)) {
946                 $fields = [];
947                 $fields['author-id'] = Contact::getIdForURL($mail['from-url'], 0, false);
948                 if (empty($fields['author-id'])) {
949                         continue;
950                 }
951
952                 $fields['uri-id']        = ItemURI::insert(['uri' => $mail['uri'], 'guid' => $mail['guid']]);
953                 $fields['parent-uri-id'] = ItemURI::getIdByURI($mail['parent-uri']);
954
955                 $reply = DBA::selectFirst('mail', ['uri', 'uri-id', 'guid'], ['parent-uri' => $mail['parent-uri'], 'reply' => false]);
956                 if (!empty($reply)) {
957                         $fields['thr-parent'] = $reply['uri'];
958                         if (!empty($reply['uri-id'])) {
959                                 $fields['thr-parent-id'] = $reply['uri-id'];
960                         } else {
961                                 $fields['thr-parent-id'] = ItemURI::insert(['uri' => $reply['uri'], 'guid' => $reply['guid']]);
962                         }
963                 }
964
965                 DBA::update('mail', $fields, ['id' => $mail['id']]);
966         }
967         return Update::SUCCESS;
968 }
969
970 function update_1429()
971 {
972         if (!DBA::e("UPDATE `contact` SET `uri-id` = null WHERE NOT `uri-id` IS NULL")) {
973                 return Update::FAILED;
974         }
975
976         if (!DBA::e("UPDATE `fcontact` SET `uri-id` = null WHERE NOT `uri-id` IS NULL")) {
977                 return Update::FAILED;
978         }
979
980         if (!DBA::e("UPDATE `apcontact` SET `uri-id` = null WHERE NOT `uri-id` IS NULL")) {
981                 return Update::FAILED;
982         }
983
984         DI::config()->set("system", "post_update_version", 1423);
985
986         return Update::SUCCESS;
987 }
988
989 function update_1434()
990 {
991         $name = DI::config()->get('storage', 'name');
992
993         // In case of an empty config, set "Database" as default storage backend
994         if (empty($name)) {
995                 DI::config()->set('storage', 'name', DatabaseStorage::getName());
996         }
997
998         // In case of a Using deprecated storage class value, set the right name for it
999         if (stristr($name, 'Friendica\Model\Storage\\')) {
1000                 DI::config()->set('storage', 'name', substr($name, 24));
1001         }
1002
1003         return Update::SUCCESS;
1004 }
1005
1006 function update_1438()
1007 {
1008         DBA::update('photo', ['photo-type' => Photo::USER_AVATAR], ['profile' => true]);
1009         DBA::update('photo', ['photo-type' => Photo::CONTACT_AVATAR], ["NOT `profile` AND NOT `contact-id` IS NULL AND `contact-id` != ?", 0]);
1010         DBA::update('photo', ['photo-type' => Photo::DEFAULT], ["NOT `profile` AND (`contact-id` IS NULL OR `contact-id` = ?) AND `photo-type` IS NULL AND `album` != ?", 0, Photo::CONTACT_PHOTOS]);
1011 }
1012
1013 function update_1439()
1014 {
1015         $intros = DBA::select('intro', ['id', 'fid'], ["NOT `fid` IS NULL AND `fid` != ?", 0]);
1016         while ($intro = DBA::fetch($intros)) {
1017                 $fcontact = DBA::selectFirst('fcontact', ['url'], ['id' => $intro['fid']]);
1018                 if (!empty($fcontact['url'])) {
1019                         $id = Contact::getIdForURL($fcontact['url']);
1020                         if (!empty($id)) {
1021                                 DBA::update('intro',['suggest-cid' => $id], ['id' => $intro['id']]);
1022                         }
1023                 }
1024         }
1025         DBA::close($intros);
1026 }
1027
1028 function update_1440()
1029 {
1030         // Fix wrong public permissionset
1031         DBA::p("UPDATE `profile_field` SET `psid` = ? WHERE psid IN (SELECT `id` FROM `permissionset` WHERE `id` != ? AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '')", PermissionSet::PUBLIC, PermissionSet::PUBLIC);
1032         DBA::delete('permissionset', ["`id` != ? AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = ''", PermissionSet::PUBLIC]);
1033
1034         return Update::SUCCESS;
1035 }
1036
1037 function update_1441()
1038 {
1039         $languages = DI::l10n()->getAvailableLanguages();
1040
1041         $albums = [Photo::PROFILE_PHOTOS];
1042         foreach ($languages as $language) {
1043                 $albums[] = DI::l10n()->withLang($language)->t(Photo::PROFILE_PHOTOS);
1044         }
1045         $albums = array_unique($albums);
1046
1047         Photo::update(['photo-type' => Photo::USER_AVATAR], ['album' => $albums]);
1048
1049         return Update::SUCCESS;
1050 }
1051
1052 function update_1442()
1053 {
1054         // transform blocked intros into ignored intros
1055         DBA::update('intro', ['ignore' => 1, 'blocked' => 0], ['blocked' => 1]);
1056
1057         return Update::SUCCESS;
1058 }
1059
1060 /**
1061  * A bug in Contact\User::updateByContactUpdate prevented any update to the user-contact table since the rows have been
1062  * created in version 1435. This version fixes this bug but the user-contact rows are outdated, we need to regenerate
1063  * them.
1064  */
1065 function update_1444()
1066 {
1067         DBA::e('TRUNCATE TABLE `user-contact`');
1068
1069         $contacts = DBA::select('contact', [], ["`uid` != ?", 0]);
1070         while ($contact = DBA::fetch($contacts)) {
1071                 Contact\User::insertForContactArray($contact);
1072         }
1073
1074         return Update::SUCCESS;
1075 }
1076
1077 function update_1446()
1078 {
1079         $distributed_cache_driver_source = DI::config()->getCache()->getSource('system', 'distributed_cache_driver');
1080         $cache_driver_source = DI::config()->getCache()->getSource('system', 'cache_driver');
1081
1082         // In case the distributed cache driver is the default value, but the current cache driver isn't default,
1083         // we assume that the distributed cache driver should be the same as the current cache driver
1084         if ($distributed_cache_driver_source === Cache::SOURCE_STATIC && $cache_driver_source > Cache::SOURCE_STATIC) {
1085                 DI::config()->set('system', 'distributed_cache_driver', DI::config()->get('system', 'cache_driver'));
1086         }
1087
1088         return Update::SUCCESS;
1089 }
1090
1091 function update_1451()
1092 {
1093         DBA::update('user', ['account-type' => User::ACCOUNT_TYPE_COMMUNITY], ['page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]]);
1094         DBA::update('contact', ['contact-type' => Contact::TYPE_COMMUNITY], ["`forum` OR `prv`"]);
1095         DBA::update('contact', ['manually-approve' => true], ['prv' => true]);
1096
1097         return Update::SUCCESS;
1098 }
1099
1100 function update_1457()
1101 {
1102         $pinned = DBA::select('post-thread-user', ['uri-id'], ['pinned' => true]);
1103         while ($post = DBA::fetch($pinned)) {
1104                 Post\Collection::add($post['uri-id'], Post\Collection::FEATURED);
1105         }
1106         DBA::close($pinned);
1107
1108         return Update::SUCCESS;
1109 }