]> git.mxchange.org Git - friendica.git/blob - update.php
0a2f788f694697bc641a7f2d298510eb68898909
[friendica.git] / update.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
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\Addon;
44 use Friendica\Core\Logger;
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\Notify;
54 use Friendica\Model\Photo;
55 use Friendica\Model\Post;
56 use Friendica\Model\Storage;
57 use Friendica\Worker\Delivery;
58
59 // Post-update script of PR 5751
60 function update_1298()
61 {
62         $keys = ['gender', 'marital', 'sexual'];
63         foreach ($keys as $translateKey) {
64                 $allData = DBA::select('profile', ['id', $translateKey]);
65                 $allLangs = DI::l10n()->getAvailableLanguages();
66                 $success = 0;
67                 $fail = 0;
68                 foreach ($allData as $key => $data) {
69                         $toTranslate = $data[$translateKey];
70                         if ($toTranslate != '') {
71                                 foreach ($allLangs as $key => $lang) {
72                                         $a = new \stdClass();
73                                         $a->strings = [];
74
75                                         // First we get the the localizations
76                                         if (file_exists("view/lang/$lang/strings.php")) {
77                                                 include "view/lang/$lang/strings.php";
78                                         }
79                                         if (file_exists("addon/morechoice/lang/$lang/strings.php")) {
80                                                 include "addon/morechoice/lang/$lang/strings.php";
81                                         }
82
83                                         $localizedStrings = $a->strings;
84                                         unset($a);
85
86                                         $key = array_search($toTranslate, $localizedStrings);
87                                         if ($key !== false) {
88                                                 break;
89                                         }
90
91                                         // defaulting to empty string
92                                         $key = '';
93                                 }
94
95                                 if ($key == '') {
96                                         $fail++;
97                                 } else {
98                                         DBA::update('profile', [$translateKey => $key], ['id' => $data['id']]);
99                                         Logger::notice('Updated contact', ['action' => 'update', 'contact' => $data['id'], "$translateKey" => $key,
100                                                 'was' => $data[$translateKey]]);
101                                         Worker::add(PRIORITY_LOW, 'ProfileUpdate', $data['id']);
102                                         Contact::updateSelfFromUserID($data['id']);
103                                         $success++;
104                                 }
105                         }
106                 }
107
108                 Logger::notice($translateKey . " fix completed", ['action' => 'update', 'translateKey' => $translateKey, 'Success' => $success, 'Fail' => $fail ]);
109         }
110         return Update::SUCCESS;
111 }
112
113 function update_1309()
114 {
115         $queue = DBA::select('queue', ['id', 'cid', 'guid']);
116         while ($entry = DBA::fetch($queue)) {
117                 $contact = DBA::selectFirst('contact', ['uid'], ['id' => $entry['cid']]);
118                 if (!DBA::isResult($contact)) {
119                         continue;
120                 }
121
122                 $item = Post::selectFirst(['id', 'gravity'], ['uid' => $contact['uid'], 'guid' => $entry['guid']]);
123                 if (!DBA::isResult($item)) {
124                         continue;
125                 }
126
127                 $deliver_options = ['priority' => PRIORITY_MEDIUM, 'dont_fork' => true];
128                 Worker::add($deliver_options, 'Delivery', Delivery::POST, $item['id'], $entry['cid']);
129                 Logger::info('Added delivery worker', ['item' => $item['id'], 'contact' => $entry['cid']]);
130                 DBA::delete('queue', ['id' => $entry['id']]);
131         }
132         return Update::SUCCESS;
133 }
134
135 function update_1315()
136 {
137         if (DBStructure::existsTable('item-delivery-data')) {
138                 DBA::delete('item-delivery-data', ['postopts' => '', 'inform' => '', 'queue_count' => 0, 'queue_done' => 0]);
139         }
140         return Update::SUCCESS;
141 }
142
143 function update_1318()
144 {
145         DBA::update('profile', ['marital' => "In a relation"], ['marital' => "Unavailable"]);
146         DBA::update('profile', ['marital' => "Single"], ['marital' => "Available"]);
147
148         Worker::add(PRIORITY_LOW, 'ProfileUpdate');
149         return Update::SUCCESS;
150 }
151
152 function update_1323()
153 {
154         $users = DBA::select('user', ['uid']);
155         while ($user = DBA::fetch($users)) {
156                 Contact::updateSelfFromUserID($user['uid']);
157         }
158         DBA::close($users);
159
160         return Update::SUCCESS;
161 }
162
163 function update_1327()
164 {
165         $contacts = DBA::select('contact', ['uid', 'id', 'blocked', 'readonly'], ["`uid` != ? AND (`blocked` OR `readonly`) AND NOT `pending`", 0]);
166         while ($contact = DBA::fetch($contacts)) {
167                 Contact\User::setBlocked($contact['id'], $contact['uid'], $contact['blocked']);
168                 Contact\User::setIgnored($contact['id'], $contact['uid'], $contact['readonly']);
169         }
170         DBA::close($contacts);
171
172         return Update::SUCCESS;
173 }
174
175 function update_1330()
176 {
177         $currStorage = DI::config()->get('storage', 'class', '');
178
179         // set the name of the storage instead of the classpath as config
180         if (!empty($currStorage)) {
181                 /** @var Storage\IStorage $currStorage */
182                 if (!DI::config()->set('storage', 'name', $currStorage::getName())) {
183                         return Update::FAILED;
184                 }
185
186                 // try to delete the class since it isn't needed. This won't work with config files
187                 DI::config()->delete('storage', 'class');
188         }
189
190         // Update attachments and photos
191         if (!DBA::p("UPDATE `photo` SET `photo`.`backend-class` = SUBSTR(`photo`.`backend-class`, 25) WHERE `photo`.`backend-class` LIKE 'Friendica\\\Model\\\Storage\\\%' ESCAPE '|'") ||
192             !DBA::p("UPDATE `attach` SET `attach`.`backend-class` = SUBSTR(`attach`.`backend-class`, 25) WHERE `attach`.`backend-class` LIKE 'Friendica\\\Model\\\Storage\\\%' ESCAPE '|'")) {
193                 return Update::FAILED;
194         };
195
196         return Update::SUCCESS;
197 }
198
199 function update_1332()
200 {
201         $condition = ["`is-default` IS NOT NULL"];
202         $profiles = DBA::select('profile', [], $condition);
203
204         while ($profile = DBA::fetch($profiles)) {
205                 DI::profileField()->migrateFromLegacyProfile($profile);
206         }
207         DBA::close($profiles);
208
209         DBA::update('contact', ['profile-id' => null], ['`profile-id` IS NOT NULL']);
210
211         return Update::SUCCESS;
212 }
213
214 function update_1347()
215 {
216         foreach (Item::ACTIVITIES as $index => $activity) {
217                 DBA::insert('verb', ['id' => $index + 1, 'name' => $activity], Database::INSERT_IGNORE);
218         }
219
220         return Update::SUCCESS;
221 }
222
223 function pre_update_1348()
224 {
225         if (!DBA::exists('contact', ['id' => 0])) {
226                 DBA::insert('contact', ['nurl' => '']);
227                 $lastid = DBA::lastInsertId();
228                 if ($lastid != 0) {
229                         DBA::update('contact', ['id' => 0], ['id' => $lastid]);
230                 }
231         }
232
233         // The tables "permissionset" and "tag" could or could not exist during the update.
234         // This depends upon the previous version. Depending upon this situation we have to add
235         // the "0" values before adding the foreign keys - or after would be sufficient.
236
237         update_1348();
238
239         DBA::e("DELETE FROM `auth_codes` WHERE NOT `client_id` IN (SELECT `client_id` FROM `clients`)");
240         DBA::e("DELETE FROM `tokens` WHERE NOT `client_id` IN (SELECT `client_id` FROM `clients`)");
241
242         return Update::SUCCESS;
243 }
244
245 function update_1348()
246 {
247         // Insert a permissionset with id=0
248         // Inserting it without an ID and then changing the value to 0 tricks the auto increment
249         if (!DBA::exists('permissionset', ['id' => 0])) {
250                 DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']);       
251                 $lastid = DBA::lastInsertId();
252                 if ($lastid != 0) {
253                         DBA::update('permissionset', ['id' => 0], ['id' => $lastid]);
254                 }
255         }
256
257         if (!DBA::exists('tag', ['id' => 0])) {
258                 DBA::insert('tag', ['name' => '']);
259                 $lastid = DBA::lastInsertId();
260                 if ($lastid != 0) {
261                         DBA::update('tag', ['id' => 0], ['id' => $lastid]);
262                 }
263         }
264
265         return Update::SUCCESS;
266 }
267
268 function update_1349()
269 {
270         $correct = true;
271         foreach (Item::ACTIVITIES as $index => $activity) {
272                 if (!DBA::exists('verb', ['id' => $index + 1, 'name' => $activity])) {
273                         $correct = false;
274                 }
275         }
276
277         if (!$correct) {
278                 // The update failed - but it cannot be recovered, since the data doesn't match our expectation
279                 // This means that we can't use this "shortcut" to fill the "vid" field and we have to rely upon
280                 // the postupdate. This is not fatal, but means that it will take some longer time for the system
281                 // to fill all data.
282                 return Update::SUCCESS;
283         }
284
285         if (!DBA::e("UPDATE `item` INNER JOIN `item-activity` ON `item`.`uri-id` = `item-activity`.`uri-id`
286                 SET `vid` = `item-activity`.`activity` + 1 WHERE `gravity` = ? AND (`vid` IS NULL OR `vid` = 0)", GRAVITY_ACTIVITY)) {
287                 return Update::FAILED;
288         }
289
290         return Update::SUCCESS;
291 }
292
293 function update_1351()
294 {
295         if (!DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id` SET `thread`.`uri-id` = `item`.`uri-id`")) {
296                 return Update::FAILED;
297         }
298
299         return Update::SUCCESS;
300 }
301
302 function pre_update_1354()
303 {
304         if (DBStructure::existsColumn('contact', ['ffi_keyword_blacklist'])
305                 && !DBStructure::existsColumn('contact', ['ffi_keyword_denylist'])
306                 && !DBA::e("ALTER TABLE `contact` CHANGE `ffi_keyword_blacklist` `ffi_keyword_denylist` text null")) {
307                 return Update::FAILED;
308         }
309         return Update::SUCCESS;
310 }
311
312 function update_1354()
313 {
314         if (DBStructure::existsColumn('contact', ['ffi_keyword_blacklist'])
315                 && DBStructure::existsColumn('contact', ['ffi_keyword_denylist'])) {
316                 if (!DBA::e("UPDATE `contact` SET `ffi_keyword_denylist` = `ffi_keyword_blacklist`")) {
317                         return Update::FAILED;
318                 }
319
320                 // When the data had been copied then the main task is done.
321                 // Having the old field removed is only beauty but not crucial.
322                 // So we don't care if this was successful or not.
323                 DBA::e("ALTER TABLE `contact` DROP `ffi_keyword_blacklist`");
324         }
325         return Update::SUCCESS;
326 }
327
328 function update_1357()
329 {
330         if (!DBA::e("UPDATE `contact` SET `failed` = true WHERE `success_update` < `failure_update` AND `failed` IS NULL")) {
331                 return Update::FAILED;
332         }
333
334         if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `success_update` > `failure_update` AND `failed` IS NULL")) {
335                 return Update::FAILED;
336         }
337
338         if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `updated` > `failure_update` AND `failed` IS NULL")) {
339                 return Update::FAILED;
340         }
341
342         if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `last-item` > `failure_update` AND `failed` IS NULL")) {
343                 return Update::FAILED;
344         }
345
346         if (!DBA::e("UPDATE `gserver` SET `failed` = true WHERE `last_contact` < `last_failure` AND `failed` IS NULL")) {
347                 return Update::FAILED;
348         }
349
350         if (!DBA::e("UPDATE `gserver` SET `failed` = false WHERE `last_contact` > `last_failure` AND `failed` IS NULL")) {
351                 return Update::FAILED;
352         }
353
354         return Update::SUCCESS;
355 }
356
357 function pre_update_1358()
358 {
359         if (!DBA::e("DELETE FROM `contact-relation` WHERE NOT `relation-cid` IN (SELECT `id` FROM `contact`) OR NOT `cid` IN (SELECT `id` FROM `contact`)")) {
360                 return Update::FAILED;
361         }
362
363         return Update::SUCCESS;
364 }
365
366 function pre_update_1363()
367 {
368         Photo::delete(["`contact-id` != ? AND NOT `contact-id` IN (SELECT `id` FROM `contact`)", 0]);
369         return Update::SUCCESS;
370 }
371
372 function pre_update_1364()
373 {
374         if (!DBA::e("DELETE FROM `2fa_recovery_codes` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
375                 return Update::FAILED;
376         }
377
378         if (!DBA::e("DELETE FROM `2fa_app_specific_password` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
379                 return Update::FAILED;
380         }
381
382         if (!DBA::e("DELETE FROM `attach` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
383                 return Update::FAILED;
384         }
385
386         if (!DBA::e("DELETE FROM `clients` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
387                 return Update::FAILED;
388         }
389
390         if (!DBA::e("DELETE FROM `conv` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
391                 return Update::FAILED;
392         }
393
394         if (!DBA::e("DELETE FROM `fsuggest` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
395                 return Update::FAILED;
396         }
397
398         if (!DBA::e("DELETE FROM `group` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
399                 return Update::FAILED;
400         }
401
402         if (!DBA::e("DELETE FROM `intro` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
403                 return Update::FAILED;
404         }
405
406         if (!DBA::e("DELETE FROM `manage` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
407                 return Update::FAILED;
408         }
409
410         if (!DBA::e("DELETE FROM `manage` WHERE NOT `mid` IN (SELECT `uid` FROM `user`)")) {
411                 return Update::FAILED;
412         }
413
414         if (!DBA::e("DELETE FROM `mail` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
415                 return Update::FAILED;
416         }
417
418         if (!DBA::e("DELETE FROM `mailacct` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
419                 return Update::FAILED;
420         }
421
422         if (!DBA::e("DELETE FROM `notify` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
423                 return Update::FAILED;
424         }
425
426         if (!DBA::e("DELETE FROM `openwebauth-token` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
427                 return Update::FAILED;
428         }
429
430         if (!DBA::e("DELETE FROM `pconfig` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
431                 return Update::FAILED;
432         }
433
434         if (!DBA::e("DELETE FROM `profile` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
435                 return Update::FAILED;
436         }
437
438         if (!DBA::e("DELETE FROM `profile_check` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
439                 return Update::FAILED;
440         }
441
442         if (!DBA::e("DELETE FROM `profile_field` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
443                 return Update::FAILED;
444         }
445
446         if (!DBA::e("DELETE FROM `push_subscriber` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
447                 return Update::FAILED;
448         }
449
450         if (!DBA::e("DELETE FROM `register` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
451                 return Update::FAILED;
452         }
453
454         if (!DBA::e("DELETE FROM `search` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
455                 return Update::FAILED;
456         }
457
458         if (!DBA::e("DELETE FROM `tokens` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
459                 return Update::FAILED;
460         }
461
462         if (!DBA::e("DELETE FROM `user-contact` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
463                 return Update::FAILED;
464         }
465
466         if (!DBA::e("DELETE FROM `user-item` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
467                 return Update::FAILED;
468         }
469
470         if (!DBA::e("DELETE FROM `notify-threads` WHERE NOT `receiver-uid` IN (SELECT `uid` FROM `user`)")) {
471                 return Update::FAILED;
472         }
473
474         if (!DBA::e("DELETE FROM `event` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
475                 return Update::FAILED;
476         }
477
478         if (!DBA::e("DELETE FROM `fsuggest` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
479                 return Update::FAILED;
480         }
481
482         if (!DBA::e("DELETE FROM `group_member` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
483                 return Update::FAILED;
484         }
485
486         if (!DBA::e("DELETE FROM `intro` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
487                 return Update::FAILED;
488         }
489
490         if (!DBA::e("DELETE FROM `participation` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
491                 return Update::FAILED;
492         }
493
494         if (!DBA::e("DELETE FROM `profile_check` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
495                 return Update::FAILED;
496         }
497
498         if (!DBA::e("DELETE FROM `user-contact` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
499                 return Update::FAILED;
500         }
501
502         if (!DBA::e("DELETE FROM `participation` WHERE NOT `fid` IN (SELECT `id` FROM `fcontact`)")) {
503                 return Update::FAILED;
504         }
505
506         if (!DBA::e("DELETE FROM `group_member` WHERE NOT `gid` IN (SELECT `id` FROM `group`)")) {
507                 return Update::FAILED;
508         }
509
510         if (!DBA::e("DELETE FROM `gserver-tag` WHERE NOT `gserver-id` IN (SELECT `id` FROM `gserver`)")) {
511                 return Update::FAILED;
512         }
513
514         if (!DBA::e("DELETE FROM `participation` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) {
515                 return Update::FAILED;
516         }
517
518         if (!DBA::e("DELETE FROM `user-item` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) {
519                 return Update::FAILED;
520         }
521
522         return Update::SUCCESS;
523 }
524
525 function pre_update_1365()
526 {
527         if (!DBA::e("DELETE FROM `notify-threads` WHERE NOT `notify-id` IN (SELECT `id` FROM `notify`)")) {
528                 return Update::FAILED;
529         }
530
531         if (!DBA::e("DELETE FROM `thread` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) {
532                 return Update::FAILED;
533         }
534
535         return Update::SUCCESS;
536 }
537
538 function update_1375()
539 {
540         if (!DBA::e("UPDATE `item` SET `thr-parent` = `parent-uri`, `thr-parent-id` = `parent-uri-id` WHERE `thr-parent` = ''")) {
541                 return Update::FAILED;
542         }
543
544         return Update::SUCCESS;
545 }
546
547 function pre_update_1376()
548 {
549         // Insert a user with uid=0
550         DBStructure::checkInitialValues();
551
552         if (!DBA::e("DELETE FROM `item` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
553                 return Update::FAILED;
554         }
555
556         if (!DBA::e("DELETE FROM `event` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
557                 return Update::FAILED;
558         }
559
560         if (!DBA::e("DELETE FROM `thread` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
561                 return Update::FAILED;
562         }
563
564         if (!DBA::e("DELETE FROM `permissionset` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
565                 return Update::FAILED;
566         }
567
568         if (!DBA::e("DELETE FROM `openwebauth-token` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
569                 return Update::FAILED;
570         }
571
572         if (!DBA::e("DELETE FROM `post-category` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
573                 return Update::FAILED;
574         }
575
576         Photo::delete(["NOT `uid` IN (SELECT `uid` FROM `user`)"]);
577
578         if (!DBA::e("DELETE FROM `contact` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
579                 return Update::FAILED;
580         }
581
582         return Update::SUCCESS;
583 }
584
585 function pre_update_1377()
586 {
587         DBStructure::checkInitialValues();
588
589         if (!DBA::e("DELETE FROM `item` WHERE NOT `author-id` IN (SELECT `id` FROM `contact`)")) {
590                 return Update::FAILED;
591         }
592
593         if (!DBA::e("DELETE FROM `item` WHERE NOT `owner-id` IN (SELECT `id` FROM `contact`)")) {
594                 return Update::FAILED;
595         }
596
597         if (!DBA::e("UPDATE `item` SET `contact-id` = `owner-id` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
598                 return Update::FAILED;
599         }
600
601         if (!DBA::e("DELETE FROM `thread` WHERE NOT `author-id` IN (SELECT `id` FROM `contact`)")) {
602                 return Update::FAILED;
603         }
604
605         if (!DBA::e("DELETE FROM `thread` WHERE NOT `owner-id` IN (SELECT `id` FROM `contact`)")) {
606                 return Update::FAILED;
607         }
608
609         if (!DBA::e("UPDATE `thread` SET `contact-id` = `owner-id` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
610                 return Update::FAILED;
611         }
612
613         if (!DBA::e("UPDATE `notify` SET `uri-id` = NULL WHERE `uri-id` = 0")) {
614                 return Update::FAILED;
615         }
616
617         if (DBStructure::existsTable('diaspora-interaction') && !DBA::e("DELETE FROM `diaspora-interaction` WHERE `uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
618                 return Update::FAILED;
619         }
620
621         if (DBStructure::existsTable('item-activity') && !DBA::e("DELETE FROM `item-activity` WHERE `uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
622                 return Update::FAILED;
623         }
624
625         if (DBStructure::existsTable('item-content') && !DBA::e("DELETE FROM `item-content` WHERE `uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
626                 return Update::FAILED;
627         }
628
629         if (!DBA::e("DELETE FROM `notify` WHERE `uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
630                 return Update::FAILED;
631         }
632
633         if (!DBA::e("UPDATE `notify` SET `parent-uri-id` = NULL WHERE `parent-uri-id` = 0")) {
634                 return Update::FAILED;
635         }
636         if (!DBA::e("DELETE FROM `notify` WHERE `parent-uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
637                 return Update::FAILED;
638         }
639
640         if (!DBA::e("UPDATE `notify-threads` SET `master-parent-uri-id` = NULL WHERE `master-parent-uri-id` = 0")) {
641                 return Update::FAILED;
642         }
643
644         if (!DBA::e("DELETE FROM `notify-threads` WHERE `master-parent-uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
645                 return Update::FAILED;
646         }
647
648         if (!DBA::e("DELETE FROM `notify-threads` WHERE `master-parent-item` NOT IN (SELECT `id` FROM `item`)")) {
649                 return Update::FAILED;
650         }
651
652         return Update::SUCCESS;
653 }
654
655 function update_1380()
656 {
657         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 (?, ?)",
658                 Notify\ObjectType::ITEM, Notify\ObjectType::PERSON)) {
659                 return Update::FAILED;
660         }
661
662         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 (?, ?)",
663                 Notify\ObjectType::ITEM, Notify\ObjectType::PERSON)) {
664                 return Update::FAILED;
665         }
666
667         return Update::SUCCESS;
668 }