From 41dc243186ebf5241e668ce6dcf4309d924b16b4 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 10 Jun 2019 14:19:24 +0000 Subject: [PATCH] Fix delivery counter for poking / unify delivery commands --- mod/events.php | 3 ++- mod/fsuggest.php | 3 ++- mod/item.php | 4 +--- mod/settings.php | 3 ++- mod/tagger.php | 3 ++- src/Core/UserImport.php | 3 ++- src/Core/Worker.php | 2 +- src/Model/Item.php | 24 +++++------------------- src/Model/Mail.php | 3 ++- src/Model/User.php | 3 ++- src/Module/Admin/Site.php | 3 ++- src/Protocol/Diaspora.php | 10 +++------- src/Worker/APDelivery.php | 2 +- src/Worker/Delivery.php | 11 +++++------ src/Worker/Notifier.php | 26 +++++--------------------- update.php | 8 +------- 16 files changed, 38 insertions(+), 73 deletions(-) diff --git a/mod/events.php b/mod/events.php index 8e9606b203..86cec9a7d4 100644 --- a/mod/events.php +++ b/mod/events.php @@ -21,6 +21,7 @@ use Friendica\Module\Login; use Friendica\Util\DateTimeFormat; use Friendica\Util\Strings; use Friendica\Util\Temporal; +use Friendica\Worker\Delivery; function events_init(App $a) { @@ -195,7 +196,7 @@ function events_post(App $a) $item_id = Event::store($datarray); if (!$cid) { - Worker::add(PRIORITY_HIGH, "Notifier", "event", $item_id); + Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $item_id); } $a->internalRedirect('events'); diff --git a/mod/fsuggest.php b/mod/fsuggest.php index 2cede56852..2bddf48133 100644 --- a/mod/fsuggest.php +++ b/mod/fsuggest.php @@ -10,6 +10,7 @@ use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\Util\DateTimeFormat; use Friendica\Util\Strings; +use Friendica\Worker\Delivery; function fsuggest_post(App $a) { @@ -51,7 +52,7 @@ function fsuggest_post(App $a) 'photo' => $contact['avatar'], 'note' => $note, 'created' => DateTimeFormat::utcNow()]; DBA::insert('fsuggest', $fields); - Worker::add(PRIORITY_HIGH, 'Notifier', 'suggest', DBA::lastInsertId()); + Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::SUGGESTION, DBA::lastInsertId()); info(L10n::t('Friend suggestion sent.') . EOL); } diff --git a/mod/item.php b/mod/item.php index 1fccbca4d6..20dc9dfdae 100644 --- a/mod/item.php +++ b/mod/item.php @@ -604,8 +604,6 @@ function item_post(App $a) { $origin = $_REQUEST['origin']; } - $notify_type = ($toplevel_item_id ? Delivery::COMMENT : Delivery::POST); - $uri = ($message_id ? $message_id : Item::newURI($api_source ? $profile_uid : $uid, $guid)); // Fallback so that we alway have a parent uri @@ -870,7 +868,7 @@ function item_post(App $a) { // When we are doing some forum posting via ! we have to start the notifier manually. // These kind of posts don't initiate the notifier call in the item class. if ($only_to_forum) { - Worker::add(PRIORITY_HIGH, "Notifier", $notify_type, $post_id); + Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post_id); } Logger::log('post_complete'); diff --git a/mod/settings.php b/mod/settings.php index 45f11cdb6c..ab7586733a 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -27,6 +27,7 @@ use Friendica\Protocol\Email; use Friendica\Util\Network; use Friendica\Util\Strings; use Friendica\Util\Temporal; +use Friendica\Worker\Delivery; function get_theme_config_file($theme) { @@ -389,7 +390,7 @@ function settings_post(App $a) BaseModule::checkFormSecurityTokenRedirectOnError('/settings', 'settings'); if (!empty($_POST['resend_relocate'])) { - Worker::add(PRIORITY_HIGH, 'Notifier', 'relocate', local_user()); + Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, local_user()); info(L10n::t("Relocate message has been send to your contacts")); $a->internalRedirect('settings'); } diff --git a/mod/tagger.php b/mod/tagger.php index 5d3d1923e4..2c15cdd28c 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -12,6 +12,7 @@ use Friendica\Database\DBA; use Friendica\Model\Item; use Friendica\Util\Strings; use Friendica\Util\XML; +use Friendica\Worker\Delivery; function tagger_content(App $a) { @@ -194,7 +195,7 @@ EOT; Hook::callAll('post_local_end', $arr); - Worker::add(PRIORITY_HIGH, "Notifier", "tag", $post_id); + Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post_id); exit(); } diff --git a/src/Core/UserImport.php b/src/Core/UserImport.php index 97a6e6028e..71767e8cef 100644 --- a/src/Core/UserImport.php +++ b/src/Core/UserImport.php @@ -10,6 +10,7 @@ use Friendica\Database\DBStructure; use Friendica\Model\Photo; use Friendica\Object\Image; use Friendica\Util\Strings; +use Friendica\Worker\Delivery; /** * @brief UserImport class @@ -278,7 +279,7 @@ class UserImport } // send relocate messages - Worker::add(PRIORITY_HIGH, 'Notifier', 'relocate', $newuid); + Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, $newuid); info(L10n::t("Done. You can now login with your username and password")); $a->internalRedirect('login'); diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 0f4a527f6b..d7e5479267 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -1100,7 +1100,7 @@ class Worker * @param (integer|array) priority or parameter array, strings are deprecated and are ignored * * next args are passed as $cmd command line - * or: Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id); + * or: Worker::add(PRIORITY_HIGH, "Notifier", Delivery::DELETION, $drop_id); * or: Worker::add(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "CreateShadowEntry", $post_id); * * @return boolean "false" if proc_run couldn't be executed diff --git a/src/Model/Item.php b/src/Model/Item.php index e57b3cbd3c..4dc1be648a 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -926,7 +926,7 @@ class Item extends BaseObject // We only need to notfiy others when it is an original entry from us. // Only call the notifier when the item has some content relevant change. if ($item['origin'] && in_array('edited', array_keys($fields))) { - Worker::add(PRIORITY_HIGH, "Notifier", 'edit_post', $item['id']); + Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $item['id']); } } @@ -1096,7 +1096,7 @@ class Item extends BaseObject self::delete(['uri' => $item['uri'], 'deleted' => false], $priority); // send the notification upstream/downstream - Worker::add(['priority' => $priority, 'dont_fork' => true], "Notifier", "drop", intval($item['id'])); + Worker::add(['priority' => $priority, 'dont_fork' => true], "Notifier", Delivery::DELETION, intval($item['id'])); } elseif ($item['uid'] != 0) { // When we delete just our local user copy of an item, we have to set a marker to hide it @@ -1509,7 +1509,7 @@ class Item extends BaseObject $item['thr-parent'] = $item['parent-uri']; - $notify_type = ''; + $notify_type = Delivery::POST; $allow_cid = ''; $allow_gid = ''; $deny_cid = ''; @@ -1522,7 +1522,6 @@ class Item extends BaseObject $allow_gid = $item['allow_gid']; $deny_cid = $item['deny_cid']; $deny_gid = $item['deny_gid']; - $notify_type = Delivery::POST; } else { // find the parent and snarf the item id and ACLs // and anything else we need to inherit @@ -1560,7 +1559,6 @@ class Item extends BaseObject $deny_cid = $parent['deny_cid']; $deny_gid = $parent['deny_gid']; $item['wall'] = $parent['wall']; - $notify_type = Delivery::COMMENT; /* * If the parent is private, force privacy for the entire conversation @@ -1882,20 +1880,8 @@ class Item extends BaseObject check_user_notification($current_post); - if ($notify) { + if ($notify || ($item['visible'] && ((!empty($parent) && $parent['origin']) || $item['origin']))) { Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $notify_type, $current_post); - } elseif ($item['visible'] && ((!empty($parent) && $parent['origin']) || $item['origin'])) { - if ($item['gravity'] == GRAVITY_ACTIVITY) { - $cmd = $item['origin'] ? Delivery::ACTIVITY : 'activity-import'; - } elseif ($item['gravity'] == GRAVITY_COMMENT) { - $cmd = $item['origin'] ? Delivery::COMMENT : 'comment-import'; - } elseif (!empty($notify_type)) { - $cmd = $notify_type; - } else { - $cmd = Delivery::POST; - } - - Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $cmd, $current_post); } return $current_post; @@ -2611,7 +2597,7 @@ class Item extends BaseObject self::updateThread($item_id); - Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', 'tgroup', $item_id); + Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', Delivery::POST, $item_id); } public static function isRemoteSelf($contact, &$datarray) diff --git a/src/Model/Mail.php b/src/Model/Mail.php index 9bdb6e1a10..30191edae6 100644 --- a/src/Model/Mail.php +++ b/src/Model/Mail.php @@ -13,6 +13,7 @@ use Friendica\Model\Item; use Friendica\Database\DBA; use Friendica\Network\Probe; use Friendica\Util\DateTimeFormat; +use Friendica\Worker\Delivery; /** * Class to handle private messages @@ -218,7 +219,7 @@ class Mail } if ($post_id) { - Worker::add(PRIORITY_HIGH, "Notifier", "mail", $post_id); + Worker::add(PRIORITY_HIGH, "Notifier", Delivery::MAIL, $post_id); return intval($post_id); } else { return -3; diff --git a/src/Model/User.php b/src/Model/User.php index 64253946fd..b73356306e 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -21,6 +21,7 @@ use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; use Friendica\Util\Strings; +use Friendica\Worker\Delivery; use LightOpenID; /** @@ -912,7 +913,7 @@ class User // The user and related data will be deleted in "cron_expire_and_remove_users" (cronjobs.php) DBA::update('user', ['account_removed' => true, 'account_expires_on' => DateTimeFormat::utc('now + 7 day')], ['uid' => $uid]); - Worker::add(PRIORITY_HIGH, 'Notifier', 'removeme', $uid); + Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::REMOVAL, $uid); // Send an update to the directory $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]); diff --git a/src/Module/Admin/Site.php b/src/Module/Admin/Site.php index 5d2004ca5f..78576efe3b 100644 --- a/src/Module/Admin/Site.php +++ b/src/Module/Admin/Site.php @@ -16,6 +16,7 @@ use Friendica\Protocol\PortableContact; use Friendica\Util\BasePath; use Friendica\Util\BaseURL; use Friendica\Util\Strings; +use Friendica\Worker\Delivery; require_once __DIR__ . '/../../../boot.php'; @@ -99,7 +100,7 @@ class Site extends BaseAdminModule // send relocate $usersStmt = DBA::select('user', ['uid'], ['account_removed' => false, 'account_expired' => false]); while ($user = DBA::fetch($usersStmt)) { - Worker::add(PRIORITY_HIGH, 'Notifier', 'relocate', $user['uid']); + Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, $user['uid']); } info("Relocation started. Could take a while to complete."); diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index ac1cf9c38d..751033e960 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -2148,13 +2148,9 @@ class Diaspora if ($comment['id'] == $comment['parent']) { continue; } - if ($comment['verb'] == ACTIVITY_POST) { - $cmd = $comment['self'] ? Delivery::COMMENT : 'comment-import'; - } else { - $cmd = $comment['self'] ? Delivery::ACTIVITY : 'activity-import'; - } - Logger::log("Send ".$cmd." for item ".$comment['id']." to contact ".$contact_id, Logger::DEBUG); - Worker::add(PRIORITY_HIGH, 'Delivery', $cmd, $comment['id'], $contact_id); + + Logger::info('Deliver participation', ['item' => $comment['id'], 'contact' => $contact_id]); + Worker::add(PRIORITY_HIGH, 'Delivery', Delivery::POST, $comment['id'], $contact_id); } DBA::close($comments); diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index 632f6cffc5..fcd4a76725 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -48,7 +48,7 @@ class APDelivery extends BaseObject $data = ActivityPub\Transmitter::createCachedActivityFromItem($target_id); if (!empty($data)) { $success = HTTPSignature::transmit($data, $inbox, $uid); - if ($success && in_array($cmd, [Delivery::POST, Delivery::COMMENT])) { + if ($success && in_array($cmd, [Delivery::POST])) { ItemDeliveryData::incrementQueueDone($target_id); } } diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 97bc58ef67..ad6bb75c03 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -27,8 +27,7 @@ class Delivery extends BaseObject const DELETION = 'drop'; const POST = 'wall-new'; const POKE = 'poke'; - const COMMENT = 'comment-new'; - const ACTIVITY = 'activity-new'; + const UPLINK = 'uplink'; const REMOVAL = 'removeme'; const PROFILEUPDATE = 'profileupdate'; @@ -319,7 +318,7 @@ class Delivery extends BaseObject // We successfully delivered a message, the contact is alive Model\Contact::unmarkForArchival($contact); - if (in_array($cmd, [Delivery::POST, Delivery::COMMENT])) { + if (in_array($cmd, [Delivery::POST, Delivery::POKE])) { Model\ItemDeliveryData::incrementQueueDone($target_item['id']); } } else { @@ -400,7 +399,7 @@ class Delivery extends BaseObject // We successfully delivered a message, the contact is alive Model\Contact::unmarkForArchival($contact); - if (in_array($cmd, [Delivery::POST, Delivery::COMMENT])) { + if (in_array($cmd, [Delivery::POST, Delivery::POKE])) { Model\ItemDeliveryData::incrementQueueDone($target_item['id']); } } else { @@ -411,7 +410,7 @@ class Delivery extends BaseObject Logger::info('Delivery failed: defer message', ['id' => defaults($target_item, 'guid', $target_item['id'])]); // defer message for redelivery Worker::defer(); - } elseif (in_array($cmd, [Delivery::POST, Delivery::COMMENT])) { + } elseif (in_array($cmd, [Delivery::POST, Delivery::POKE])) { Model\ItemDeliveryData::incrementQueueDone($target_item['id']); } } @@ -439,7 +438,7 @@ class Delivery extends BaseObject return; } - if (!in_array($cmd, [self::POST, self::COMMENT])) { + if (!in_array($cmd, [self::POST, self::POKE])) { return; } diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index c2f61c55a4..a677cef604 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -32,23 +32,7 @@ require_once 'include/items.php'; * * Worker::add(PRIORITY_HIGH, "Notifier", COMMAND, ITEM_ID); * - * where COMMAND is one of the following: - * - * activity (in diaspora.php, dfrn_confirm.php, profiles.php) - * comment-import (in diaspora.php, items.php) - * comment-new (in item.php) - * drop (in diaspora.php, items.php, photos.php) - * edit_post (in item.php) - * event (in events.php) - * like (in like.php, poke.php) - * mail (in message.php) - * suggest (in fsuggest.php) - * tag (in photos.php, poke.php, tagger.php) - * tgroup (in items.php) - * wall-new (in photos.php, item.php) - * removeme (in Contact.php) - * relocate (in uimport.php) - * + * where COMMAND is one of the constants that are defined in Worker/Delivery.php * and ITEM_ID is the id of the item in the database that needs to be sent to others. */ @@ -199,7 +183,7 @@ class Notifier } - if (($cmd === 'uplink') && (intval($parent['forum_mode']) == 1) && !$top_level) { + if (($cmd === Delivery::UPLINK) && (intval($parent['forum_mode']) == 1) && !$top_level) { $relay_to_owner = true; } @@ -287,8 +271,8 @@ class Notifier // if our parent is a public forum (forum_mode == 1), uplink to the origional author causing // a delivery fork. private groups (forum_mode == 2) do not uplink - if ((intval($parent['forum_mode']) == 1) && !$top_level && ($cmd !== 'uplink')) { - Worker::add($a->queue['priority'], 'Notifier', 'uplink', $target_id); + if ((intval($parent['forum_mode']) == 1) && !$top_level && ($cmd !== Delivery::UPLINK)) { + Worker::add($a->queue['priority'], 'Notifier', Delivery::UPLINK, $target_id); } foreach ($items as $item) { @@ -545,7 +529,7 @@ class Notifier if (!empty($target_item)) { Logger::log('Calling hooks for ' . $cmd . ' ' . $target_id, Logger::DEBUG); - if (in_array($cmd, [Delivery::POST, Delivery::COMMENT])) { + if (in_array($cmd, [Delivery::POST, Delivery::POKE])) { ItemDeliveryData::update($target_item['id'], ['queue_count' => $delivery_queue_count]); } diff --git a/update.php b/update.php index 40a3e8ff0d..077a56e66e 100644 --- a/update.php +++ b/update.php @@ -362,14 +362,8 @@ function update_1309() continue; } - if ($item['gravity'] == GRAVITY_PARENT) { - $cmd = Delivery::POST; - } else { - $cmd = Delivery::COMMENT; - } - $deliver_options = ['priority' => PRIORITY_MEDIUM, 'dont_fork' => true]; - Worker::add($deliver_options, 'Delivery', $cmd, $item['id'], $entry['cid']); + Worker::add($deliver_options, 'Delivery', Delivery::POST, $item['id'], $entry['cid']); Logger::info('Added delivery worker', ['command' => $cmd, 'item' => $item['id'], 'contact' => $entry['cid']]); DBA::delete('queue', ['id' => $entry['id']]); } -- 2.39.5