Elgg\Notifications\NotificationsService::processQueue PHP Метод

processQueue() публичный Метод

Pull notification events from queue until stop time is reached
public processQueue ( integer $stopTime, boolean $matrix = false ) : integer | array
$stopTime integer The Unix time to stop sending notifications
$matrix boolean If true, will return delivery matrix instead of a notifications event count
Результат integer | array The number of notification events handled, or a delivery matrix
    public function processQueue($stopTime, $matrix = false)
    {
        $this->subscriptions->methods = $this->methods;
        $delivery_matrix = [];
        $count = 0;
        // @todo grab mutex
        $ia = $this->session->setIgnoreAccess(true);
        while (time() < $stopTime) {
            // dequeue notification event
            $event = $this->queue->dequeue();
            /* @var $event NotificationEvent */
            if (!$event) {
                // queue is empty
                break;
            }
            if (!$event instanceof NotificationEvent || !$event->getObject() || !$event->getActor()) {
                // event object or actor have been deleted since the event was enqueued
                continue;
            }
            $subscriptions = $this->subscriptions->getSubscriptions($event);
            // return false to stop the default notification sender
            $params = ['event' => $event, 'subscriptions' => $subscriptions];
            $deliveries = [];
            if ($this->hooks->trigger('send:before', 'notifications', $params, true)) {
                $deliveries = $this->sendNotifications($event, $subscriptions);
            }
            $params['deliveries'] = $deliveries;
            $this->hooks->trigger('send:after', 'notifications', $params);
            $count++;
            $delivery_matrix[$event->getDescription()] = $deliveries;
        }
        // release mutex
        $this->session->setIgnoreAccess($ia);
        return $matrix ? $delivery_matrix : $count;
    }

Usage Example

Пример #1
0
 public function testValidatesActorExistenceForDequeuedSubscriptionNotificationEvent()
 {
     // This test can be enabled once users table operations such as delete/ban are mocked
     $this->markTestSkipped();
     $object = $this->getTestObject();
     $mock = $this->getMock(SubscriptionsService::class, ['getSubscriptions'], [], '', false);
     $mock->expects($this->exactly(0))->method('getSubscriptions')->will($this->returnValue([]));
     $this->subscriptions = $mock;
     $this->setupServices();
     $this->notifications->registerMethod('test_method');
     $this->session->setLoggedInUser($this->actor);
     $this->notifications->registerEvent($object->getType(), $object->getSubtype(), ['test_event']);
     $this->notifications->enqueueEvent('test_event', $object->getType(), $object);
     $this->session->removeLoggedInUser();
     $actor->delete();
     $this->assertEquals(0, $this->notifications->processQueue($this->time + 10));
 }