]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Post/Delivery.php
Merge pull request #12298 from annando/api-suggestions
[friendica.git] / src / Model / Post / Delivery.php
index 8d19f8c941136c319894e9dcfd96472a884f7e90..f8ed068fe8e128f089f75c04fc172933ae43cdf7 100644 (file)
@@ -35,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);
        }
@@ -81,6 +83,18 @@ class Delivery
 
        public static function selectForInbox(string $inbox)
        {
-               return DBA::selectToArray('post-delivery', [], ['inbox-id' => ItemURI::getIdByURI($inbox)], ['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;
        }
 }