public function actionMessage($queue_name, $subscriber_id = null, $message_id = null)
    {
        if (($subscriber_id = trim($subscriber_id)) === '') {
            $subscriber_id = null;
        }
        /** @var QueueInterface $queue */
        list($queue, $authItems) = $this->loadQueue($queue_name, ['nfy.message.read', 'nfy.message.create']);
        $this->verifySubscriber($queue, $subscriber_id);

        if ($queue instanceof components\DbQueue) {
            $query = models\DbMessage::find()->withQueue($queue->id);
            if ($subscriber_id !== null) {
                $query->withSubscriber($subscriber_id);
            }

            $dbMessage = $query->andWhere([
                'in',
                models\DbMessage::tableName().'.'.models\DbMessage::primaryKey()[0],
                $message_id,
            ])->one();
            if ($dbMessage === null) {
                throw new NotFoundHttpException(Yii::t("app", 'Message with given ID was not found.'));
            }
            $messages = models\DbMessage::createMessages($dbMessage);
            $message = reset($messages);
        } else {
            $dbMessage = null;
            //! @todo should we even bother to locate a single message by id?
            $message = new components\Message();
            $message->setAttributes([
                'id' => $message_id,
                'subscriber_id' => $subscriber_id,
                'status' => components\Message::AVAILABLE,
            ]);
        }

        if (isset($_POST['delete'])) {
            $queue->delete($message->id, $message->subscriber_id);

            return $this->redirect([
                'messages',
                'queue_name' => $queue_name,
                'subscriber_id' => $message->subscriber_id,
            ]);
        }

        return $this->render('message', [
            'queue' => $queue,
            'queue_name' => $queue_name,
            'dbMessage' => $dbMessage,
            'message' => $message,
            'authItems' => $authItems,
        ]);
    }
public function actionMessage($queue_name, $subscriber_id = null, $message_id = null)
    {
        if (($subscriber_id = trim($subscriber_id)) === '') {
            $subscriber_id = null;
        }
        /** @var QueueInterface $queue */
        list($queue, $authItems) = $this->loadQueue($queue_name, ['nfy.message.read', 'nfy.message.create']);
        $this->verifySubscriber($queue, $subscriber_id);

        if ($queue instanceof components\DbQueue) {
            $query = models\DbMessage::find()->withQueue($queue->id);
            if ($subscriber_id !== null) {
                $query->withSubscriber($subscriber_id);
            }

            $dbMessage = $query->andWhere([
                'in',
                models\DbMessage::tableName().'.'.models\DbMessage::primaryKey()[0],
                $message_id,
            ])->one();
            if ($dbMessage === null) {
                throw new NotFoundHttpException(Yii::t("app", 'Message with given ID was not found.'));
            }
            $messages = models\DbMessage::createMessages($dbMessage);
            $message = reset($messages);
        } else {
            $dbMessage = null;
            //! @todo should we even bother to locate a single message by id?
            $message = new components\Message();
            $message->setAttributes([
                'id' => $message_id,
                'subscriber_id' => $subscriber_id,
                'status' => components\Message::AVAILABLE,
            ]);
        }

        if (isset($_POST['delete'])) {
            $queue->delete($message->id, $message->subscriber_id);

            return $this->redirect([
                'messages',
                'queue_name' => $queue_name,
                'subscriber_id' => $message->subscriber_id,
            ]);
        }

        return $this->render('message', [
            'queue' => $queue,
            'queue_name' => $queue_name,
            'dbMessage' => $dbMessage,
            'message' => $message,
            'authItems' => $authItems,
        ]);
    }
public function actionMessage ( $ queue_name , $ subscriber_id = null , $ message_id = null ) { if ( ( $ subscriber_id = trim ( $ subscriber_id ) ) === '' ) { $ subscriber_id = null ; } /** @var QueueInterface $queue */ list ( $ queue , $ authItems ) = $ this -> loadQueue ( $ queue_name , [ 'nfy.message.read' , 'nfy.message.create' ] ) ; $ this -> verifySubscriber ( $ queue , $ subscriber_id ) ; if ( $ queue instanceof components \ DbQueue ) { $ query = models \ DbMessage :: find ( ) -> withQueue ( $ queue -> id ) ; if ( $ subscriber_id !== null ) { $ query -> withSubscriber ( $ subscriber_id ) ; } $ dbMessage = $ query -> andWhere ( [ 'in' , models \ DbMessage :: tableName ( ) . '.' . models \ DbMessage :: primaryKey ( ) [ 0 ] , $ message_id , ] ) -> one ( ) ; if ( $ dbMessage === null ) { throw new NotFoundHttpException ( Yii :: t ( "app" , 'Message with given ID was not found.' ) ) ; } $ messages = models \ DbMessage :: createMessages ( $ dbMessage ) ; $ message = reset ( $ messages ) ; } else { $ dbMessage = null ; //! @todo should we even bother to locate a single message by id? $ message = new components \ Message ( ) ; $ message -> setAttributes ( [ 'id' => $ message_id , 'subscriber_id' => $ subscriber_id , 'status' => components \ Message :: AVAILABLE , ] ) ; } if ( isset ( $ _POST [ 'delete' ] ) ) { $ queue -> delete ( $ message -> id , $ message -> subscriber_id ) ; return $ this -> redirect ( [ 'messages' , 'queue_name' => $ queue_name , 'subscriber_id' => $ message -> subscriber_id , ] ) ; } return $ this -> render ( 'message' , [ 'queue' => $ queue , 'queue_name' => $ queue_name , 'dbMessage' => $ dbMessage , 'message' => $ message , 'authItems' => $ authItems , ] ) ; }
Fetches details of a single message, allows to release or delete it or sends a new message.
@param string $queue_name
@param string $subscriber_id
@param string $message_id
@return string|\yii\web\Response
@throws ForbiddenHttpException
@throws NotFoundHttpException
Fetches details of a single message allows to release or delete it or sends a new message .