model() public static method

Returns the static model of the specified AR class.
public static model ( string $className = __CLASS__ ) : Queue
$className string active record class name.
return Queue the static model class
 public function run($args)
 {
     echo "*********************\n " . date('Y-m-d H:i:s') . "\n*********************\n";
     $c = new CDbCriteria();
     $c->order = 'create_time ASC';
     /** @var Queue $queue */
     $queue = Queue::model()->find($c);
     if (!$queue) {
         echo "The queue is empty\n*********************\n";
         return;
     }
     switch ($queue->type) {
         case Queue::TYPE_MAIL:
             $this->handleMail($queue);
             break;
     }
     $queue->delete();
     echo "*********************\n";
 }
 public function actionIndex($limit = 5)
 {
     $limit = (int) $limit;
     echo "Process " . $limit . " mail task...\n";
     Yii::log("Process " . $limit . " mail task...\n");
     $models = Queue::model()->findAll(array('condition' => 'worker = :worker AND status = :status', 'params' => array(':worker' => self::MAIL_WORKER_ID, ':status' => Queue::STATUS_NEW), 'limit' => $limit, 'order' => 'priority desc'));
     echo "Find " . count($models) . " new mail task...\n";
     Yii::log("Find " . count($models) . " new mail task...\n");
     foreach ($models as $model) {
         echo "Process mail task id = {$model->id}...\n";
         Yii::log("Process mail task id = {$model->id}...\n");
         if (!($data = (array) json_decode($model->task))) {
             $model->status = Queue::STATUS_ERROR;
             $model->notice = 'Error json_decode...';
             $model->save();
             echo "Error json_decode...\n";
             Yii::log('Error json_decode...');
             continue;
         }
         if (!isset($data['from'], $data['to'], $data['theme'], $data['body'])) {
             $model->status = Queue::STATUS_ERROR;
             $model->notice = 'Wrong data...';
             $model->save();
             echo "Wrong data...";
             Yii::log('Wrong data...');
             continue;
         }
         if (Yii::app()->mail->send($data['from'], $data['to'], $data['theme'], $data['body'])) {
             $model->status = Queue::STATUS_COMLETED;
             $model->complete_time = new CDbExpression('NOW()');
             $model->save();
             echo "Success send...";
             Yii::log("Success send...");
             continue;
         }
     }
 }
Esempio n. 3
0
 /**
  * Возвращает модель по указанному идентификатору
  * Если модель не будет найдена - возникнет HTTP-исключение.
  * 
  * @throws CHttpException
  * 
  * @param integer $id идентификатор нужной модели
  * 
  * @return Queue $model
  *
  * @throws CHttpException If record not found
  */
 public function loadModel($id)
 {
     if (($model = Queue::model()->findByPk($id)) === null) {
         throw new CHttpException(404, Yii::t('QueueModule.queue', 'Requested page was not found.'));
     }
     return $model;
 }
Esempio n. 4
0
 public function init()
 {
     parent::init();
     $this->queueTableName = Queue::model()->tableName();
 }