]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Post/Delivery.php
Merge pull request #12305 from MrPetovan/bug/notices
[friendica.git] / src / Model / Post / Delivery.php
index 9ccfdc15a6bdd24888c9d756f38a0216db8cf8fd..f8ed068fe8e128f089f75c04fc172933ae43cdf7 100644 (file)
@@ -24,6 +24,7 @@ namespace Friendica\Model\Post;
 use Friendica\Database\DBA;
 use BadMethodCallException;
 use Friendica\Database\Database;
+use Friendica\DI;
 use Friendica\Model\ItemURI;
 
 class Delivery
@@ -34,14 +35,16 @@ class Delivery
         * @param integer $uri_id
         * @param string  $inbox
         * @param string  $created
+        * @param array   %receivers
         */
-       public static function add(int $uri_id, int $uid, string $inbox, string $created, string $command)
+       public static function add(int $uri_id, int $uid, string $inbox, string $created, string $command, array $receivers)
        {
                if (empty($uri_id)) {
                        throw new BadMethodCallException('Empty URI_id');
                }
 
-               $fields = ['uri-id' => $uri_id, 'uid' => $uid, 'inbox-id' => ItemURI::getIdByURI($inbox), 'created' => $created, 'command' => $command];
+               $fields = ['uri-id' => $uri_id, 'uid' => $uid, 'inbox-id' => ItemURI::getIdByURI($inbox),
+                       'created' => $created, 'command' => $command, 'receivers' => json_encode($receivers)];
 
                DBA::insert('post-delivery', $fields, Database::INSERT_IGNORE);
        }
@@ -57,6 +60,16 @@ class Delivery
                DBA::delete('post-delivery', ['uri-id' => $uri_id, 'inbox-id' => ItemURI::getIdByURI($inbox)]);
        }
 
+       /**
+        * Remove failed posts for an inbox
+        *
+        * @param string  $inbox
+        */
+       public static function removeFailed(string $inbox)
+       {
+               DBA::delete('post-delivery', ["`inbox-id` = ? AND `failed` >= ?", ItemURI::getIdByURI($inbox), DI::config()->get('system', 'worker_defer_limit')]);
+       }
+
        /**
         * Increment "failed" counter for the given inbox and post
         *
@@ -70,6 +83,18 @@ class Delivery
 
        public static function selectForInbox(string $inbox)
        {
-               return DBA::selectToArray('post-delivery', [], ["`inbox-id` = ? AND `failed` < ?", ItemURI::getIdByURI($inbox), 15], ['order' => ['created']]);
+               $rows = DBA::select('post-delivery', [], ["`inbox-id` = ? AND `failed` < ?", ItemURI::getIdByURI($inbox), DI::config()->get('system', 'worker_defer_limit')], ['order' => ['created']]);
+               $deliveries = [];
+               while ($row = DBA::fetch($rows)) {
+                       if (!empty($row['receivers'])) {
+                               $row['receivers'] = json_decode($row['receivers'], true);
+                       } else {
+                               $row['receivers'] = [];
+                       }
+                       $deliveries[] = $row;
+               }
+               DBA::close($rows);
+
+               return $deliveries;
        }
 }