]> git.mxchange.org Git - friendica.git/commitdiff
Issue 11893: Postupdate to fix wrong parents
authorMichael <heluecht@pirati.ca>
Tue, 6 Sep 2022 20:00:06 +0000 (20:00 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 6 Sep 2022 20:00:06 +0000 (20:00 +0000)
src/Database/PostUpdate.php
src/Model/Item.php

index 26eef2c94f9b291bddcd428ecfd21b40b7131062..91f5301e17f19525472ecfccd5ecac86b988373e 100644 (file)
@@ -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;
+       }
 }
index 78bc8c64d18b26410117ba65d0546db74ebb32e8..79fe4c02ee6f01da6d1e1b1070051b9ebf944c12 100644 (file)
@@ -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
         *