3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
20 * Automatic post-databse structure change updates
22 * These functions are responsible for doing critical post update changes to the data (not the structure) in the database.
24 * Database structure changes are done in static/dbstructure.config.php
26 * For non-critical database migrations, please add a method in the Database\PostUpdate class
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.
31 * The numbered script in this file has to be exactly like the DB_UPDATE_VERSION
34 * You are currently on version 4711 and you are preparing changes that demand an update script.
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.
40 * If you need to run a script before the database update, name the function "pre_update_4712()"
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;
51 use Friendica\Model\Contact;
52 use Friendica\Model\Item;
53 use Friendica\Model\Photo;
54 use Friendica\Model\User;
55 use Friendica\Model\Storage;
56 use Friendica\Util\DateTimeFormat;
57 use Friendica\Worker\Delivery;
59 function update_1179()
61 if (DI::config()->get('system', 'no_community_page')) {
62 DI::config()->set('system', 'community_page_style', CP_NO_COMMUNITY_PAGE);
65 // Update the central item storage with uid=0
66 Worker::add(PRIORITY_LOW, "threadupdate");
68 return Update::SUCCESS;
71 function update_1181()
74 // Fill the new fields in the term table.
75 // deactivated, the "term" table is deprecated
76 // Worker::add(PRIORITY_LOW, "TagUpdate");
78 return Update::SUCCESS;
81 function update_1189()
84 if (strlen(DI::config()->get('system', 'directory_submit_url')) &&
85 !strlen(DI::config()->get('system', 'directory'))) {
86 DI::config()->set('system', 'directory', dirname(DI::config()->get('system', 'directory_submit_url')));
87 DI::config()->delete('system', 'directory_submit_url');
90 return Update::SUCCESS;
93 function update_1191()
95 DI::config()->set('system', 'maintenance', 1);
97 if (Addon::isEnabled('forumlist')) {
98 Addon::uninstall('forumlist');
101 // select old formlist addon entries
102 $r = q("SELECT `uid`, `cat`, `k`, `v` FROM `pconfig` WHERE `cat` = '%s' ",
103 DBA::escape('forumlist')
106 // convert old forumlist addon entries in new config entries
107 if (DBA::isResult($r)) {
108 foreach ($r as $rr) {
110 $family = $rr['cat'];
114 if ($key === 'randomise') {
115 DI::pConfig()->delete($uid, $family, $key);
118 if ($key === 'show_on_profile') {
120 DI::pConfig()->set($uid, 'feature', 'forumlist_profile', $value);
123 DI::pConfig()->delete($uid, $family, $key);
126 if ($key === 'show_on_network') {
128 DI::pConfig()->set($uid, 'feature', 'forumlist_widget', $value);
131 DI::pConfig()->delete($uid, $family, $key);
136 DI::config()->set('system', 'maintenance', 0);
138 return Update::SUCCESS;
141 function update_1203()
143 $r = q("UPDATE `user` SET `account-type` = %d WHERE `page-flags` IN (%d, %d)",
144 DBA::escape(User::ACCOUNT_TYPE_COMMUNITY),
145 DBA::escape(User::PAGE_FLAGS_COMMUNITY),
146 DBA::escape(User::PAGE_FLAGS_PRVGROUP)
150 function update_1244()
152 // Sets legacy_password for all legacy hashes
153 DBA::update('user', ['legacy_password' => true], ['SUBSTR(password, 1, 4) != "$2y$"']);
155 // All legacy hashes are re-hashed using the new secure hashing function
156 $stmt = DBA::select('user', ['uid', 'password'], ['legacy_password' => true]);
157 while ($user = DBA::fetch($stmt)) {
158 DBA::update('user', ['password' => User::hashPassword($user['password'])], ['uid' => $user['uid']]);
161 // Logged in users are forcibly logged out
162 DBA::delete('session', ['1 = 1']);
164 return Update::SUCCESS;
167 function update_1245()
169 $rino = DI::config()->get('system', 'rino_encrypt');
172 return Update::SUCCESS;
175 DI::config()->set('system', 'rino_encrypt', 1);
177 return Update::SUCCESS;
180 function update_1247()
182 // Removing hooks with the old name
183 DBA::e("DELETE FROM `hook`
184 WHERE `hook` LIKE 'plugin_%'");
186 // Make sure we install the new renamed ones
190 function update_1260()
192 DI::config()->set('system', 'maintenance', 1);
195 'maintenance_reason',
197 '%s: Updating author-id and owner-id in item and thread table. ',
198 DateTimeFormat::utcNow().' '.date('e')
202 $items = DBA::p("SELECT `id`, `owner-link`, `owner-name`, `owner-avatar`, `network` FROM `item`
203 WHERE `owner-id` = 0 AND `owner-link` != ''");
204 while ($item = DBA::fetch($items)) {
205 $contact = ['url' => $item['owner-link'], 'name' => $item['owner-name'],
206 'photo' => $item['owner-avatar'], 'network' => $item['network']];
207 $cid = Contact::getIdForURL($item['owner-link'], 0, null, $contact);
211 Item::update(['owner-id' => $cid], ['id' => $item['id']]);
215 DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id`
216 SET `thread`.`owner-id` = `item`.`owner-id` WHERE `thread`.`owner-id` = 0");
218 $items = DBA::p("SELECT `id`, `author-link`, `author-name`, `author-avatar`, `network` FROM `item`
219 WHERE `author-id` = 0 AND `author-link` != ''");
220 while ($item = DBA::fetch($items)) {
221 $contact = ['url' => $item['author-link'], 'name' => $item['author-name'],
222 'photo' => $item['author-avatar'], 'network' => $item['network']];
223 $cid = Contact::getIdForURL($item['author-link'], 0, null, $contact);
227 Item::update(['author-id' => $cid], ['id' => $item['id']]);
231 DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id`
232 SET `thread`.`author-id` = `item`.`author-id` WHERE `thread`.`author-id` = 0");
234 DI::config()->set('system', 'maintenance', 0);
235 return Update::SUCCESS;
238 function update_1261()
240 // This fixes the results of an issue in the develop branch of 2018-05.
241 DBA::update('contact', ['blocked' => false, 'pending' => false], ['uid' => 0, 'blocked' => true, 'pending' => true]);
242 return Update::SUCCESS;
245 function update_1278()
247 DI::config()->set('system', 'maintenance', 1);
250 'maintenance_reason',
252 '%s: Updating post-type.',
253 DateTimeFormat::utcNow().' '.date('e')
257 Item::update(['post-type' => Item::PT_PAGE], ['bookmark' => true]);
258 Item::update(['post-type' => Item::PT_PERSONAL_NOTE], ['type' => 'note']);
260 DI::config()->set('system', 'maintenance', 0);
262 return Update::SUCCESS;
265 function update_1288()
267 // Updates missing `uri-id` values
269 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");
270 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");
272 return Update::SUCCESS;
275 // Post-update script of PR 5751
276 function update_1298()
278 $keys = ['gender', 'marital', 'sexual'];
279 foreach ($keys as $translateKey) {
280 $allData = DBA::select('profile', ['id', $translateKey]);
281 $allLangs = DI::l10n()->getAvailableLanguages();
284 foreach ($allData as $key => $data) {
285 $toTranslate = $data[$translateKey];
286 if ($toTranslate != '') {
287 foreach ($allLangs as $key => $lang) {
288 $a = new \stdClass();
291 // First we get the the localizations
292 if (file_exists("view/lang/$lang/strings.php")) {
293 include "view/lang/$lang/strings.php";
295 if (file_exists("addon/morechoice/lang/$lang/strings.php")) {
296 include "addon/morechoice/lang/$lang/strings.php";
299 $localizedStrings = $a->strings;
302 $key = array_search($toTranslate, $localizedStrings);
303 if ($key !== false) {
307 // defaulting to empty string
314 DBA::update('profile', [$translateKey => $key], ['id' => $data['id']]);
315 Logger::notice('Updated contact', ['action' => 'update', 'contact' => $data['id'], "$translateKey" => $key,
316 'was' => $data[$translateKey]]);
317 Worker::add(PRIORITY_LOW, 'ProfileUpdate', $data['id']);
318 Contact::updateSelfFromUserID($data['id']);
324 Logger::notice($translateKey . " fix completed", ['action' => 'update', 'translateKey' => $translateKey, 'Success' => $success, 'Fail' => $fail ]);
326 return Update::SUCCESS;
329 function update_1309()
331 $queue = DBA::select('queue', ['id', 'cid', 'guid']);
332 while ($entry = DBA::fetch($queue)) {
333 $contact = DBA::selectFirst('contact', ['uid'], ['id' => $entry['cid']]);
334 if (!DBA::isResult($contact)) {
338 $item = Item::selectFirst(['id', 'gravity'], ['uid' => $contact['uid'], 'guid' => $entry['guid']]);
339 if (!DBA::isResult($item)) {
343 $deliver_options = ['priority' => PRIORITY_MEDIUM, 'dont_fork' => true];
344 Worker::add($deliver_options, 'Delivery', Delivery::POST, $item['id'], $entry['cid']);
345 Logger::info('Added delivery worker', ['item' => $item['id'], 'contact' => $entry['cid']]);
346 DBA::delete('queue', ['id' => $entry['id']]);
348 return Update::SUCCESS;
351 function update_1315()
353 if (DBStructure::existsTable('item-delivery-data')) {
354 DBA::delete('item-delivery-data', ['postopts' => '', 'inform' => '', 'queue_count' => 0, 'queue_done' => 0]);
356 return Update::SUCCESS;
359 function update_1318()
361 DBA::update('profile', ['marital' => "In a relation"], ['marital' => "Unavailable"]);
362 DBA::update('profile', ['marital' => "Single"], ['marital' => "Available"]);
364 Worker::add(PRIORITY_LOW, 'ProfileUpdate');
365 return Update::SUCCESS;
368 function update_1323()
370 $users = DBA::select('user', ['uid']);
371 while ($user = DBA::fetch($users)) {
372 Contact::updateSelfFromUserID($user['uid']);
376 return Update::SUCCESS;
379 function update_1327()
381 $contacts = DBA::select('contact', ['uid', 'id', 'blocked', 'readonly'], ["`uid` != ? AND (`blocked` OR `readonly`) AND NOT `pending`", 0]);
382 while ($contact = DBA::fetch($contacts)) {
383 Contact\User::setBlocked($contact['id'], $contact['uid'], $contact['blocked']);
384 Contact\User::setIgnored($contact['id'], $contact['uid'], $contact['readonly']);
386 DBA::close($contacts);
388 return Update::SUCCESS;
391 function update_1330()
393 $currStorage = DI::config()->get('storage', 'class', '');
395 // set the name of the storage instead of the classpath as config
396 if (!empty($currStorage)) {
397 /** @var Storage\IStorage $currStorage */
398 if (!DI::config()->set('storage', 'name', $currStorage::getName())) {
399 return Update::FAILED;
402 // try to delete the class since it isn't needed. This won't work with config files
403 DI::config()->delete('storage', 'class');
406 // Update attachments and photos
407 if (!DBA::p("UPDATE `photo` SET `photo`.`backend-class` = SUBSTR(`photo`.`backend-class`, 25) WHERE `photo`.`backend-class` LIKE 'Friendica\\\Model\\\Storage\\\%' ESCAPE '|'") ||
408 !DBA::p("UPDATE `attach` SET `attach`.`backend-class` = SUBSTR(`attach`.`backend-class`, 25) WHERE `attach`.`backend-class` LIKE 'Friendica\\\Model\\\Storage\\\%' ESCAPE '|'")) {
409 return Update::FAILED;
412 return Update::SUCCESS;
415 function update_1332()
417 $condition = ["`is-default` IS NOT NULL"];
418 $profiles = DBA::select('profile', [], $condition);
420 while ($profile = DBA::fetch($profiles)) {
421 DI::profileField()->migrateFromLegacyProfile($profile);
423 DBA::close($profiles);
425 DBA::update('contact', ['profile-id' => null], ['`profile-id` IS NOT NULL']);
427 return Update::SUCCESS;
430 function update_1347()
432 foreach (Item::ACTIVITIES as $index => $activity) {
433 DBA::insert('verb', ['id' => $index + 1, 'name' => $activity], Database::INSERT_IGNORE);
436 return Update::SUCCESS;
439 function pre_update_1348()
441 if (!DBA::exists('contact', ['id' => 0])) {
442 DBA::insert('contact', ['nurl' => '']);
443 $lastid = DBA::lastInsertId();
445 DBA::update('contact', ['id' => 0], ['id' => $lastid]);
449 // The tables "permissionset" and "tag" could or could not exist during the update.
450 // This depends upon the previous version. Depending upon this situation we have to add
451 // the "0" values before adding the foreign keys - or after would be sufficient.
455 DBA::e("DELETE FROM `auth_codes` WHERE NOT `client_id` IN (SELECT `client_id` FROM `clients`)");
456 DBA::e("DELETE FROM `tokens` WHERE NOT `client_id` IN (SELECT `client_id` FROM `clients`)");
458 return Update::SUCCESS;
461 function update_1348()
463 // Insert a permissionset with id=0
464 // Inserting it without an ID and then changing the value to 0 tricks the auto increment
465 if (!DBA::exists('permissionset', ['id' => 0])) {
466 DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']);
467 $lastid = DBA::lastInsertId();
469 DBA::update('permissionset', ['id' => 0], ['id' => $lastid]);
473 if (!DBA::exists('tag', ['id' => 0])) {
474 DBA::insert('tag', ['name' => '']);
475 $lastid = DBA::lastInsertId();
477 DBA::update('tag', ['id' => 0], ['id' => $lastid]);
481 return Update::SUCCESS;
484 function update_1349()
487 foreach (Item::ACTIVITIES as $index => $activity) {
488 if (!DBA::exists('verb', ['id' => $index + 1, 'name' => $activity])) {
494 // The update failed - but it cannot be recovered, since the data doesn't match our expectation
495 // This means that we can't use this "shortcut" to fill the "vid" field and we have to rely upon
496 // the postupdate. This is not fatal, but means that it will take some longer time for the system
498 return Update::SUCCESS;
501 if (!DBA::e("UPDATE `item` INNER JOIN `item-activity` ON `item`.`uri-id` = `item-activity`.`uri-id`
502 SET `vid` = `item-activity`.`activity` + 1 WHERE `gravity` = ? AND (`vid` IS NULL OR `vid` = 0)", GRAVITY_ACTIVITY)) {
503 return Update::FAILED;
506 return Update::SUCCESS;
509 function update_1351()
511 if (!DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id` SET `thread`.`uri-id` = `item`.`uri-id`")) {
512 return Update::FAILED;
515 return Update::SUCCESS;
518 function pre_update_1354()
520 if (DBStructure::existsColumn('contact', ['ffi_keyword_blacklist'])
521 && !DBStructure::existsColumn('contact', ['ffi_keyword_denylist'])
522 && !DBA::e("ALTER TABLE `contact` CHANGE `ffi_keyword_blacklist` `ffi_keyword_denylist` text null")) {
523 return Update::FAILED;
525 return Update::SUCCESS;
528 function update_1354()
530 if (DBStructure::existsColumn('contact', ['ffi_keyword_blacklist'])
531 && DBStructure::existsColumn('contact', ['ffi_keyword_denylist'])) {
532 if (!DBA::e("UPDATE `contact` SET `ffi_keyword_denylist` = `ffi_keyword_blacklist`")) {
533 return Update::FAILED;
536 // When the data had been copied then the main task is done.
537 // Having the old field removed is only beauty but not crucial.
538 // So we don't care if this was successful or not.
539 DBA::e("ALTER TABLE `contact` DROP `ffi_keyword_blacklist`");
541 return Update::SUCCESS;
544 function update_1357()
546 if (!DBA::e("UPDATE `contact` SET `failed` = true WHERE `success_update` < `failure_update` AND `failed` IS NULL")) {
547 return Update::FAILED;
550 if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `success_update` > `failure_update` AND `failed` IS NULL")) {
551 return Update::FAILED;
554 if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `updated` > `failure_update` AND `failed` IS NULL")) {
555 return Update::FAILED;
558 if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `last-item` > `failure_update` AND `failed` IS NULL")) {
559 return Update::FAILED;
562 if (!DBA::e("UPDATE `gserver` SET `failed` = true WHERE `last_contact` < `last_failure` AND `failed` IS NULL")) {
563 return Update::FAILED;
566 if (!DBA::e("UPDATE `gserver` SET `failed` = false WHERE `last_contact` > `last_failure` AND `failed` IS NULL")) {
567 return Update::FAILED;
570 return Update::SUCCESS;
573 function pre_update_1358()
575 if (!DBA::e("DELETE FROM `contact-relation` WHERE NOT `relation-cid` IN (SELECT `id` FROM `contact`) OR NOT `cid` IN (SELECT `id` FROM `contact`)")) {
576 return Update::FAILED;
579 return Update::SUCCESS;
582 function pre_update_1363()
584 Photo::delete(["`contact-id` != ? AND NOT `contact-id` IN (SELECT `id` FROM `contact`)", 0]);
585 return Update::SUCCESS;
588 function pre_update_1364()
590 if (!DBA::e("DELETE FROM `2fa_recovery_codes` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
591 return Update::FAILED;
594 if (!DBA::e("DELETE FROM `2fa_app_specific_password` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
595 return Update::FAILED;
598 if (!DBA::e("DELETE FROM `attach` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
599 return Update::FAILED;
602 if (!DBA::e("DELETE FROM `clients` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
603 return Update::FAILED;
606 if (!DBA::e("DELETE FROM `conv` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
607 return Update::FAILED;
610 if (!DBA::e("DELETE FROM `fsuggest` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
611 return Update::FAILED;
614 if (!DBA::e("DELETE FROM `group` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
615 return Update::FAILED;
618 if (!DBA::e("DELETE FROM `intro` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
619 return Update::FAILED;
622 if (!DBA::e("DELETE FROM `manage` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
623 return Update::FAILED;
626 if (!DBA::e("DELETE FROM `manage` WHERE NOT `mid` IN (SELECT `uid` FROM `user`)")) {
627 return Update::FAILED;
630 if (!DBA::e("DELETE FROM `mail` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
631 return Update::FAILED;
634 if (!DBA::e("DELETE FROM `mailacct` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
635 return Update::FAILED;
638 if (!DBA::e("DELETE FROM `notify` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
639 return Update::FAILED;
642 if (!DBA::e("DELETE FROM `openwebauth-token` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
643 return Update::FAILED;
646 if (!DBA::e("DELETE FROM `pconfig` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
647 return Update::FAILED;
650 if (!DBA::e("DELETE FROM `profile` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
651 return Update::FAILED;
654 if (!DBA::e("DELETE FROM `profile_check` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
655 return Update::FAILED;
658 if (!DBA::e("DELETE FROM `profile_field` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
659 return Update::FAILED;
662 if (!DBA::e("DELETE FROM `push_subscriber` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
663 return Update::FAILED;
666 if (!DBA::e("DELETE FROM `register` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
667 return Update::FAILED;
670 if (!DBA::e("DELETE FROM `search` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
671 return Update::FAILED;
674 if (!DBA::e("DELETE FROM `tokens` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
675 return Update::FAILED;
678 if (!DBA::e("DELETE FROM `user-contact` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
679 return Update::FAILED;
682 if (!DBA::e("DELETE FROM `user-item` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
683 return Update::FAILED;
686 if (!DBA::e("DELETE FROM `notify-threads` WHERE NOT `receiver-uid` IN (SELECT `uid` FROM `user`)")) {
687 return Update::FAILED;
690 if (!DBA::e("DELETE FROM `event` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
691 return Update::FAILED;
694 if (!DBA::e("DELETE FROM `fsuggest` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
695 return Update::FAILED;
698 if (!DBA::e("DELETE FROM `group_member` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
699 return Update::FAILED;
702 if (!DBA::e("DELETE FROM `intro` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
703 return Update::FAILED;
706 if (!DBA::e("DELETE FROM `participation` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
707 return Update::FAILED;
710 if (!DBA::e("DELETE FROM `profile_check` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
711 return Update::FAILED;
714 if (!DBA::e("DELETE FROM `user-contact` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
715 return Update::FAILED;
718 if (!DBA::e("DELETE FROM `participation` WHERE NOT `fid` IN (SELECT `id` FROM `fcontact`)")) {
719 return Update::FAILED;
722 if (!DBA::e("DELETE FROM `group_member` WHERE NOT `gid` IN (SELECT `id` FROM `group`)")) {
723 return Update::FAILED;
726 if (!DBA::e("DELETE FROM `gserver-tag` WHERE NOT `gserver-id` IN (SELECT `id` FROM `gserver`)")) {
727 return Update::FAILED;
730 if (!DBA::e("DELETE FROM `participation` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) {
731 return Update::FAILED;
734 if (!DBA::e("DELETE FROM `user-item` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) {
735 return Update::FAILED;
738 return Update::SUCCESS;
741 function pre_update_1365()
743 if (!DBA::e("DELETE FROM `notify-threads` WHERE NOT `notify-id` IN (SELECT `id` FROM `notify`)")) {
744 return Update::FAILED;
747 if (!DBA::e("DELETE FROM `thread` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) {
748 return Update::FAILED;
751 return Update::SUCCESS;
754 function update_1375()
756 if (!DBA::e("UPDATE `item` SET `thr-parent` = `parent-uri`, `thr-parent-id` = `parent-uri-id` WHERE `thr-parent` = ''")) {
757 return Update::FAILED;
760 return Update::SUCCESS;
763 function pre_update_1376()
765 // Insert a user with uid=0
766 DBStructure::checkInitialValues();
768 if (!DBA::e("DELETE FROM `item` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
769 return Update::FAILED;
772 if (!DBA::e("DELETE FROM `event` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
773 return Update::FAILED;
776 if (!DBA::e("DELETE FROM `thread` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
777 return Update::FAILED;
780 if (!DBA::e("DELETE FROM `permissionset` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
781 return Update::FAILED;
784 if (!DBA::e("DELETE FROM `openwebauth-token` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
785 return Update::FAILED;
788 if (!DBA::e("DELETE FROM `post-category` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
789 return Update::FAILED;
792 Photo::delete(["NOT `uid` IN (SELECT `uid` FROM `user`)"]);
794 if (!DBA::e("DELETE FROM `contact` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
795 return Update::FAILED;
798 return Update::SUCCESS;
801 function pre_update_1377()
803 DBStructure::checkInitialValues();
805 if (!DBA::e("DELETE FROM `item` WHERE NOT `parent` IN (SELECT `id` FROM `item`)")) {
806 return Update::FAILED;
809 if (!DBA::e("DELETE FROM `item` WHERE NOT `author-id` IN (SELECT `id` FROM `contact`)")) {
810 return Update::FAILED;
813 if (!DBA::e("DELETE FROM `item` WHERE NOT `owner-id` IN (SELECT `id` FROM `contact`)")) {
814 return Update::FAILED;
817 if (!DBA::e("UPDATE `item` SET `contact-id` = `owner-id` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
818 return Update::FAILED;
821 if (!DBA::e("DELETE FROM `thread` WHERE NOT `author-id` IN (SELECT `id` FROM `contact`)")) {
822 return Update::FAILED;
825 if (!DBA::e("DELETE FROM `thread` WHERE NOT `owner-id` IN (SELECT `id` FROM `contact`)")) {
826 return Update::FAILED;
829 if (!DBA::e("UPDATE `thread` SET `contact-id` = `owner-id` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
830 return Update::FAILED;
833 if (!DBA::e("UPDATE `notify` SET `uri-id` = NULL WHERE `uri-id` = 0")) {
834 return Update::FAILED;
837 if (!DBA::e("DELETE FROM `notify` WHERE `uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
838 return Update::FAILED;
841 if (!DBA::e("UPDATE `notify` SET `parent-uri-id` = NULL WHERE `parent-uri-id` = 0")) {
842 return Update::FAILED;
845 if (!DBA::e("DELETE FROM `notify` WHERE `parent-uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
846 return Update::FAILED;
849 if (!DBA::e("UPDATE `notify-threads` SET `master-parent-uri-id` = NULL WHERE `master-parent-uri-id` = 0")) {
850 return Update::FAILED;
853 if (!DBA::e("DELETE FROM `notify-threads` WHERE `master-parent-uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
854 return Update::FAILED;
857 if (!DBA::e("DELETE FROM `notify-threads` WHERE `master-parent-item` NOT IN (SELECT `id` FROM `item`)")) {
858 return Update::FAILED;
861 return Update::SUCCESS;