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