From 896e58347d81532adf51c4f2835a967a764368e9 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 14 Feb 2021 21:57:02 +0000 Subject: [PATCH] Post update function to set the "external-id" --- src/Database/PostUpdate.php | 47 ++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index a58281e48..f36ae4f62 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -27,6 +27,7 @@ use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\GServer; use Friendica\Model\Item; +use Friendica\Model\ItemURI; use Friendica\Model\Photo; use Friendica\Model\Post; use Friendica\Model\Post\Category; @@ -87,7 +88,9 @@ class PostUpdate if (!self::update1384()) { return false; } - + if (!self::update1400()) { + return false; + } return true; } @@ -766,4 +769,46 @@ class PostUpdate return false; } + + /** + * update the "hash" field in the photo table + * + * @return bool "true" when the job is done + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \ImagickException + */ + private static function update1400() + { + // Was the script completed? + if (DI::config()->get("system", "post_update_version") >= 1400) { + return true; + } + + $condition = ["`extid` != ? AND EXISTS(SELECT `id` FROM `post-user` WHERE `uri-id` = `item`.`uri-id` AND `uid` = `item`.`uid` AND `external-id` IS NULL)", '']; + Logger::info('Start', ['rest' => DBA::count('item', $condition)]); + + $rows = 0; + $items = DBA::select('item', ['uri-id', 'uid', 'extid'], $condition, ['order' => ['id'], 'limit' => 10000]); + + if (DBA::errorNo() != 0) { + Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]); + return false; + } + + while ($item = DBA::fetch($items)) { + Post::update(['external-id' => ItemURI::getIdByURI($item['extid'])], ['uri-id' => $item['uri-id'], 'uid' => $item['uid']]); + ++$rows; + } + DBA::close($items); + + Logger::info('Processed', ['rows' => $rows]); + + if ($rows <= 100) { + DI::config()->set("system", "post_update_version", 1384); + Logger::info('Done'); + return true; + } + + return false; + } }