X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FDatabase%2FPostUpdate.php;h=62b023fb6fdd6c09fe86d44bb2b933db30e3b3df;hb=38cf0666bd7a6537a5a6af19b5bd6073ef12e82f;hp=9216d800da42f643860b872c17b24df27aa099c8;hpb=7da43fe28a90db0fa52d5653d67b41000e8c0598;p=friendica.git diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index 9216d800da..62b023fb6f 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -50,7 +50,7 @@ class PostUpdate // Needed for the helper function to read from the legacy term table const OBJECT_TYPE_POST = 1; - const VERSION = 1452; + const VERSION = 1484; /** * Calls the post update functions @@ -114,6 +114,9 @@ class PostUpdate if (!self::update1483()) { return false; } + if (!self::update1484()) { + return false; + } return true; } @@ -1120,4 +1123,55 @@ class PostUpdate Logger::info('Done'); return true; } + + /** + * Handle duplicate contact entries + * + * @return bool "true" when the job is done + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \ImagickException + */ + private static function update1484() + { + // Was the script completed? + if (DI::config()->get('system', 'post_update_version') >= 1484) { + return true; + } + + $id = DI::config()->get('system', 'post_update_version_1484_id', 0); + + Logger::info('Start', ['id' => $id]); + + $rows = 0; + + $contacts = DBA::select('contact', ['id', 'uid', 'uri-id', 'url'], ["`id` > ?", $id], ['order' => ['id'], 'limit' => 1000]); + + if (DBA::errorNo() != 0) { + Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]); + return false; + } + + while ($contact = DBA::fetch($contacts)) { + $id = $contact['id']; + if (is_null($contact['uri-id'])) { + $contact['uri-id'] = ItemURI::getIdByURI($contact['url']); + DBA::update('contact', ['uri-id' => $contact['uri-id']], ['id' => $contact['id']]); + } + Contact::setAccountUser($contact['id'], $contact['uid'], $contact['uri-id'], $contact['url']); + ++$rows; + } + DBA::close($contacts); + + DI::config()->set('system', 'post_update_version_1484_id', $id); + + Logger::info('Processed', ['rows' => $rows, 'last' => $id]); + + if ($rows <= 100) { + DI::config()->set('system', 'post_update_version', 1484); + Logger::info('Done'); + return true; + } + + return false; + } }