]> git.mxchange.org Git - friendica.git/blobdiff - src/Database/PostUpdate.php
Make Storage testable & add tests
[friendica.git] / src / Database / PostUpdate.php
index 885c9eea013d3b81a66999dc235fcc74ed52fa2c..f0050e0ef353f3b0298c87d2d896cdf0876b2169 100644 (file)
@@ -10,6 +10,7 @@ use Friendica\Core\Protocol;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\ItemURI;
+use Friendica\Model\UserItem;
 use Friendica\Model\PermissionSet;
 
 /**
@@ -40,6 +41,9 @@ class PostUpdate
                if (!self::update1322()) {
                        return false;
                }
+               if (!self::update1329()) {
+                       return false;
+               }
 
                return true;
        }
@@ -453,4 +457,54 @@ class PostUpdate
 
                return true;
        }
+
+       /**
+        * @brief update user-item data with notifications
+        *
+        * @return bool "true" when the job is done
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        */
+       private static function update1329()
+       {
+               // Was the script completed?
+               if (Config::get('system', 'post_update_version') >= 1329) {
+                       return true;
+               }
+
+               $id = Config::get('system', 'post_update_version_1329_id', 0);
+
+               Logger::info('Start', ['item' => $id]);
+
+               $start_id = $id;
+               $rows = 0;
+               $condition = ["`id` > ?", $id];
+               $params = ['order' => ['id'], 'limit' => 10000];
+               $items = DBA::select('item', ['id'], $condition, $params);
+
+               if (DBA::errorNo() != 0) {
+                       Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
+                       return false;
+               }
+
+               while ($item = DBA::fetch($items)) {
+                       $id = $item['id'];
+
+                       UserItem::setNotification($item['id']);
+
+                       ++$rows;
+               }
+               DBA::close($items);
+
+               Config::set('system', 'post_update_version_1329_id', $id);
+
+               Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
+
+               if ($start_id == $id) {
+                       Config::set('system', 'post_update_version', 1329);
+                       Logger::info('Done');
+                       return true;
+               }
+
+               return false;
+       }
 }