]> git.mxchange.org Git - friendica.git/blob - src/Model/PushSubscriber.php
Merge pull request #5076 from tobiasd/20180517-extract
[friendica.git] / src / Model / PushSubscriber.php
1 <?php
2 /**
3  * @file src/Model/PushSubscriber.php
4  */
5 namespace Friendica\Model;
6
7 use Friendica\Core\Worker;
8 use dba;
9
10 require_once 'include/dba.php';
11
12 class PushSubscriber
13 {
14         /**
15          * @param string $priority Priority for push workers
16          */
17         public static function publishFeed($default_priority = PRIORITY_HIGH)
18         {
19                 // We'll push to each subscriber that has push > 0,
20                 // i.e. there has been an update (set in notifier.php).
21                 $subscribers = dba::select('push_subscriber', ['id', 'push', 'callback_url'], ["`push` > 0 AND `next_try` < UTC_TIMESTAMP()"]);
22
23                 while ($subscriber = dba::fetch($subscribers)) {
24                         // We always handle retries with low priority
25                         if ($subscriber["push"] > 1) {
26                                 $priority = PRIORITY_LOW;
27                         } else {
28                                 $priority = $default_priority;
29                         }
30
31                         logger("Publish feed to " . $subscriber["callback_url"] . " with priority " . $priority, LOGGER_DEBUG);
32                         Worker::add($priority, 'PubSubPublish', (int)$subscriber["id"]);
33                 }
34
35                 dba::close($subscribers);
36         }
37 }