Exemplo n.º 1
0
 /**
  * Add one or more recipients to this thread
  *
  * @param string $threadId
  *   Thread identifier
  * @param string|string[] $userId
  *   User identifier or list of user identifiers
  */
 public function addRecipientsTo($threadId, $userIdList)
 {
     $subList = [];
     foreach (Misc::toIterable($userIdList) as $userId) {
         $subList[] = $this->backend->getSubscriber($this->getUserSubscriberId($userId))->subscribe($threadId)->getId();
     }
     $this->backend->copyQueue($threadId, $subList);
 }
Exemplo n.º 2
0
 /**
  * Notify an action happened on a resource in an arbitrary channel
  *
  * @param string|string[] $chanId
  * @param string $resourceType
  * @param string|string[] $resourceId
  * @param string $action
  * @param array $data
  *   Arbitrary data to send along
  * @param int $level
  *   Arbitrary level, see Notification::LEVEL_* constants. This value is
  *   purely arbitrary, it is up to the business layer to do something with
  *   it. It does not alters the notification system behavior.
  * @param boolean $doExcludeCurrent
  *   If set to false the current subscribers won't be excluded from the
  *   current notification recipient list
  */
 public function notifyChannel($chanId, $resourceType, $resourceId, $action, $data = [], $level = null, $doExcludeCurrent = true)
 {
     if (null === $level) {
         $level = NotificationInterface::LEVEL_INFO;
     }
     $chanIdList = Misc::toIterable($chanId);
     $data = ['data' => $data];
     $data['id'] = Misc::toArray($resourceId);
     $type = $resourceType . ':' . $action;
     try {
         $exclude = [];
         if ($doExcludeCurrent && $this->currentSubscribers) {
             foreach ($this->currentSubscribers as $name) {
                 // Using getSubscriptionIds() will avoid an odd number of
                 // backend queries (at least for SQL backend). I do hope
                 // that our current subscriber does not have thousands...
                 $exclude = array_merge($exclude, $this->backend->getSubscriber($name)->getSubscriptionsIds());
             }
         }
         $this->prepareNotification($type, $data, $level);
         // Channels are not automatically created
         // TODO Find a better a way, to filter out non-existing channels
         $this->backend->createChannels($chanIdList, true);
         $this->backend->send($chanIdList, $data, $type, null, $level, $exclude);
     } catch (ChannelDoesNotExistException $e) {
         // Nothing to do, no channel means no subscription
     } catch (Exception $e) {
         // Any other exception must be shutdown when in production mode
         if (!$this->silentMode) {
             throw $e;
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Add channel to notification destination
  *
  * @param string|string[] $chanId
  */
 public function addArbitraryChanId($chanId)
 {
     foreach (Misc::toIterable($chanId) as $id) {
         $this->chanIdList[] = $id;
     }
 }