]> git.mxchange.org Git - friendica.git/commitdiff
Moved functionality in new model class
authorMichael <heluecht@pirati.ca>
Thu, 17 May 2018 23:30:49 +0000 (23:30 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 17 May 2018 23:30:49 +0000 (23:30 +0000)
src/Model/PushSubscriber.php [new file with mode: 0644]
src/Worker/Notifier.php
src/Worker/PubSubPublish.php
src/Worker/Queue.php

diff --git a/src/Model/PushSubscriber.php b/src/Model/PushSubscriber.php
new file mode 100644 (file)
index 0000000..2794a0b
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+/**
+ * @file src/Model/PushSubscriber.php
+ */
+namespace Friendica\Model;
+
+use Friendica\Core\Worker;
+use dba;
+
+require_once 'include/dba.php';
+
+class PushSubscriber
+{
+       /**
+        * @param string $priority Priority for push workers
+        */
+       public static function publishFeed($priority = PRIORITY_HIGH)
+       {
+               // We'll push to each subscriber that has push > 0,
+               // i.e. there has been an update (set in notifier.php).
+               $subscribers = dba::select('push_subscriber', ['id', 'callback_url'], ["`push` > 0 AND `next_try` < UTC_TIMESTAMP()"]);
+
+               while ($subscriber = dba::fetch($subscribers)) {
+                       logger("Publish feed to " . $subscriber["callback_url"], LOGGER_DEBUG);
+                       Worker::add($priority, 'PubSubPublish', (int)$subscriber["id"]);
+               }
+
+               dba::close($subscribers);
+       }
+}
index f8b37c2f9090ceabda6c397094fd05a7c4661b83..f7b7aeae14c44d5b1681bbebbcd12c1f3ab92b07 100644 (file)
@@ -11,6 +11,7 @@ use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
 use Friendica\Model\User;
+use Friendica\Model\PushSubscriber;
 use Friendica\Network\Probe;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
@@ -506,8 +507,7 @@ class Notifier {
                        logger('Activating internal PuSH for item '.$item_id, LOGGER_DEBUG);
 
                        // Handling the pubsubhubbub requests
-                       Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
-                                       'PubSubPublish');
+                       PushSubscriber::publishFeed($a->queue['priority']);
                }
 
                logger('notifier: calling hooks for ' . $cmd . ' ' . $item_id, LOGGER_DEBUG);
index 1b2dbbef9f0cb0cb95e470fffb28017edaf183c7..27b6f3d9a16853ef3a398ecd275f4edd08bfb56b 100644 (file)
@@ -20,24 +20,11 @@ require_once 'include/items.php';
 class PubSubPublish {
        public static function execute($pubsubpublish_id = 0)
        {
-               global $a;
-
-               if ($pubsubpublish_id != 0) {
-                       self::publish($pubsubpublish_id);
+               if ($pubsubpublish_id == 0) {
                        return;
                }
 
-               // We'll push to each subscriber that has push > 0,
-               // i.e. there has been an update (set in notifier.php).
-               $subscribers = dba::select('push_subscriber', ['id', 'callback_url'], ["`push` > 0 AND `next_try` < UTC_TIMESTAMP()"]);
-
-               while ($subscriber = dba::fetch($subscribers)) {
-                       logger("Publish feed to " . $subscriber["callback_url"], LOGGER_DEBUG);
-                       Worker::add(['priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true],
-                                       'PubSubPublish', (int)$subscriber["id"]);
-               }
-
-               dba::close($subscribers);
+               self::publish($pubsubpublish_id);
        }
 
        private static function publish($id) {
index 20ade6dfaecd8a35430b20d4d8981d4ffc8c6536..50a9a5c91acb7c9dbc52c928bf9ea0eb9b554536 100644 (file)
@@ -10,6 +10,7 @@ use Friendica\Core\Config;
 use Friendica\Core\Worker;
 use Friendica\Database\DBM;
 use Friendica\Model\Queue as QueueModel;
+use Friendica\Model\PushSubscriber;
 use Friendica\Protocol\DFRN;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\PortableContact;
@@ -34,7 +35,7 @@ class Queue
                        logger('filling queue jobs - start');
 
                        // Handling the pubsubhubbub requests
-                       Worker::add(['priority' => PRIORITY_LOW, 'dont_fork' => true], 'PubSubPublish');
+                       PushSubscriber::publishFeed(PRIORITY_LOW);
 
                        $r = dba::inArray(dba::p("SELECT `id` FROM `queue` WHERE `next` < UTC_TIMESTAMP() ORDER BY `batch`, `cid`"));