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\Notify;
54 use Friendica\Model\Photo;
55 use Friendica\Model\Post;
56 use Friendica\Model\User;
57 use Friendica\Model\Storage;
58 use Friendica\Util\DateTimeFormat;
59 use Friendica\Worker\Delivery;
61 function update_1179()
63 if (DI::config()->get('system', 'no_community_page')) {
64 DI::config()->set('system', 'community_page_style', CP_NO_COMMUNITY_PAGE);
67 // Update the central item storage with uid=0
68 Worker::add(PRIORITY_LOW, "threadupdate");
70 return Update::SUCCESS;
73 function update_1181()
76 // Fill the new fields in the term table.
77 // deactivated, the "term" table is deprecated
78 // Worker::add(PRIORITY_LOW, "TagUpdate");
80 return Update::SUCCESS;
83 function update_1189()
86 if (strlen(DI::config()->get('system', 'directory_submit_url')) &&
87 !strlen(DI::config()->get('system', 'directory'))) {
88 DI::config()->set('system', 'directory', dirname(DI::config()->get('system', 'directory_submit_url')));
89 DI::config()->delete('system', 'directory_submit_url');
92 return Update::SUCCESS;
95 function update_1191()
97 DI::config()->set('system', 'maintenance', 1);
99 if (Addon::isEnabled('forumlist')) {
100 Addon::uninstall('forumlist');
103 // select old formlist addon entries
104 $r = q("SELECT `uid`, `cat`, `k`, `v` FROM `pconfig` WHERE `cat` = '%s' ",
105 DBA::escape('forumlist')
108 // convert old forumlist addon entries in new config entries
109 if (DBA::isResult($r)) {
110 foreach ($r as $rr) {
112 $family = $rr['cat'];
116 if ($key === 'randomise') {
117 DI::pConfig()->delete($uid, $family, $key);
120 if ($key === 'show_on_profile') {
122 DI::pConfig()->set($uid, 'feature', 'forumlist_profile', $value);
125 DI::pConfig()->delete($uid, $family, $key);
128 if ($key === 'show_on_network') {
130 DI::pConfig()->set($uid, 'feature', 'forumlist_widget', $value);
133 DI::pConfig()->delete($uid, $family, $key);
138 DI::config()->set('system', 'maintenance', 0);
140 return Update::SUCCESS;
143 function update_1203()
145 $r = q("UPDATE `user` SET `account-type` = %d WHERE `page-flags` IN (%d, %d)",
146 DBA::escape(User::ACCOUNT_TYPE_COMMUNITY),
147 DBA::escape(User::PAGE_FLAGS_COMMUNITY),
148 DBA::escape(User::PAGE_FLAGS_PRVGROUP)
152 function update_1244()
154 // Sets legacy_password for all legacy hashes
155 DBA::update('user', ['legacy_password' => true], ['SUBSTR(password, 1, 4) != "$2y$"']);
157 // All legacy hashes are re-hashed using the new secure hashing function
158 $stmt = DBA::select('user', ['uid', 'password'], ['legacy_password' => true]);
159 while ($user = DBA::fetch($stmt)) {
160 DBA::update('user', ['password' => User::hashPassword($user['password'])], ['uid' => $user['uid']]);
163 // Logged in users are forcibly logged out
164 DBA::delete('session', ['1 = 1']);
166 return Update::SUCCESS;
169 function update_1245()
171 $rino = DI::config()->get('system', 'rino_encrypt');
174 return Update::SUCCESS;
177 DI::config()->set('system', 'rino_encrypt', 1);
179 return Update::SUCCESS;
182 function update_1247()
184 // Removing hooks with the old name
185 DBA::e("DELETE FROM `hook`
186 WHERE `hook` LIKE 'plugin_%'");
188 // Make sure we install the new renamed ones
192 function update_1260()
194 DI::config()->set('system', 'maintenance', 1);
197 'maintenance_reason',
199 '%s: Updating author-id and owner-id in item and thread table. ',
200 DateTimeFormat::utcNow().' '.date('e')
204 $items = DBA::p("SELECT `id`, `owner-link`, `owner-name`, `owner-avatar`, `network` FROM `item`
205 WHERE `owner-id` = 0 AND `owner-link` != ''");
206 while ($item = DBA::fetch($items)) {
207 $contact = ['url' => $item['owner-link'], 'name' => $item['owner-name'],
208 'photo' => $item['owner-avatar'], 'network' => $item['network']];
209 $cid = Contact::getIdForURL($item['owner-link'], 0, null, $contact);
213 Item::update(['owner-id' => $cid], ['id' => $item['id']]);
217 DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id`
218 SET `thread`.`owner-id` = `item`.`owner-id` WHERE `thread`.`owner-id` = 0");
220 $items = DBA::p("SELECT `id`, `author-link`, `author-name`, `author-avatar`, `network` FROM `item`
221 WHERE `author-id` = 0 AND `author-link` != ''");
222 while ($item = DBA::fetch($items)) {
223 $contact = ['url' => $item['author-link'], 'name' => $item['author-name'],
224 'photo' => $item['author-avatar'], 'network' => $item['network']];
225 $cid = Contact::getIdForURL($item['author-link'], 0, null, $contact);
229 Item::update(['author-id' => $cid], ['id' => $item['id']]);
233 DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id`
234 SET `thread`.`author-id` = `item`.`author-id` WHERE `thread`.`author-id` = 0");
236 DI::config()->set('system', 'maintenance', 0);
237 return Update::SUCCESS;
240 function update_1261()
242 // This fixes the results of an issue in the develop branch of 2018-05.
243 DBA::update('contact', ['blocked' => false, 'pending' => false], ['uid' => 0, 'blocked' => true, 'pending' => true]);
244 return Update::SUCCESS;
247 function update_1278()
249 DI::config()->set('system', 'maintenance', 1);
252 'maintenance_reason',
254 '%s: Updating post-type.',
255 DateTimeFormat::utcNow().' '.date('e')
259 Item::update(['post-type' => Item::PT_PAGE], ['bookmark' => true]);
260 Item::update(['post-type' => Item::PT_PERSONAL_NOTE], ['type' => 'note']);
262 DI::config()->set('system', 'maintenance', 0);
264 return Update::SUCCESS;
267 function update_1288()
269 // Updates missing `uri-id` values
271 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");
272 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");
274 return Update::SUCCESS;
277 // Post-update script of PR 5751
278 function update_1298()
280 $keys = ['gender', 'marital', 'sexual'];
281 foreach ($keys as $translateKey) {
282 $allData = DBA::select('profile', ['id', $translateKey]);
283 $allLangs = DI::l10n()->getAvailableLanguages();
286 foreach ($allData as $key => $data) {
287 $toTranslate = $data[$translateKey];
288 if ($toTranslate != '') {
289 foreach ($allLangs as $key => $lang) {
290 $a = new \stdClass();
293 // First we get the the localizations
294 if (file_exists("view/lang/$lang/strings.php")) {
295 include "view/lang/$lang/strings.php";
297 if (file_exists("addon/morechoice/lang/$lang/strings.php")) {
298 include "addon/morechoice/lang/$lang/strings.php";
301 $localizedStrings = $a->strings;
304 $key = array_search($toTranslate, $localizedStrings);
305 if ($key !== false) {
309 // defaulting to empty string
316 DBA::update('profile', [$translateKey => $key], ['id' => $data['id']]);
317 Logger::notice('Updated contact', ['action' => 'update', 'contact' => $data['id'], "$translateKey" => $key,
318 'was' => $data[$translateKey]]);
319 Worker::add(PRIORITY_LOW, 'ProfileUpdate', $data['id']);
320 Contact::updateSelfFromUserID($data['id']);
326 Logger::notice($translateKey . " fix completed", ['action' => 'update', 'translateKey' => $translateKey, 'Success' => $success, 'Fail' => $fail ]);
328 return Update::SUCCESS;
331 function update_1309()
333 $queue = DBA::select('queue', ['id', 'cid', 'guid']);
334 while ($entry = DBA::fetch($queue)) {
335 $contact = DBA::selectFirst('contact', ['uid'], ['id' => $entry['cid']]);
336 if (!DBA::isResult($contact)) {
340 $item = Post::selectFirst(['id', 'gravity'], ['uid' => $contact['uid'], 'guid' => $entry['guid']]);
341 if (!DBA::isResult($item)) {
345 $deliver_options = ['priority' => PRIORITY_MEDIUM, 'dont_fork' => true];
346 Worker::add($deliver_options, 'Delivery', Delivery::POST, $item['id'], $entry['cid']);
347 Logger::info('Added delivery worker', ['item' => $item['id'], 'contact' => $entry['cid']]);
348 DBA::delete('queue', ['id' => $entry['id']]);
350 return Update::SUCCESS;
353 function update_1315()
355 if (DBStructure::existsTable('item-delivery-data')) {
356 DBA::delete('item-delivery-data', ['postopts' => '', 'inform' => '', 'queue_count' => 0, 'queue_done' => 0]);
358 return Update::SUCCESS;
361 function update_1318()
363 DBA::update('profile', ['marital' => "In a relation"], ['marital' => "Unavailable"]);
364 DBA::update('profile', ['marital' => "Single"], ['marital' => "Available"]);
366 Worker::add(PRIORITY_LOW, 'ProfileUpdate');
367 return Update::SUCCESS;
370 function update_1323()
372 $users = DBA::select('user', ['uid']);
373 while ($user = DBA::fetch($users)) {
374 Contact::updateSelfFromUserID($user['uid']);
378 return Update::SUCCESS;
381 function update_1327()
383 $contacts = DBA::select('contact', ['uid', 'id', 'blocked', 'readonly'], ["`uid` != ? AND (`blocked` OR `readonly`) AND NOT `pending`", 0]);
384 while ($contact = DBA::fetch($contacts)) {
385 Contact\User::setBlocked($contact['id'], $contact['uid'], $contact['blocked']);
386 Contact\User::setIgnored($contact['id'], $contact['uid'], $contact['readonly']);
388 DBA::close($contacts);
390 return Update::SUCCESS;
393 function update_1330()
395 $currStorage = DI::config()->get('storage', 'class', '');
397 // set the name of the storage instead of the classpath as config
398 if (!empty($currStorage)) {
399 /** @var Storage\IStorage $currStorage */
400 if (!DI::config()->set('storage', 'name', $currStorage::getName())) {
401 return Update::FAILED;
404 // try to delete the class since it isn't needed. This won't work with config files
405 DI::config()->delete('storage', 'class');
408 // Update attachments and photos
409 if (!DBA::p("UPDATE `photo` SET `photo`.`backend-class` = SUBSTR(`photo`.`backend-class`, 25) WHERE `photo`.`backend-class` LIKE 'Friendica\\\Model\\\Storage\\\%' ESCAPE '|'") ||
410 !DBA::p("UPDATE `attach` SET `attach`.`backend-class` = SUBSTR(`attach`.`backend-class`, 25) WHERE `attach`.`backend-class` LIKE 'Friendica\\\Model\\\Storage\\\%' ESCAPE '|'")) {
411 return Update::FAILED;
414 return Update::SUCCESS;
417 function update_1332()
419 $condition = ["`is-default` IS NOT NULL"];
420 $profiles = DBA::select('profile', [], $condition);
422 while ($profile = DBA::fetch($profiles)) {
423 DI::profileField()->migrateFromLegacyProfile($profile);
425 DBA::close($profiles);
427 DBA::update('contact', ['profile-id' => null], ['`profile-id` IS NOT NULL']);
429 return Update::SUCCESS;
432 function update_1347()
434 foreach (Item::ACTIVITIES as $index => $activity) {
435 DBA::insert('verb', ['id' => $index + 1, 'name' => $activity], Database::INSERT_IGNORE);
438 return Update::SUCCESS;
441 function pre_update_1348()
443 if (!DBA::exists('contact', ['id' => 0])) {
444 DBA::insert('contact', ['nurl' => '']);
445 $lastid = DBA::lastInsertId();
447 DBA::update('contact', ['id' => 0], ['id' => $lastid]);
451 // The tables "permissionset" and "tag" could or could not exist during the update.
452 // This depends upon the previous version. Depending upon this situation we have to add
453 // the "0" values before adding the foreign keys - or after would be sufficient.
457 DBA::e("DELETE FROM `auth_codes` WHERE NOT `client_id` IN (SELECT `client_id` FROM `clients`)");
458 DBA::e("DELETE FROM `tokens` WHERE NOT `client_id` IN (SELECT `client_id` FROM `clients`)");
460 return Update::SUCCESS;
463 function update_1348()
465 // Insert a permissionset with id=0
466 // Inserting it without an ID and then changing the value to 0 tricks the auto increment
467 if (!DBA::exists('permissionset', ['id' => 0])) {
468 DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']);
469 $lastid = DBA::lastInsertId();
471 DBA::update('permissionset', ['id' => 0], ['id' => $lastid]);
475 if (!DBA::exists('tag', ['id' => 0])) {
476 DBA::insert('tag', ['name' => '']);
477 $lastid = DBA::lastInsertId();
479 DBA::update('tag', ['id' => 0], ['id' => $lastid]);
483 return Update::SUCCESS;
486 function update_1349()
489 foreach (Item::ACTIVITIES as $index => $activity) {
490 if (!DBA::exists('verb', ['id' => $index + 1, 'name' => $activity])) {
496 // The update failed - but it cannot be recovered, since the data doesn't match our expectation
497 // This means that we can't use this "shortcut" to fill the "vid" field and we have to rely upon
498 // the postupdate. This is not fatal, but means that it will take some longer time for the system
500 return Update::SUCCESS;
503 if (!DBA::e("UPDATE `item` INNER JOIN `item-activity` ON `item`.`uri-id` = `item-activity`.`uri-id`
504 SET `vid` = `item-activity`.`activity` + 1 WHERE `gravity` = ? AND (`vid` IS NULL OR `vid` = 0)", GRAVITY_ACTIVITY)) {
505 return Update::FAILED;
508 return Update::SUCCESS;
511 function update_1351()
513 if (!DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id` SET `thread`.`uri-id` = `item`.`uri-id`")) {
514 return Update::FAILED;
517 return Update::SUCCESS;
520 function pre_update_1354()
522 if (DBStructure::existsColumn('contact', ['ffi_keyword_blacklist'])
523 && !DBStructure::existsColumn('contact', ['ffi_keyword_denylist'])
524 && !DBA::e("ALTER TABLE `contact` CHANGE `ffi_keyword_blacklist` `ffi_keyword_denylist` text null")) {
525 return Update::FAILED;
527 return Update::SUCCESS;
530 function update_1354()
532 if (DBStructure::existsColumn('contact', ['ffi_keyword_blacklist'])
533 && DBStructure::existsColumn('contact', ['ffi_keyword_denylist'])) {
534 if (!DBA::e("UPDATE `contact` SET `ffi_keyword_denylist` = `ffi_keyword_blacklist`")) {
535 return Update::FAILED;
538 // When the data had been copied then the main task is done.
539 // Having the old field removed is only beauty but not crucial.
540 // So we don't care if this was successful or not.
541 DBA::e("ALTER TABLE `contact` DROP `ffi_keyword_blacklist`");
543 return Update::SUCCESS;
546 function update_1357()
548 if (!DBA::e("UPDATE `contact` SET `failed` = true WHERE `success_update` < `failure_update` AND `failed` IS NULL")) {
549 return Update::FAILED;
552 if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `success_update` > `failure_update` AND `failed` IS NULL")) {
553 return Update::FAILED;
556 if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `updated` > `failure_update` AND `failed` IS NULL")) {
557 return Update::FAILED;
560 if (!DBA::e("UPDATE `contact` SET `failed` = false WHERE `last-item` > `failure_update` AND `failed` IS NULL")) {
561 return Update::FAILED;
564 if (!DBA::e("UPDATE `gserver` SET `failed` = true WHERE `last_contact` < `last_failure` AND `failed` IS NULL")) {
565 return Update::FAILED;
568 if (!DBA::e("UPDATE `gserver` SET `failed` = false WHERE `last_contact` > `last_failure` AND `failed` IS NULL")) {
569 return Update::FAILED;
572 return Update::SUCCESS;
575 function pre_update_1358()
577 if (!DBA::e("DELETE FROM `contact-relation` WHERE NOT `relation-cid` IN (SELECT `id` FROM `contact`) OR NOT `cid` IN (SELECT `id` FROM `contact`)")) {
578 return Update::FAILED;
581 return Update::SUCCESS;
584 function pre_update_1363()
586 Photo::delete(["`contact-id` != ? AND NOT `contact-id` IN (SELECT `id` FROM `contact`)", 0]);
587 return Update::SUCCESS;
590 function pre_update_1364()
592 if (!DBA::e("DELETE FROM `2fa_recovery_codes` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
593 return Update::FAILED;
596 if (!DBA::e("DELETE FROM `2fa_app_specific_password` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
597 return Update::FAILED;
600 if (!DBA::e("DELETE FROM `attach` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
601 return Update::FAILED;
604 if (!DBA::e("DELETE FROM `clients` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
605 return Update::FAILED;
608 if (!DBA::e("DELETE FROM `conv` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
609 return Update::FAILED;
612 if (!DBA::e("DELETE FROM `fsuggest` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
613 return Update::FAILED;
616 if (!DBA::e("DELETE FROM `group` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
617 return Update::FAILED;
620 if (!DBA::e("DELETE FROM `intro` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
621 return Update::FAILED;
624 if (!DBA::e("DELETE FROM `manage` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
625 return Update::FAILED;
628 if (!DBA::e("DELETE FROM `manage` WHERE NOT `mid` IN (SELECT `uid` FROM `user`)")) {
629 return Update::FAILED;
632 if (!DBA::e("DELETE FROM `mail` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
633 return Update::FAILED;
636 if (!DBA::e("DELETE FROM `mailacct` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
637 return Update::FAILED;
640 if (!DBA::e("DELETE FROM `notify` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
641 return Update::FAILED;
644 if (!DBA::e("DELETE FROM `openwebauth-token` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
645 return Update::FAILED;
648 if (!DBA::e("DELETE FROM `pconfig` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
649 return Update::FAILED;
652 if (!DBA::e("DELETE FROM `profile` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
653 return Update::FAILED;
656 if (!DBA::e("DELETE FROM `profile_check` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
657 return Update::FAILED;
660 if (!DBA::e("DELETE FROM `profile_field` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
661 return Update::FAILED;
664 if (!DBA::e("DELETE FROM `push_subscriber` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
665 return Update::FAILED;
668 if (!DBA::e("DELETE FROM `register` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
669 return Update::FAILED;
672 if (!DBA::e("DELETE FROM `search` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
673 return Update::FAILED;
676 if (!DBA::e("DELETE FROM `tokens` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
677 return Update::FAILED;
680 if (!DBA::e("DELETE FROM `user-contact` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
681 return Update::FAILED;
684 if (!DBA::e("DELETE FROM `user-item` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
685 return Update::FAILED;
688 if (!DBA::e("DELETE FROM `notify-threads` WHERE NOT `receiver-uid` IN (SELECT `uid` FROM `user`)")) {
689 return Update::FAILED;
692 if (!DBA::e("DELETE FROM `event` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
693 return Update::FAILED;
696 if (!DBA::e("DELETE FROM `fsuggest` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
697 return Update::FAILED;
700 if (!DBA::e("DELETE FROM `group_member` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
701 return Update::FAILED;
704 if (!DBA::e("DELETE FROM `intro` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
705 return Update::FAILED;
708 if (!DBA::e("DELETE FROM `participation` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
709 return Update::FAILED;
712 if (!DBA::e("DELETE FROM `profile_check` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
713 return Update::FAILED;
716 if (!DBA::e("DELETE FROM `user-contact` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) {
717 return Update::FAILED;
720 if (!DBA::e("DELETE FROM `participation` WHERE NOT `fid` IN (SELECT `id` FROM `fcontact`)")) {
721 return Update::FAILED;
724 if (!DBA::e("DELETE FROM `group_member` WHERE NOT `gid` IN (SELECT `id` FROM `group`)")) {
725 return Update::FAILED;
728 if (!DBA::e("DELETE FROM `gserver-tag` WHERE NOT `gserver-id` IN (SELECT `id` FROM `gserver`)")) {
729 return Update::FAILED;
732 if (!DBA::e("DELETE FROM `participation` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) {
733 return Update::FAILED;
736 if (!DBA::e("DELETE FROM `user-item` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) {
737 return Update::FAILED;
740 return Update::SUCCESS;
743 function pre_update_1365()
745 if (!DBA::e("DELETE FROM `notify-threads` WHERE NOT `notify-id` IN (SELECT `id` FROM `notify`)")) {
746 return Update::FAILED;
749 if (!DBA::e("DELETE FROM `thread` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) {
750 return Update::FAILED;
753 return Update::SUCCESS;
756 function update_1375()
758 if (!DBA::e("UPDATE `item` SET `thr-parent` = `parent-uri`, `thr-parent-id` = `parent-uri-id` WHERE `thr-parent` = ''")) {
759 return Update::FAILED;
762 return Update::SUCCESS;
765 function pre_update_1376()
767 // Insert a user with uid=0
768 DBStructure::checkInitialValues();
770 if (!DBA::e("DELETE FROM `item` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
771 return Update::FAILED;
774 if (!DBA::e("DELETE FROM `event` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
775 return Update::FAILED;
778 if (!DBA::e("DELETE FROM `thread` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
779 return Update::FAILED;
782 if (!DBA::e("DELETE FROM `permissionset` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
783 return Update::FAILED;
786 if (!DBA::e("DELETE FROM `openwebauth-token` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
787 return Update::FAILED;
790 if (!DBA::e("DELETE FROM `post-category` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
791 return Update::FAILED;
794 Photo::delete(["NOT `uid` IN (SELECT `uid` FROM `user`)"]);
796 if (!DBA::e("DELETE FROM `contact` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) {
797 return Update::FAILED;
800 return Update::SUCCESS;
803 function pre_update_1377()
805 DBStructure::checkInitialValues();
807 if (!DBA::e("DELETE FROM `item` WHERE NOT `author-id` IN (SELECT `id` FROM `contact`)")) {
808 return Update::FAILED;
811 if (!DBA::e("DELETE FROM `item` WHERE NOT `owner-id` IN (SELECT `id` FROM `contact`)")) {
812 return Update::FAILED;
815 if (!DBA::e("UPDATE `item` SET `contact-id` = `owner-id` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
816 return Update::FAILED;
819 if (!DBA::e("DELETE FROM `thread` WHERE NOT `author-id` IN (SELECT `id` FROM `contact`)")) {
820 return Update::FAILED;
823 if (!DBA::e("DELETE FROM `thread` WHERE NOT `owner-id` IN (SELECT `id` FROM `contact`)")) {
824 return Update::FAILED;
827 if (!DBA::e("UPDATE `thread` SET `contact-id` = `owner-id` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) {
828 return Update::FAILED;
831 if (!DBA::e("UPDATE `notify` SET `uri-id` = NULL WHERE `uri-id` = 0")) {
832 return Update::FAILED;
835 if (DBStructure::existsTable('diaspora-interaction') && !DBA::e("DELETE FROM `diaspora-interaction` WHERE `uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
836 return Update::FAILED;
839 if (DBStructure::existsTable('item-activity') && !DBA::e("DELETE FROM `item-activity` WHERE `uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
840 return Update::FAILED;
843 if (DBStructure::existsTable('item-content') && !DBA::e("DELETE FROM `item-content` WHERE `uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
844 return Update::FAILED;
847 if (!DBA::e("DELETE FROM `notify` WHERE `uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
848 return Update::FAILED;
851 if (!DBA::e("UPDATE `notify` SET `parent-uri-id` = NULL WHERE `parent-uri-id` = 0")) {
852 return Update::FAILED;
854 if (!DBA::e("DELETE FROM `notify` WHERE `parent-uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
855 return Update::FAILED;
858 if (!DBA::e("UPDATE `notify-threads` SET `master-parent-uri-id` = NULL WHERE `master-parent-uri-id` = 0")) {
859 return Update::FAILED;
862 if (!DBA::e("DELETE FROM `notify-threads` WHERE `master-parent-uri-id` NOT IN (SELECT `id` FROM `item-uri`)")) {
863 return Update::FAILED;
866 if (!DBA::e("DELETE FROM `notify-threads` WHERE `master-parent-item` NOT IN (SELECT `id` FROM `item`)")) {
867 return Update::FAILED;
870 return Update::SUCCESS;
873 function update_1380()
875 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 (?, ?)",
876 Notify\ObjectType::ITEM, Notify\ObjectType::PERSON)) {
877 return Update::FAILED;
880 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 (?, ?)",
881 Notify\ObjectType::ITEM, Notify\ObjectType::PERSON)) {
882 return Update::FAILED;
885 return Update::SUCCESS;