3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Worker;
24 use Friendica\Core\Logger;
25 use Friendica\Core\Worker;
26 use Friendica\Model\Post;
27 use Friendica\Protocol\ActivityPub;
31 * Delivers ActivityPub messages
33 * @param string $cmd One of the Worker\Delivery constant values
34 * @param integer $item_id 0 if no item is involved (like Delivery::REMOVAL and Delivery::PROFILEUPDATE)
35 * @param string $inbox The URL of the recipient profile
36 * @param integer $uid The ID of the user who triggered this delivery
37 * @param array $receivers The contact IDs related to the inbox URL for contact archival housekeeping
38 * @param int $uri_id URI-ID of item to be transmitted
39 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
40 * @throws \ImagickException
42 public static function execute(string $cmd, int $item_id, string $inbox, int $uid, array $receivers = [], int $uri_id = 0)
44 if (ActivityPub\Transmitter::archivedInbox($inbox)) {
45 Logger::info('Inbox is archived', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $item_id, 'uri-id' => $uri_id, 'uid' => $uid]);
46 if (empty($uri_id) && !empty($item_id)) {
47 $item = Post::selectFirst(['uri-id'], ['id' => $item_id]);
48 $uri_id = $item['uri-id'] ?? 0;
51 $posts = Post\Delivery::selectForInbox($inbox);
52 $uri_ids = array_column($posts, 'uri-id');
57 foreach ($uri_ids as $uri_id) {
58 Post\Delivery::remove($uri_id, $inbox);
59 Post\DeliveryData::incrementQueueFailed($uri_id);
64 Logger::debug('Invoked', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $item_id, 'uri-id' => $uri_id, 'uid' => $uid]);
67 $result = ActivityPub\Delivery::deliver($inbox);
68 $success = $result['success'];
70 $uri_ids = $result['uri_ids'];
72 $result = ActivityPub\Delivery::deliverToInbox($cmd, $item_id, $inbox, $uid, $receivers, $uri_id);
73 $success = $result['success'];
74 $drop = $result['drop'];
78 if (!$drop && !$success && !Worker::defer() && !empty($uri_ids)) {
79 foreach ($uri_ids as $uri_id) {
80 Post\Delivery::remove($uri_id, $inbox);
81 Post\DeliveryData::incrementQueueFailed($uri_id);