]> git.mxchange.org Git - friendica.git/blobdiff - src/Database/PostUpdate.php
Detection of local requests
[friendica.git] / src / Database / PostUpdate.php
index f36ae4f62b31b8d6f8ac7c1956163ff68fbafb75..aa657b0233d9d818167887aa08c26646d9207943 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -45,7 +45,8 @@ class PostUpdate
 {
        // Needed for the helper function to read from the legacy term table
        const OBJECT_TYPE_POST  = 1;
-       const VERSION = 1384;
+
+       const VERSION = 1427;
 
        /**
         * Calls the post update functions
@@ -91,6 +92,18 @@ class PostUpdate
                if (!self::update1400()) {
                        return false;
                }
+               if (!self::update1424()) {
+                       return false;
+               }
+               if (!self::update1425()) {
+                       return false;
+               }
+               if (!self::update1426()) {
+                       return false;
+               }
+               if (!self::update1427()) {
+                       return false;
+               }
                return true;
        }
 
@@ -740,7 +753,7 @@ class PostUpdate
                Logger::info('Start', ['rest' => DBA::count('photo', $condition)]);
 
                $rows = 0;
-               $photos = DBA::select('photo', [], $condition, ['limit' => 10000]);
+               $photos = DBA::select('photo', [], $condition, ['limit' => 100]);
 
                if (DBA::errorNo() != 0) {
                        Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
@@ -771,7 +784,7 @@ class PostUpdate
        }
 
        /**
-        * update the "hash" field in the photo table
+        * update the "external-id" field in the post table
         *
         * @return bool "true" when the job is done
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
@@ -784,6 +797,11 @@ class PostUpdate
                        return true;
                }
 
+               if (!DBStructure::existsTable('item')) {
+                       DI::config()->set("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)]);
 
@@ -804,7 +822,190 @@ class PostUpdate
                Logger::info('Processed', ['rows' => $rows]);
 
                if ($rows <= 100) {
-                       DI::config()->set("system", "post_update_version", 1384);
+                       DI::config()->set("system", "post_update_version", 1400);
+                       Logger::info('Done');
+                       return true;
+               }
+
+               return false;
+       }
+
+       /**
+        * update the "uri-id" field in the contact table
+        *
+        * @return bool "true" when the job is done
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       private static function update1424()
+       {
+               // Was the script completed?
+               if (DI::config()->get("system", "post_update_version") >= 1424) {
+                       return true;
+               }
+
+               $condition = ["`uri-id` IS NULL"];
+               Logger::info('Start', ['rest' => DBA::count('contact', $condition)]);
+
+               $rows = 0;
+               $contacts = DBA::select('contact', ['id', 'url'], $condition, ['limit' => 1000]);
+
+               if (DBA::errorNo() != 0) {
+                       Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
+                       return false;
+               }
+
+               while ($contact = DBA::fetch($contacts)) {
+                       DBA::update('contact', ['uri-id' => ItemURI::getIdByURI($contact['url'])], ['id' => $contact['id']]);
+                       ++$rows;
+               }
+               DBA::close($contacts);
+
+               Logger::info('Processed', ['rows' => $rows]);
+
+               if ($rows <= 100) {
+                       DI::config()->set("system", "post_update_version", 1424);
+                       Logger::info('Done');
+                       return true;
+               }
+
+               return false;
+       }
+
+       /**
+        * update the "uri-id" field in the fcontact table
+        *
+        * @return bool "true" when the job is done
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       private static function update1425()
+       {
+               // Was the script completed?
+               if (DI::config()->get("system", "post_update_version") >= 1425) {
+                       return true;
+               }
+
+               $condition = ["`uri-id` IS NULL"];
+               Logger::info('Start', ['rest' => DBA::count('fcontact', $condition)]);
+
+               $rows = 0;
+               $fcontacts = DBA::select('fcontact', ['id', 'url', 'guid'], $condition, ['limit' => 1000]);
+
+               if (DBA::errorNo() != 0) {
+                       Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
+                       return false;
+               }
+
+               while ($fcontact = DBA::fetch($fcontacts)) {
+                       if (!empty($fcontact['guid'])) {
+                               $uriid = ItemURI::insert(['uri' => $fcontact['url'], 'guid' => $fcontact['guid']]);
+                       } else {
+                               $uriid = ItemURI::getIdByURI($fcontact['url']);
+                       }
+                       DBA::update('fcontact', ['uri-id' => $uriid], ['id' => $fcontact['id']]);
+                       ++$rows;
+               }
+               DBA::close($fcontacts);
+
+               Logger::info('Processed', ['rows' => $rows]);
+
+               if ($rows <= 100) {
+                       DI::config()->set("system", "post_update_version", 1425);
+                       Logger::info('Done');
+                       return true;
+               }
+
+               return false;
+       }
+
+       /**
+        * update the "uri-id" field in the apcontact table
+        *
+        * @return bool "true" when the job is done
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       private static function update1426()
+       {
+               // Was the script completed?
+               if (DI::config()->get("system", "post_update_version") >= 1426) {
+                       return true;
+               }
+
+               $condition = ["`uri-id` IS NULL"];
+               Logger::info('Start', ['rest' => DBA::count('apcontact', $condition)]);
+
+               $rows = 0;
+               $apcontacts = DBA::select('apcontact', ['url', 'uuid'], $condition, ['limit' => 1000]);
+
+               if (DBA::errorNo() != 0) {
+                       Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
+                       return false;
+               }
+
+               while ($apcontact = DBA::fetch($apcontacts)) {
+                       if (!empty($apcontact['uuid'])) {
+                               $uriid = ItemURI::insert(['uri' => $apcontact['url'], 'guid' => $apcontact['uuid']]);
+                       } else {
+                               $uriid = ItemURI::getIdByURI($apcontact['url']);
+                       }
+                       DBA::update('apcontact', ['uri-id' => $uriid], ['url' => $apcontact['url']]);
+                       ++$rows;
+               }
+               DBA::close($apcontacts);
+
+               Logger::info('Processed', ['rows' => $rows]);
+
+               if ($rows <= 100) {
+                       DI::config()->set("system", "post_update_version", 1426);
+                       Logger::info('Done');
+                       return true;
+               }
+
+               return false;
+       }
+
+       /**
+        * update the "uri-id" field in the event table
+        *
+        * @return bool "true" when the job is done
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       private static function update1427()
+       {
+               // Was the script completed?
+               if (DI::config()->get("system", "post_update_version") >= 1427) {
+                       return true;
+               }
+
+               $condition = ["`uri-id` IS NULL"];
+               Logger::info('Start', ['rest' => DBA::count('event', $condition)]);
+
+               $rows = 0;
+               $events = DBA::select('event', ['id', 'uri', 'guid'], $condition, ['limit' => 1000]);
+
+               if (DBA::errorNo() != 0) {
+                       Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
+                       return false;
+               }
+
+               while ($event = DBA::fetch($events)) {
+                       if (!empty($event['guid'])) {
+                               $uriid = ItemURI::insert(['uri' => $event['uri'], 'guid' => $event['guid']]);
+                       } else {
+                               $uriid = ItemURI::getIdByURI($event['uri']);
+                       }
+                       DBA::update('event', ['uri-id' => $uriid], ['id' => $event['id']]);
+                       ++$rows;
+               }
+               DBA::close($events);
+
+               Logger::info('Processed', ['rows' => $rows]);
+
+               if ($rows <= 100) {
+                       DI::config()->set("system", "post_update_version", 1427);
                        Logger::info('Done');
                        return true;
                }