]> git.mxchange.org Git - friendica.git/commitdiff
Post update function to set the "external-id"
authorMichael <heluecht@pirati.ca>
Sun, 14 Feb 2021 21:57:02 +0000 (21:57 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 14 Feb 2021 21:57:02 +0000 (21:57 +0000)
src/Database/PostUpdate.php

index a58281e48b3ed62aadaf07c782df16e857d44355..f36ae4f62b31b8d6f8ac7c1956163ff68fbafb75 100644 (file)
@@ -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;
+       }
 }