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