X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FWorker%2FDelivery.php;h=fbc8fb8b25a21013c1447e33fc040a7e4d3ae9d4;hb=81de61c6a7f6c0b2a3f50b50a8fc21c261bdb70f;hp=ab3e3a6e0bdc3023bbd66833bea917bfdd6e9ef5;hpb=0a82fe4211f73cf10107feb69fe38eaa85eb61f8;p=friendica.git diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index ab3e3a6e0b..fbc8fb8b25 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -33,7 +33,7 @@ class Delivery extends BaseObject public static function execute($cmd, $target_id, $contact_id) { - Logger::log('Invoked: ' . $cmd . ': ' . $target_id . ' to ' . $contact_id, Logger::DEBUG); + Logger::info('Invoked', ['cmd' => $cmd, 'target' => $target_id, 'contact' => $contact_id]); $top_level = false; $followup = false; @@ -43,12 +43,14 @@ class Delivery extends BaseObject if ($cmd == self::MAIL) { $target_item = DBA::selectFirst('mail', [], ['id' => $target_id]); if (!DBA::isResult($target_item)) { + self::setFailedQueue($cmd, $target_id); 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); return; } $uid = $target_item['uid']; @@ -58,6 +60,7 @@ class Delivery extends BaseObject } else { $item = Model\Item::selectFirst(['parent'], ['id' => $target_id]); if (!DBA::isResult($item) || empty($item['parent'])) { + self::setFailedQueue($cmd, $target_id); return; } $parent_id = intval($item['parent']); @@ -79,11 +82,13 @@ class Delivery extends BaseObject if (empty($target_item)) { Logger::log('Item ' . $target_id . "wasn't found. Quitting here."); + self::setFailedQueue($cmd, $target_id); return; } if (empty($parent)) { Logger::log('Parent ' . $parent_id . ' for item ' . $target_id . "wasn't found. Quitting here."); + self::setFailedQueue($cmd, $target_id); return; } @@ -93,6 +98,21 @@ class Delivery extends BaseObject $uid = $target_item['uid']; } else { Logger::log('Only public users for item ' . $target_id, Logger::DEBUG); + self::setFailedQueue($cmd, $target_id); + return; + } + + $condition = ['uri' => $target_item['thr-parent'], 'uid' => $target_item['uid']]; + $thr_parent = Model\Item::selectFirst(['network'], $condition); + if (!DBA::isResult($thr_parent)) { + // Shouldn't happen. But when this does, we just take the parent as thread parent. + // That's totally okay for what we use this variable here. + $thr_parent = $parent; + } + + 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); return; } @@ -152,6 +172,7 @@ class Delivery extends BaseObject $owner = Model\User::getOwnerDataById($uid); if (!DBA::isResult($owner)) { + self::setFailedQueue($cmd, $target_id); return; } @@ -160,23 +181,25 @@ class Delivery extends BaseObject ['id' => $contact_id, 'blocked' => false, 'pending' => false, 'self' => false] ); if (!DBA::isResult($contact)) { + self::setFailedQueue($cmd, $target_id); return; } if (Network::isUrlBlocked($contact['url'])) { + self::setFailedQueue($cmd, $target_id); return; } - // Transmit via Diaspora if the thread had started as Diaspora post + // Transmit via Diaspora if the thread had started as Diaspora post. + // Also transmit via Diaspora if this is a direct answer to a Diaspora comment. // This is done since the uri wouldn't match (Diaspora doesn't transmit it) - if (isset($parent) && ($parent['network'] == Protocol::DIASPORA) && ($contact['network'] == Protocol::DFRN)) { + if (!empty($parent) && !empty($thr_parent) && in_array(Protocol::DIASPORA, [$parent['network'], $thr_parent['network']])) { $contact['network'] = Protocol::DIASPORA; } - Logger::log("Delivering " . $cmd . " followup=$followup - via network " . $contact['network']); + Logger::notice('Delivering', ['cmd' => $cmd, 'target' => $target_id, 'followup' => $followup, 'network' => $contact['network']]); switch ($contact['network']) { - case Protocol::DFRN: self::deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup); break; @@ -196,6 +219,21 @@ class Delivery extends BaseObject return; } + /** + * Increased the "failed" counter in the item delivery data + * + * @param string $cmd Command + * @param integer $id Item id + */ + private static function setFailedQueue(string $cmd, int $id) + { + if (!in_array($cmd, [Delivery::POST, Delivery::POKE])) { + return; + } + + Model\ItemDeliveryData::incrementQueueFailed($id); + } + /** * @brief Deliver content via DFRN * @@ -212,7 +250,7 @@ class Delivery extends BaseObject */ private static function deliverDFRN($cmd, $contact, $owner, $items, $target_item, $public_message, $top_level, $followup) { - Logger::log('Deliver ' . defaults($target_item, 'guid', $target_item['id']) . ' via DFRN to ' . (empty($contact['addr']) ? $contact['url'] : $contact['addr'])); + Logger::info('Deliver ' . (($target_item['guid'] ?? '') ?: $target_item['id']) . ' via DFRN to ' . (($contact['addr'] ?? '') ?: $contact['url'])); if ($cmd == self::MAIL) { $item = $target_item; @@ -240,7 +278,7 @@ class Delivery extends BaseObject $atom = DFRN::entries($msgitems, $owner); } - Logger::log('Notifier entry: ' . $contact["url"] . ' ' . defaults($target_item, 'guid', $target_item['id']) . ' entry: ' . $atom, Logger::DATA); + Logger::debug('Notifier entry: ' . $contact["url"] . ' ' . (($target_item['guid'] ?? '') ?: $target_item['id']) . ' entry: ' . $atom); $basepath = implode('/', array_slice(explode('/', $contact['url']), 0, 3)); @@ -291,7 +329,15 @@ class Delivery extends BaseObject // We never spool failed relay deliveries if ($public_dfrn) { - Logger::log('Relay delivery to ' . $contact["url"] . ' with guid ' . $target_item["guid"] . ' returns ' . $deliver_status); + Logger::info('Relay delivery to ' . $contact["url"] . ' with guid ' . $target_item["guid"] . ' returns ' . $deliver_status); + + if (in_array($cmd, [Delivery::POST, Delivery::POKE])) { + if (($deliver_status >= 200) && ($deliver_status <= 299)) { + Model\ItemDeliveryData::incrementQueueDone($target_item['id'], $protocol); + } else { + Model\ItemDeliveryData::incrementQueueFailed($target_item['id']); + } + } return; } @@ -313,7 +359,7 @@ class Delivery extends BaseObject $protocol = Model\ItemDeliveryData::LEGACY_DFRN; } - Logger::info('DFRN Delivery', ['cmd' => $cmd, 'url' => $contact['url'], 'guid' => defaults($target_item, 'guid', $target_item['id']), 'return' => $deliver_status]); + Logger::info('DFRN Delivery', ['cmd' => $cmd, 'url' => $contact['url'], 'guid' => ($target_item['guid'] ?? '') ?: $target_item['id'], 'return' => $deliver_status]); if (($deliver_status >= 200) && ($deliver_status <= 299)) { // We successfully delivered a message, the contact is alive @@ -326,8 +372,10 @@ class Delivery extends BaseObject // The message could not be delivered. We mark the contact as "dead" Model\Contact::markForArchival($contact); - Logger::info('Delivery failed: defer message', ['id' => defaults($target_item, 'guid', $target_item['id'])]); - Worker::defer(); + 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']); + } } } @@ -356,7 +404,7 @@ class Delivery extends BaseObject $loc = $contact['addr']; } - Logger::log('Deliver ' . defaults($target_item, 'guid', $target_item['id']) . ' via Diaspora to ' . $loc); + Logger::notice('Deliver via Diaspora', ['target' => $target_item['id'], 'guid' => $target_item['guid'], 'to' => $loc]); if (Config::get('system', 'dfrn_only') || !Config::get('system', 'diaspora_enabled')) { return; @@ -409,12 +457,19 @@ class Delivery extends BaseObject // The message could not be delivered. We mark the contact as "dead" Model\Contact::markForArchival($contact); + // When it is delivered to the public endpoint, we do mark the relay contact for archival as well + if ($public_message) { + Diaspora::markRelayForArchival($contact); + } + if (empty($contact['contact-type']) || ($contact['contact-type'] != Model\Contact::TYPE_RELAY)) { - Logger::info('Delivery failed: defer message', ['id' => defaults($target_item, 'guid', $target_item['id'])]); + Logger::info('Delivery failed: defer message', ['id' => ($target_item['guid'] ?? '') ?: $target_item['id']]); // defer message for redelivery - Worker::defer(); + if (!Worker::defer() && in_array($cmd, [Delivery::POST, Delivery::POKE])) { + Model\ItemDeliveryData::incrementQueueFailed($target_item['id']); + } } elseif (in_array($cmd, [Delivery::POST, Delivery::POKE])) { - Model\ItemDeliveryData::incrementQueueDone($target_item['id'], Model\ItemDeliveryData::DIASPORA); + Model\ItemDeliveryData::incrementQueueFailed($target_item['id']); } } }