]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #7245 from annando/unify-constants
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 10 Jun 2019 15:59:40 +0000 (11:59 -0400)
committerGitHub <noreply@github.com>
Mon, 10 Jun 2019 15:59:40 +0000 (11:59 -0400)
Fix delivery counter for poking / unify delivery commands

16 files changed:
mod/events.php
mod/fsuggest.php
mod/item.php
mod/settings.php
mod/tagger.php
src/Core/UserImport.php
src/Core/Worker.php
src/Model/Item.php
src/Model/Mail.php
src/Model/User.php
src/Module/Admin/Site.php
src/Protocol/Diaspora.php
src/Worker/APDelivery.php
src/Worker/Delivery.php
src/Worker/Notifier.php
update.php

index 8e9606b203cb8e15b236a6c45f28e494ab409635..86cec9a7d4130edfdafb31a6bd66f10e594bf6b0 100644 (file)
@@ -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');
index 2cede5685215abe6ad0bbf8bbddaa90b42efd86e..2bddf48133103510becfb1c90290c86a2c820059 100644 (file)
@@ -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);
 }
index 1fccbca4d6b85fa072729b6bad8005027998c26d..20dc9dfdae892a94a22da257dff8f9b235d28f60 100644 (file)
@@ -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');
index 45f11cdb6c3f3ff89e69ad9899b986ca1e74bcb5..ab7586733adfe3bd014157181a226388f28950e8 100644 (file)
@@ -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');
        }
index 5d3d1923e4425958b4d53a00e3ea436cd8553c76..2c15cdd28c68d62f4d836b905713d1c30b435fa7 100644 (file)
@@ -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();
 }
index 97a6e6028e3b4905e341506a5f4d540ccbbd219d..71767e8cef788be4cfa1f90b7c189d7dac63ad13 100644 (file)
@@ -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');
index 548547022476d91c8f75e7c421583467a8176efd..8fdd60c2a74db95549ec4d3766b631b3f1020358 100644 (file)
@@ -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
index e57b3cbd3c740649234a4c11fc12373da26822bb..4dc1be648aea7c455cf20958cae6512b69da744c 100644 (file)
@@ -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)
index 9bdb6e1a10bdd91895dd6fcdf91f020b71e248f9..30191edae62b4122337e3e29cdcd4e2d527d53fa 100644 (file)
@@ -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;
index 64253946fd71207f0c54b50b58c4ad76ed5ecaf5..b73356306e465720f15aec64601dbe5045603c68 100644 (file)
@@ -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]);
index 5d2004ca5fbf988961e51671f9dc973671792450..78576efe3bce0f710a926fc9074a729f8f6616b8 100644 (file)
@@ -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.");
index ac1cf9c38d469793b7d7179de1cca1a0707167b0..751033e9600c6dc5fb4453e95562177a732f2dcb 100644 (file)
@@ -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);
 
index 632f6cffc5dae09736391dafa11befa0ae6d7993..fcd4a76725f65dd4881a3f956fb14bf9da653b13 100644 (file)
@@ -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);
                                }
                        }
index 97bc58ef67411fd52345cd85e74790c7105798d2..ad6bb75c03af95055ecd2944c0dc1eea3633e373 100644 (file)
@@ -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;
                }
 
index c2f61c55a426325ef97734ee1ae39d1bade45e0d..a677cef60442fcd4fd873bc72e8c1ce3a8425a54 100644 (file)
@@ -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]);
                        }
 
index 40a3e8ff0d22ee39328b8eddcd39621144af1e00..077a56e66e795252e8027ab6b1f73caa1ad338f3 100644 (file)
@@ -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']]);
        }