]> git.mxchange.org Git - friendica.git/commitdiff
"item-delivery-data" is now "post-delivery-data"
authorMichael <heluecht@pirati.ca>
Sat, 2 May 2020 19:34:02 +0000 (19:34 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 2 May 2020 19:34:02 +0000 (19:34 +0000)
database.sql
src/Model/Item.php
src/Model/ItemDeliveryData.php [deleted file]
src/Model/Post/DeliveryData.php [new file with mode: 0644]
src/Protocol/Diaspora.php
src/Worker/APDelivery.php
src/Worker/Delivery.php
src/Worker/Notifier.php
static/dbstructure.config.php

index a68f3d4e5a2398b865598350f5120cf8bfefcc84..320ef38e77177b2f0355a56f8c85ed7f4b1cdf2c 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2020.06-dev (Red Hot Poker)
--- DB_UPDATE_VERSION 1341
+-- DB_UPDATE_VERSION 1343
 -- ------------------------------------------
 
 
@@ -666,7 +666,8 @@ CREATE TABLE IF NOT EXISTS `item` (
         INDEX `uid_eventid` (`uid`,`event-id`),
         INDEX `icid` (`icid`),
         INDEX `iaid` (`iaid`),
-        INDEX `psid_wall` (`psid`,`wall`)
+        INDEX `psid_wall` (`psid`,`wall`),
+        INDEX `uri-id` (`uri-id`)
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts';
 
 --
@@ -714,24 +715,6 @@ CREATE TABLE IF NOT EXISTS `item-content` (
         INDEX `uri-id` (`uri-id`)
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
 
---
--- TABLE item-delivery-data
---
-CREATE TABLE IF NOT EXISTS `item-delivery-data` (
-       `iid` int unsigned NOT NULL COMMENT 'Item id',
-       `postopts` text COMMENT 'External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery',
-       `inform` mediumtext COMMENT 'Additional receivers of the linked item',
-       `queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
-       `queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
-       `queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
-       `activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
-       `dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
-       `legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
-       `diaspora` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via Diaspora',
-       `ostatus` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via OStatus',
-        PRIMARY KEY(`iid`)
-) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
-
 --
 -- TABLE item-uri
 --
@@ -1187,6 +1170,24 @@ CREATE TABLE IF NOT EXISTS `tag` (
         INDEX `url` (`url`)
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='tags and mentions';
 
+--
+-- TABLE post-delivery-data
+--
+CREATE TABLE IF NOT EXISTS `post-delivery-data` (
+       `uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
+       `postopts` text COMMENT 'External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery',
+       `inform` mediumtext COMMENT 'Additional receivers of the linked item',
+       `queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count',
+       `queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done',
+       `queue_failed` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of unsuccessful deliveries, used as item.delivery_queue_failed',
+       `activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub',
+       `dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN',
+       `legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN',
+       `diaspora` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via Diaspora',
+       `ostatus` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via OStatus',
+        PRIMARY KEY(`uri-id`)
+) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
+
 --
 -- TABLE post-tag
 --
@@ -1577,6 +1578,27 @@ CREATE VIEW `pending-view` AS SELECT
                        INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
                        INNER JOIN `user` ON `register`.`uid` = `user`.`uid`;
 
+--
+-- VIEW tag-search-view
+--
+DROP VIEW IF EXISTS `tag-search-view`;
+CREATE VIEW `tag-search-view` AS SELECT 
+       `post-tag`.`uri-id` AS `uri-id`,
+       `item`.`id` AS `iid`,
+       `item`.`uri` AS `uri`,
+       `item`.`guid` AS `guid`,
+       `item`.`uid` AS `uid`,
+       `item`.`private` AS `private`,
+       `item`.`wall` AS `wall`,
+       `item`.`origin` AS `origin`,
+       `item`.`gravity` AS `gravity`,
+       `item`.`received` AS `received`,
+       `tag`.`name` AS `name`
+       FROM `post-tag`
+                       INNER JOIN `tag` ON `tag`.`id` = `post-tag`.`tid`
+                       INNER JOIN `item` ON `item`.`uri-id` = `post-tag`.`uri-id`
+                       WHERE `post-tag`.`type` = 1;
+
 --
 -- VIEW workerqueue-view
 --
index 1096c221316bf84fb4283a0d1058056af3707d98..c01535ab652e66972bd098101a0f78af6df77ba6 100644 (file)
@@ -283,7 +283,7 @@ class Item
 
                // Fetch data from the item-content table whenever there is content there
                if (self::isLegacyMode()) {
-                       $legacy_fields = array_merge(ItemDeliveryData::LEGACY_FIELD_LIST, self::MIXED_CONTENT_FIELDLIST);
+                       $legacy_fields = array_merge(Post\DeliveryData::LEGACY_FIELD_LIST, self::MIXED_CONTENT_FIELDLIST);
                        foreach ($legacy_fields as $field) {
                                if (empty($row[$field]) && !empty($row['internal-item-' . $field])) {
                                        $row[$field] = $row['internal-item-' . $field];
@@ -687,7 +687,7 @@ class Item
 
                $fields['item-content'] = array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST);
 
-               $fields['item-delivery-data'] = array_merge(ItemDeliveryData::LEGACY_FIELD_LIST, ItemDeliveryData::FIELD_LIST);
+               $fields['post-delivery-data'] = array_merge(Post\DeliveryData::LEGACY_FIELD_LIST, Post\DeliveryData::FIELD_LIST);
 
                $fields['permissionset'] = ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
 
@@ -809,8 +809,8 @@ class Item
                        $joins .= " LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id`";
                }
 
-               if (strpos($sql_commands, "`item-delivery-data`.") !== false) {
-                       $joins .= " LEFT JOIN `item-delivery-data` ON `item-delivery-data`.`iid` = `item`.`id`";
+               if (strpos($sql_commands, "`post-delivery-data`.") !== false) {
+                       $joins .= " LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `item`.`uri-id` AND `item`.`origin`";
                }
 
                if (strpos($sql_commands, "`permissionset`.") !== false) {
@@ -850,7 +850,7 @@ class Item
                        $selected[] = 'internal-user-ignored';
                }
 
-               $legacy_fields = array_merge(ItemDeliveryData::LEGACY_FIELD_LIST, self::MIXED_CONTENT_FIELDLIST);
+               $legacy_fields = array_merge(Post\DeliveryData::LEGACY_FIELD_LIST, self::MIXED_CONTENT_FIELDLIST);
 
                $selection = [];
                foreach ($fields as $table => $table_fields) {
@@ -936,7 +936,7 @@ class Item
                        }
                }
 
-               $delivery_data = ItemDeliveryData::extractFields($fields);
+               $delivery_data = Post\DeliveryData::extractFields($fields);
 
                $clear_fields = ['bookmark', 'type', 'author-name', 'author-avatar', 'author-link', 'owner-name', 'owner-avatar', 'owner-link', 'postopts', 'inform'];
                foreach ($clear_fields as $field) {
@@ -1038,7 +1038,7 @@ class Item
                                }
                        }
 
-                       ItemDeliveryData::update($item['id'], $delivery_data);
+                       Post\DeliveryData::update($item['uri-id'], $delivery_data);
 
                        self::updateThread($item['id']);
 
@@ -1118,7 +1118,7 @@ class Item
        {
                Logger::info('Mark item for deletion by id', ['id' => $item_id, 'callstack' => System::callstack()]);
                // locate item to be deleted
-               $fields = ['id', 'uri', 'uid', 'parent', 'parent-uri', 'origin',
+               $fields = ['id', 'uri', 'uri-id', 'uid', 'parent', 'parent-uri', 'origin',
                        'deleted', 'file', 'resource-id', 'event-id', 'attach',
                        'verb', 'object-type', 'object', 'target', 'contact-id',
                        'icid', 'iaid', 'psid'];
@@ -1202,7 +1202,7 @@ class Item
                        self::markForDeletion(['uri' => $item['uri'], 'uid' => 0, 'deleted' => false], $priority);
                }
 
-               ItemDeliveryData::delete($item['id']);
+               Post\DeliveryData::delete($item['uri-id']);
 
                // We don't delete the item-activity here, since we need some of the data for ActivityPub
 
@@ -1903,7 +1903,8 @@ class Item
                        self::insertContent($item);
                }
 
-               $delivery_data = ItemDeliveryData::extractFields($item);
+               $postfields = $item;
+               $delivery_data = Post\DeliveryData::extractFields($postfields);
 
                unset($item['postopts']);
                unset($item['inform']);
@@ -2007,7 +2008,7 @@ class Item
                }
 
                if (!empty($item['origin']) || !empty($item['wall']) || !empty($delivery_data['postopts']) || !empty($delivery_data['inform'])) {
-                       ItemDeliveryData::insert($current_post, $delivery_data);
+                       Post\DeliveryData::insert($item['uri-id'], $delivery_data);
                }
 
                DBA::commit();
diff --git a/src/Model/ItemDeliveryData.php b/src/Model/ItemDeliveryData.php
deleted file mode 100644 (file)
index a26c80b..0000000
+++ /dev/null
@@ -1,193 +0,0 @@
-<?php
-/**
- * @copyright Copyright (C) 2020, Friendica
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- *
- */
-
-namespace Friendica\Model;
-
-use Friendica\Database\DBA;
-use \BadMethodCallException;
-
-class ItemDeliveryData
-{
-       const LEGACY_FIELD_LIST = [
-               // Legacy fields moved from item table
-               'postopts',
-               'inform',
-       ];
-
-       const FIELD_LIST = [
-               // New delivery fields with virtual field name in item fields
-               'queue_count' => 'delivery_queue_count',
-               'queue_done'  => 'delivery_queue_done',
-               'queue_failed'  => 'delivery_queue_failed',
-       ];
-
-       const ACTIVITYPUB = 1;
-       const DFRN = 2;
-       const LEGACY_DFRN = 3;
-       const DIASPORA = 4;
-       const OSTATUS = 5;
-       const MAIL = 6;
-
-       /**
-        * Extract delivery data from the provided item fields
-        *
-        * @param array $fields
-        * @return array
-        */
-       public static function extractFields(array &$fields)
-       {
-               $delivery_data = [];
-               foreach (array_merge(ItemDeliveryData::FIELD_LIST, ItemDeliveryData::LEGACY_FIELD_LIST) as $key => $field) {
-                       if (is_int($key) && isset($fields[$field])) {
-                               // Legacy field moved from item table
-                               $delivery_data[$field] = $fields[$field];
-                               $fields[$field] = null;
-                       } elseif (isset($fields[$field])) {
-                               // New delivery field with virtual field name in item fields
-                               $delivery_data[$key] = $fields[$field];
-                               unset($fields[$field]);
-                       }
-               }
-
-               return $delivery_data;
-       }
-
-       /**
-        * Increments the queue_done for the given item ID.
-        *
-        * Avoids racing condition between multiple delivery threads.
-        *
-        * @param integer $item_id
-        * @param integer $protocol
-        * @return bool
-        * @throws \Exception
-        */
-       public static function incrementQueueDone($item_id, $protocol = 0)
-       {
-               $sql = '';
-
-               switch ($protocol) {
-                       case self::ACTIVITYPUB:
-                               $sql = ", `activitypub` = `activitypub` + 1";
-                               break;
-                       case self::DFRN:
-                               $sql = ", `dfrn` = `dfrn` + 1";
-                               break;
-                       case self::LEGACY_DFRN:
-                               $sql = ", `legacy_dfrn` = `legacy_dfrn` + 1";
-                               break;
-                       case self::DIASPORA:
-                               $sql = ", `diaspora` = `diaspora` + 1";
-                               break;
-                       case self::OSTATUS:
-                               $sql = ", `ostatus` = `ostatus` + 1";
-                               break;
-               }
-
-               return DBA::e('UPDATE `item-delivery-data` SET `queue_done` = `queue_done` + 1' . $sql . ' WHERE `iid` = ?', $item_id);
-       }
-
-       /**
-        * Increments the queue_failed for the given item ID.
-        *
-        * Avoids racing condition between multiple delivery threads.
-        *
-        * @param integer $item_id
-        * @return bool
-        * @throws \Exception
-        */
-       public static function incrementQueueFailed($item_id)
-       {
-               return DBA::e('UPDATE `item-delivery-data` SET `queue_failed` = `queue_failed` + 1 WHERE `iid` = ?', $item_id);
-       }
-
-       /**
-        * Increments the queue_count for the given item ID.
-        *
-        * @param integer $item_id
-        * @param integer $increment
-        * @return bool
-        * @throws \Exception
-        */
-       public static function incrementQueueCount(int $item_id, int $increment = 1)
-       {
-               return DBA::e('UPDATE `item-delivery-data` SET `queue_count` = `queue_count` + ? WHERE `iid` = ?', $increment, $item_id);
-       }
-
-       /**
-        * Insert a new item delivery data entry
-        *
-        * @param integer $item_id
-        * @param array   $fields
-        * @return bool
-        * @throws \Exception
-        */
-       public static function insert($item_id, array $fields)
-       {
-               if (empty($item_id)) {
-                       throw new BadMethodCallException('Empty item_id');
-               }
-
-               $fields['iid'] = $item_id;
-
-               return DBA::insert('item-delivery-data', $fields);
-       }
-
-       /**
-        * Update/Insert item delivery data
-        *
-        * If you want to update queue_done, please use incrementQueueDone instead.
-        *
-        * @param integer $item_id
-        * @param array   $fields
-        * @return bool
-        * @throws \Exception
-        */
-       public static function update($item_id, array $fields)
-       {
-               if (empty($item_id)) {
-                       throw new BadMethodCallException('Empty item_id');
-               }
-
-               if (empty($fields)) {
-                       // Nothing to do, update successful
-                       return true;
-               }
-
-               return DBA::update('item-delivery-data', $fields, ['iid' => $item_id], true);
-       }
-
-       /**
-        * Delete item delivery data
-        *
-        * @param integer $item_id
-        * @return bool
-        * @throws \Exception
-        */
-       public static function delete($item_id)
-       {
-               if (empty($item_id)) {
-                       throw new BadMethodCallException('Empty item_id');
-               }
-
-               return DBA::delete('item-delivery-data', ['iid' => $item_id]);
-       }
-}
diff --git a/src/Model/Post/DeliveryData.php b/src/Model/Post/DeliveryData.php
new file mode 100644 (file)
index 0000000..0feb382
--- /dev/null
@@ -0,0 +1,193 @@
+<?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Model\Post;
+
+use Friendica\Database\DBA;
+use \BadMethodCallException;
+
+class DeliveryData
+{
+       const LEGACY_FIELD_LIST = [
+               // Legacy fields moved from item table
+               'postopts',
+               'inform',
+       ];
+
+       const FIELD_LIST = [
+               // New delivery fields with virtual field name in item fields
+               'queue_count' => 'delivery_queue_count',
+               'queue_done'  => 'delivery_queue_done',
+               'queue_failed'  => 'delivery_queue_failed',
+       ];
+
+       const ACTIVITYPUB = 1;
+       const DFRN = 2;
+       const LEGACY_DFRN = 3;
+       const DIASPORA = 4;
+       const OSTATUS = 5;
+       const MAIL = 6;
+
+       /**
+        * Extract delivery data from the provided item fields
+        *
+        * @param array $fields
+        * @return array
+        */
+       public static function extractFields(array &$fields)
+       {
+               $delivery_data = [];
+               foreach (array_merge(self::FIELD_LIST, self::LEGACY_FIELD_LIST) as $key => $field) {
+                       if (is_int($key) && isset($fields[$field])) {
+                               // Legacy field moved from item table
+                               $delivery_data[$field] = $fields[$field];
+                               $fields[$field] = null;
+                       } elseif (isset($fields[$field])) {
+                               // New delivery field with virtual field name in item fields
+                               $delivery_data[$key] = $fields[$field];
+                               unset($fields[$field]);
+                       }
+               }
+
+               return $delivery_data;
+       }
+
+       /**
+        * Increments the queue_done for the given URI ID.
+        *
+        * Avoids racing condition between multiple delivery threads.
+        *
+        * @param integer $uri_id
+        * @param integer $protocol
+        * @return bool
+        * @throws \Exception
+        */
+       public static function incrementQueueDone(int $uri_id, int $protocol = 0)
+       {
+               $sql = '';
+
+               switch ($protocol) {
+                       case self::ACTIVITYPUB:
+                               $sql = ", `activitypub` = `activitypub` + 1";
+                               break;
+                       case self::DFRN:
+                               $sql = ", `dfrn` = `dfrn` + 1";
+                               break;
+                       case self::LEGACY_DFRN:
+                               $sql = ", `legacy_dfrn` = `legacy_dfrn` + 1";
+                               break;
+                       case self::DIASPORA:
+                               $sql = ", `diaspora` = `diaspora` + 1";
+                               break;
+                       case self::OSTATUS:
+                               $sql = ", `ostatus` = `ostatus` + 1";
+                               break;
+               }
+
+               return DBA::e('UPDATE `post-delivery-data` SET `queue_done` = `queue_done` + 1' . $sql . ' WHERE `uri-id` = ?', $uri_id);
+       }
+
+       /**
+        * Increments the queue_failed for the given URI ID.
+        *
+        * Avoids racing condition between multiple delivery threads.
+        *
+        * @param integer $uri_id
+        * @return bool
+        * @throws \Exception
+        */
+       public static function incrementQueueFailed(int $uri_id)
+       {
+               return DBA::e('UPDATE `post-delivery-data` SET `queue_failed` = `queue_failed` + 1 WHERE `uri-id` = ?', $uri_id);
+       }
+
+       /**
+        * Increments the queue_count for the given URI ID.
+        *
+        * @param integer $uri_id
+        * @param integer $increment
+        * @return bool
+        * @throws \Exception
+        */
+       public static function incrementQueueCount(int $uri_id, int $increment = 1)
+       {
+               return DBA::e('UPDATE `post-delivery-data` SET `queue_count` = `queue_count` + ? WHERE `uri-id` = ?', $increment, $uri_id);
+       }
+
+       /**
+        * Insert a new URI delivery data entry
+        *
+        * @param integer $uri_id
+        * @param array   $fields
+        * @return bool
+        * @throws \Exception
+        */
+       public static function insert(int $uri_id, array $fields)
+       {
+               if (empty($uri_id)) {
+                       throw new BadMethodCallException('Empty URI_id');
+               }
+
+               $fields['uri-id'] = $uri_id;
+
+               return DBA::insert('post-delivery-data', $fields);
+       }
+
+       /**
+        * Update/Insert URI delivery data
+        *
+        * If you want to update queue_done, please use incrementQueueDone instead.
+        *
+        * @param integer $uri_id
+        * @param array   $fields
+        * @return bool
+        * @throws \Exception
+        */
+       public static function update(int $uri_id, array $fields)
+       {
+               if (empty($uri_id)) {
+                       throw new BadMethodCallException('Empty URI_id');
+               }
+
+               if (empty($fields)) {
+                       // Nothing to do, update successful
+                       return true;
+               }
+
+               return DBA::update('post-delivery-data', $fields, ['uri-id' => $uri_id], true);
+       }
+
+       /**
+        * Delete URI delivery data
+        *
+        * @param integer $uri_id
+        * @return bool
+        * @throws \Exception
+        */
+       public static function delete(int $uri_id)
+       {
+               if (empty($uri_id)) {
+                       throw new BadMethodCallException('Empty URI_id');
+               }
+
+               return DBA::delete('post-delivery-data', ['uri-id' => $uri_id]);
+       }
+}
index a91c5cdf80925bf19e77afc24c85f32422c2f551..0a97f39a5fe7769e75693a5fcfe38548dc1e715e 100644 (file)
@@ -36,8 +36,8 @@ use Friendica\Model\Conversation;
 use Friendica\Model\GContact;
 use Friendica\Model\Item;
 use Friendica\Model\ItemURI;
-use Friendica\Model\ItemDeliveryData;
 use Friendica\Model\Mail;
+use Friendica\Model\Post;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
 use Friendica\Network\Probe;
@@ -2293,7 +2293,7 @@ class Diaspora
                }
 
                // Send all existing comments and likes to the requesting server
-               $comments = Item::select(['id', 'parent', 'verb', 'self'], ['parent' => $item['id']]);
+               $comments = Item::select(['id', 'uri-id', 'parent', 'verb', 'self'], ['parent' => $item['id']]);
                while ($comment = Item::fetch($comments)) {
                        if ($comment['id'] == $comment['parent']) {
                                continue;
@@ -2301,7 +2301,7 @@ class Diaspora
 
                        Logger::info('Deliver participation', ['item' => $comment['id'], 'contact' => $contact_id]);
                        if (Worker::add(PRIORITY_HIGH, 'Delivery', Delivery::POST, $comment['id'], $contact_id)) {
-                               ItemDeliveryData::incrementQueueCount($comment['id'], 1);
+                               Post\DeliveryData::incrementQueueCount($comment['uri-id'], 1);
                        }
                }
                DBA::close($comments);
index 60752896fc64b05c224504ecd78c355c4a8114dc..609bb88886632b128eac4282db661eaabd9fa6e6 100644 (file)
@@ -23,7 +23,8 @@ namespace Friendica\Worker;
 
 use Friendica\Core\Logger;
 use Friendica\Core\Worker;
-use Friendica\Model\ItemDeliveryData;
+use Friendica\Model\Item;
+use Friendica\Model\Post;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Util\HTTPSignature;
 
@@ -67,10 +68,13 @@ class APDelivery
                        }
                }
 
+               // This should never fail and is temporariy (until the move to )
+               $item = Item::selectFirst(['uri-id'], ['id' => $target_id]);
+
                if (!$success && !Worker::defer() && in_array($cmd, [Delivery::POST])) {
-                       ItemDeliveryData::incrementQueueFailed($target_id);
+                       Post\DeliveryData::incrementQueueFailed($item['uri-id']);
                } elseif ($success && in_array($cmd, [Delivery::POST])) {
-                       ItemDeliveryData::incrementQueueDone($target_id, ItemDeliveryData::ACTIVITYPUB);
+                       Post\DeliveryData::incrementQueueDone($item['uri-id'], Post\DeliveryData::ACTIVITYPUB);
                }
        }
 }
index 94a0f4902b0ba3c441e0cfe915b6c740fd985711..0a865cb3a7f7047fc5fc8e17a931cbfc5cc984ac 100644 (file)
@@ -58,14 +58,14 @@ class Delivery
                if ($cmd == self::MAIL) {
                        $target_item = DBA::selectFirst('mail', [], ['id' => $target_id]);
                        if (!DBA::isResult($target_item)) {
-                               self::setFailedQueue($cmd, $target_id);
+                               self::setFailedQueue($cmd, $target_item);
                                return;
                        }
                        $uid = $target_item['uid'];
                } elseif ($cmd == self::SUGGESTION) {
                        $target_item = DBA::selectFirst('fsuggest', [], ['id' => $target_id]);
                        if (!DBA::isResult($target_item)) {
-                               self::setFailedQueue($cmd, $target_id);
+                               self::setFailedQueue($cmd, $target_item);
                                return;
                        }
                        $uid = $target_item['uid'];
@@ -75,7 +75,7 @@ class Delivery
                } else {
                        $item = Model\Item::selectFirst(['parent'], ['id' => $target_id]);
                        if (!DBA::isResult($item) || empty($item['parent'])) {
-                               self::setFailedQueue($cmd, $target_id);
+                               self::setFailedQueue($cmd, $target_item);
                                return;
                        }
                        $parent_id = intval($item['parent']);
@@ -97,13 +97,13 @@ class Delivery
 
                        if (empty($target_item)) {
                                Logger::log('Item ' . $target_id . "wasn't found. Quitting here.");
-                               self::setFailedQueue($cmd, $target_id);
+                               self::setFailedQueue($cmd, $target_item);
                                return;
                        }
 
                        if (empty($parent)) {
                                Logger::log('Parent ' . $parent_id . ' for item ' . $target_id . "wasn't found. Quitting here.");
-                               self::setFailedQueue($cmd, $target_id);
+                               self::setFailedQueue($cmd, $target_item);
                                return;
                        }
 
@@ -113,7 +113,7 @@ class Delivery
                                $uid = $target_item['uid'];
                        } else {
                                Logger::log('Only public users for item ' . $target_id, Logger::DEBUG);
-                               self::setFailedQueue($cmd, $target_id);
+                               self::setFailedQueue($cmd, $target_item);
                                return;
                        }
 
@@ -127,7 +127,7 @@ class Delivery
 
                        if (!empty($contact_id) && Model\Contact::isArchived($contact_id)) {
                                Logger::info('Contact is archived', ['id' => $contact_id, 'cmd' => $cmd, 'item' => $target_item['id']]);
-                               self::setFailedQueue($cmd, $target_id);
+                               self::setFailedQueue($cmd, $target_item);
                                return;
                        }
 
@@ -187,7 +187,7 @@ class Delivery
 
                $owner = Model\User::getOwnerDataById($uid);
                if (!DBA::isResult($owner)) {
-                       self::setFailedQueue($cmd, $target_id);
+                       self::setFailedQueue($cmd, $target_item);
                        return;
                }
 
@@ -196,12 +196,12 @@ class Delivery
                        ['id' => $contact_id, 'blocked' => false, 'pending' => false, 'self' => false]
                );
                if (!DBA::isResult($contact)) {
-                       self::setFailedQueue($cmd, $target_id);
+                       self::setFailedQueue($cmd, $target_item);
                        return;
                }
 
                if (Network::isUrlBlocked($contact['url'])) {
-                       self::setFailedQueue($cmd, $target_id);
+                       self::setFailedQueue($cmd, $target_item);
                        return;
                }
 
@@ -242,16 +242,16 @@ class Delivery
        /**
         * Increased the "failed" counter in the item delivery data
         *
-        * @param string  $cmd Command
-        * @param integer $id  Item id
+        * @param string $cmd  Command
+        * @param array  $item Item array
         */
-       private static function setFailedQueue(string $cmd, int $id)
+       private static function setFailedQueue(string $cmd, array $item)
        {
                if (!in_array($cmd, [Delivery::POST, Delivery::POKE])) {
                        return;
                }
 
-               Model\ItemDeliveryData::incrementQueueFailed($id);
+               Model\Post\DeliveryData::incrementQueueFailed($item['uri-id'] ?? $item['id']);
        }
 
        /**
@@ -335,13 +335,13 @@ class Delivery
                        DFRN::import($atom, $target_importer);
 
                        if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
-                               Model\ItemDeliveryData::incrementQueueDone($target_item['id'], Model\ItemDeliveryData::DFRN);
+                               Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Model\Post\DeliveryData::DFRN);
                        }
 
                        return;
                }
 
-               $protocol = Model\ItemDeliveryData::DFRN;
+               $protocol = Model\Post\DeliveryData::DFRN;
 
                // We don't have a relationship with contacts on a public post.
                // Se we transmit with the new method and via Diaspora as a fallback
@@ -357,9 +357,9 @@ class Delivery
 
                                if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
                                        if (($deliver_status >= 200) && ($deliver_status <= 299)) {
-                                               Model\ItemDeliveryData::incrementQueueDone($target_item['id'], $protocol);
+                                               Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], $protocol);
                                        } else {
-                                               Model\ItemDeliveryData::incrementQueueFailed($target_item['id']);
+                                               Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
                                        }
                                }
                                return;
@@ -376,11 +376,11 @@ class Delivery
                        if ($deliver_status < 200) {
                                // Legacy DFRN
                                $deliver_status = DFRN::deliver($owner, $contact, $atom);
-                               $protocol = Model\ItemDeliveryData::LEGACY_DFRN;
+                               $protocol = Model\Post\DeliveryData::LEGACY_DFRN;
                        }
                } else {
                        $deliver_status = DFRN::deliver($owner, $contact, $atom);
-                       $protocol = Model\ItemDeliveryData::LEGACY_DFRN;
+                       $protocol = Model\Post\DeliveryData::LEGACY_DFRN;
                }
 
                Logger::info('DFRN Delivery', ['cmd' => $cmd, 'url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id'], 'return' => $deliver_status]);
@@ -390,7 +390,7 @@ class Delivery
                        Model\Contact::unmarkForArchival($contact);
 
                        if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
-                               Model\ItemDeliveryData::incrementQueueDone($target_item['id'], $protocol);
+                               Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], $protocol);
                        }
                } else {
                        // The message could not be delivered. We mark the contact as "dead"
@@ -398,7 +398,7 @@ class Delivery
 
                        Logger::info('Delivery failed: defer message', ['id' => ($target_item['guid'] ?? '') ?: $target_item['id']]);
                        if (!Worker::defer() && in_array($cmd, [Delivery::POST, Delivery::POKE])) {
-                               Model\ItemDeliveryData::incrementQueueFailed($target_item['id']);
+                               Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
                        }
                }
        }
@@ -475,7 +475,7 @@ class Delivery
                        Model\Contact::unmarkForArchival($contact);
 
                        if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
-                               Model\ItemDeliveryData::incrementQueueDone($target_item['id'], Model\ItemDeliveryData::DIASPORA);
+                               Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Model\Post\DeliveryData::DIASPORA);
                        }
                } else {
                        // The message could not be delivered. We mark the contact as "dead"
@@ -490,10 +490,10 @@ class Delivery
                                Logger::info('Delivery failed: defer message', ['id' => ($target_item['guid'] ?? '') ?: $target_item['id']]);
                                // defer message for redelivery
                                if (!Worker::defer() && in_array($cmd, [Delivery::POST, Delivery::POKE])) {
-                                       Model\ItemDeliveryData::incrementQueueFailed($target_item['id']);
+                                       Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
                                }
                        } elseif (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
-                               Model\ItemDeliveryData::incrementQueueFailed($target_item['id']);
+                               Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
                        }
                }
        }
@@ -603,7 +603,7 @@ class Delivery
 
                Email::send($addr, $subject, $headers, $target_item);
 
-               Model\ItemDeliveryData::incrementQueueDone($target_item['id'], Model\ItemDeliveryData::MAIL);
+               Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Model\Post\DeliveryData::MAIL);
 
                Logger::info('Delivered via mail', ['guid' => $target_item['guid'], 'to' => $addr, 'subject' => $subject]);
        }
index 35a228fce1b1622d2fc548857fa1c6663a5c082c..a9fadf2519d5550d32d6ed0ee1848b81bd5d2fac 100644 (file)
@@ -32,7 +32,7 @@ use Friendica\Model\Contact;
 use Friendica\Model\Conversation;
 use Friendica\Model\Group;
 use Friendica\Model\Item;
-use Friendica\Model\ItemDeliveryData;
+use Friendica\Model\Post;
 use Friendica\Model\PushSubscriber;
 use Friendica\Model\User;
 use Friendica\Network\Probe;
@@ -573,7 +573,7 @@ class Notifier
                                /// @TODO Redeliver/queue these items on failure, though there is no contact record
                                $delivery_queue_count++;
                                Salmon::slapper($owner, $url, $slap);
-                               ItemDeliveryData::incrementQueueDone($target_id, ItemDeliveryData::OSTATUS);
+                               Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Post\DeliveryData::OSTATUS);
                        }
                }
 
@@ -595,11 +595,11 @@ class Notifier
                        // Workaround for pure connector posts
                        if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
                                if ($delivery_queue_count == 0) {
-                                       ItemDeliveryData::incrementQueueDone($target_item['id']);
+                                       Post\DeliveryData::incrementQueueDone($target_item['uri-id']);
                                        $delivery_queue_count = 1;
                                }
 
-                               ItemDeliveryData::incrementQueueCount($target_item['id'], $delivery_queue_count);
+                               Post\DeliveryData::incrementQueueCount($target_item['uri-id'], $delivery_queue_count);
                        }
                }
 
index 2c3a9fb5fd42c3b97899d7773b80dba66db535ba..085d544faaf5f736bf935d2ba84a53b42a3a71c1 100755 (executable)
@@ -804,25 +804,6 @@ return [
                        "uri-id" => ["uri-id"]
                ]
        ],
-       "item-delivery-data" => [
-               "comment" => "Delivery data for items",
-               "fields" => [
-                       "iid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "relation" => ["item" => "id"], "comment" => "Item id"],
-                       "postopts" => ["type" => "text", "comment" => "External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery"],
-                       "inform" => ["type" => "mediumtext", "comment" => "Additional receivers of the linked item"],
-                       "queue_count" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Initial number of delivery recipients, used as item.delivery_queue_count"],
-                       "queue_done" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries, used as item.delivery_queue_done"],
-                       "queue_failed" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of unsuccessful deliveries, used as item.delivery_queue_failed"],
-                       "activitypub" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via ActivityPub"],
-                       "dfrn" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via DFRN"],
-                       "legacy_dfrn" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via legacy DFRN"],
-                       "diaspora" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via Diaspora"],
-                       "ostatus" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via OStatus"],
-               ],
-               "indexes" => [
-                       "PRIMARY" => ["iid"],
-               ]
-       ],
        "item-uri" => [
                "comment" => "URI and GUID for items",
                "fields" => [
@@ -1306,6 +1287,25 @@ return [
                        "url" => ["url"]
                ]
        ],
+       "post-delivery-data" => [
+               "comment" => "Delivery data for items",
+               "fields" => [
+                       "uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "relation" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
+                       "postopts" => ["type" => "text", "comment" => "External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery"],
+                       "inform" => ["type" => "mediumtext", "comment" => "Additional receivers of the linked item"],
+                       "queue_count" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Initial number of delivery recipients, used as item.delivery_queue_count"],
+                       "queue_done" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries, used as item.delivery_queue_done"],
+                       "queue_failed" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of unsuccessful deliveries, used as item.delivery_queue_failed"],
+                       "activitypub" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via ActivityPub"],
+                       "dfrn" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via DFRN"],
+                       "legacy_dfrn" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via legacy DFRN"],
+                       "diaspora" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via Diaspora"],
+                       "ostatus" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via OStatus"],
+               ],
+               "indexes" => [
+                       "PRIMARY" => ["uri-id"],
+               ]
+       ],
        "post-tag" => [
                "comment" => "post relation to tags",
                "fields" => [