From ec8377a8c7b519dfbd0a5f18a94f52381b7e9340 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 6 Sep 2022 20:00:06 +0000 Subject: [PATCH 1/3] Issue 11893: Postupdate to fix wrong parents --- src/Database/PostUpdate.php | 36 ++++++++++++++++++++++++++++++++++++ src/Model/Item.php | 20 ++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index 26eef2c94f..91f5301e17 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -111,6 +111,9 @@ class PostUpdate if (!self::update1452()) { return false; } + if (!self::update1483()) { + return false; + } return true; } @@ -1085,4 +1088,37 @@ class PostUpdate return false; } + + /** + * Correct the parent. + * This fixes a bug that was introduced in the development of version 2022.09 + * + * @return bool "true" when the job is done + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \ImagickException + */ + public static function update1483() + { + // Was the script completed? + if (DI::config()->get('system', 'post_update_version') >= 1483) { + return true; + } + + Logger::info('Start'); + + $posts = DBA::select('post-view', ['uri-id'], ['conversation' => './']); + while ($post = DBA::fetch($posts)) { + echo $post['uri-id'] . "\n"; + $parent = Item::getParent($post['uri-id']); + if ($parent != 0) { + DBA::update('post', ['parent-uri-id' => $parent], ['uri-id' => $post['uri-id']]); + DBA::update('post-user', ['parent-uri-id' => $parent], ['uri-id' => $post['uri-id']]); + } + } + DBA::close($posts); + + DI::config()->set('system', 'post_update_version', 1483); + Logger::info('Done'); + return true; + } } diff --git a/src/Model/Item.php b/src/Model/Item.php index 78bc8c64d1..79fe4c02ee 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -701,6 +701,26 @@ class Item return 0; } + /** + * Fetch the uri-id of the parent for the given uri-id + * + * @param integer $uriid + * @return integer + */ + public static function getParent(int $uriid): int + { + $thread_parent = Post::selectFirstPost(['thr-parent-id', 'gravity'], ['uri-id' => $uriid]); + if (empty($thread_parent)) { + return 0; + } + + if ($thread_parent['gravity'] == GRAVITY_PARENT) { + return $uriid; + } + + return self::getParent($thread_parent['thr-parent-id']); + } + /** * Fetch top-level parent data for the given item array * From d7212cbbbcf3f92e6d2935b3b4c596016b8f167d Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 6 Sep 2022 20:47:18 +0000 Subject: [PATCH 2/3] Function only needn't to be public --- src/Database/PostUpdate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index 91f5301e17..3ec7822bf0 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -1097,7 +1097,7 @@ class PostUpdate * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function update1483() + private static function update1483() { // Was the script completed? if (DI::config()->get('system', 'post_update_version') >= 1483) { From 0121c2845ae4228a68c389f54b4884f7e6a02497 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 6 Sep 2022 22:56:56 +0000 Subject: [PATCH 3/3] Test stuff removed --- src/Database/PostUpdate.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index 3ec7822bf0..9216d800da 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -1108,7 +1108,6 @@ class PostUpdate $posts = DBA::select('post-view', ['uri-id'], ['conversation' => './']); while ($post = DBA::fetch($posts)) { - echo $post['uri-id'] . "\n"; $parent = Item::getParent($post['uri-id']); if ($parent != 0) { DBA::update('post', ['parent-uri-id' => $parent], ['uri-id' => $post['uri-id']]);