public function actionSendOne() { $db = \Yii::$app->db; /** @var Message $model */ $model = Message::find()->where(['status' => Message::STATUS_NEW])->orderBy(['id' => SORT_ASC, 'priority' => SORT_DESC])->one(); if (!$model) { return false; } $transaction = $db->beginTransaction(); try { $model->status = $this->component->send($model->to, $model->text, $model->transport) ? Message::STATUS_SENT : Message::STATUS_ERROR; $model->updateAttributes(['status']); $transaction->commit(); } catch (\Exception $e) { $transaction->rollback(); throw $e; } return true; }
/** * Put message to queue * * @param $to * @param $text * @param int $priority * @param string|null $transport * @return bool */ public function queue($to, $text, $priority = 0, $transport = null) { if (empty($transport)) { $transport = $this->defaultTransport; } if (!array_key_exists($transport, $this->transports)) { throw new \BadMethodCallException('Bad transport ID'); } Message::queue($to, $text, $priority, $transport); return true; }
public function actionDashboard() { $stat = ['new' => Message::find()->where(['status' => Message::STATUS_NEW])->count(), 'sent' => Message::find()->where(['status' => Message::STATUS_SENT])->count(), 'error' => Message::find()->where(['status' => Message::STATUS_ERROR])->count()]; return $this->render('@vendor/yii-dream-team/yii2-sms-center/src/backend/views/stat/dashboard', ['stat' => $stat]); }