2019-12-23 16:28:30 +03:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace dominion\cron\models;
|
|
|
|
|
|
|
|
|
|
use Yii;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This is the model class for table "mole_task".
|
|
|
|
|
*
|
|
|
|
|
* @property int $id
|
|
|
|
|
* @property int $parentId
|
|
|
|
|
* @property string $dateAdd
|
|
|
|
|
* @property string $dateStart
|
|
|
|
|
* @property string $dateEnd
|
|
|
|
|
* @property string $module
|
|
|
|
|
* @property string $controller
|
|
|
|
|
* @property string $type
|
|
|
|
|
* @property string $name
|
|
|
|
|
* @property string $params
|
|
|
|
|
* @property int $isReady
|
|
|
|
|
* @property int $completed
|
|
|
|
|
* @property int $priority
|
|
|
|
|
* @property int $childsTotalCount
|
|
|
|
|
* @property int $childsCompleted
|
|
|
|
|
* @property string $status
|
|
|
|
|
* @property string $project
|
2020-10-26 14:08:52 +03:00
|
|
|
|
* @property int $period
|
2019-12-23 16:28:30 +03:00
|
|
|
|
*/
|
|
|
|
|
class MoleTask extends \yii\db\ActiveRecord
|
|
|
|
|
{
|
2020-10-26 14:08:52 +03:00
|
|
|
|
|
2019-12-23 16:28:30 +03:00
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
|
|
|
|
public static function tableName()
|
|
|
|
|
{
|
|
|
|
|
return 'mole_task';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
|
|
|
|
public function rules()
|
|
|
|
|
{
|
|
|
|
|
return [
|
2019-12-24 17:04:30 +03:00
|
|
|
|
//[['parentId', 'isReady', 'childsTotalCount', 'childsCompleted', 'status'], 'required'],
|
2020-10-26 14:08:52 +03:00
|
|
|
|
[['parentId', 'isReady', 'completed', 'priority', 'childsTotalCount', 'childsCompleted', 'period'], 'integer'],
|
2019-12-23 16:28:30 +03:00
|
|
|
|
[['dateAdd', 'dateStart', 'dateEnd'], 'safe'],
|
|
|
|
|
[['params'], 'string'],
|
|
|
|
|
[['module', 'controller', 'type', 'name', 'status'], 'string', 'max' => 255],
|
|
|
|
|
[['project'], 'string', 'max' => 50],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
|
|
|
|
public function attributeLabels()
|
|
|
|
|
{
|
|
|
|
|
return [
|
2019-12-23 17:34:09 +03:00
|
|
|
|
'id' => Yii::t('mole', 'ID'),
|
2019-12-24 17:04:30 +03:00
|
|
|
|
'parentId' => Yii::t('mole', 'Parent ID'),
|
2019-12-23 17:34:09 +03:00
|
|
|
|
'dateAdd' => Yii::t('mole', 'Date Add'),
|
|
|
|
|
'dateStart' => Yii::t('mole', 'Date Start'),
|
|
|
|
|
'dateEnd' => Yii::t('mole', 'Date End'),
|
|
|
|
|
'module' => Yii::t('mole', 'Module'),
|
|
|
|
|
'controller' => Yii::t('mole', 'Controller'),
|
|
|
|
|
'type' => Yii::t('mole', 'Type'),
|
|
|
|
|
'name' => Yii::t('mole', 'Name'),
|
|
|
|
|
'params' => Yii::t('mole', 'Params'),
|
|
|
|
|
'isReady' => Yii::t('mole', 'Is Ready'),
|
|
|
|
|
'completed' => Yii::t('mole', 'Completed'),
|
|
|
|
|
'priority' => Yii::t('mole', 'Priority'),
|
|
|
|
|
'childsTotalCount' => Yii::t('mole', 'Childs Total Count'),
|
|
|
|
|
'childsCompleted' => Yii::t('mole', 'Childs Completed'),
|
|
|
|
|
'status' => Yii::t('mole', 'Status'),
|
2019-12-24 17:04:30 +03:00
|
|
|
|
'project' => Yii::t('mole', 'Project'),
|
2020-10-26 14:08:52 +03:00
|
|
|
|
'period' => Yii::t('mole', 'Period'),
|
2019-12-23 16:28:30 +03:00
|
|
|
|
];
|
|
|
|
|
}
|
2020-10-26 14:08:52 +03:00
|
|
|
|
|
2019-12-24 17:04:30 +03:00
|
|
|
|
/**
|
|
|
|
|
* Выбираем все строки с project
|
|
|
|
|
*/
|
|
|
|
|
public function getAllTask()
|
|
|
|
|
{
|
|
|
|
|
return self::find()
|
2020-10-26 14:08:52 +03:00
|
|
|
|
->andWhere([
|
|
|
|
|
'project' => Yii::$app->getModule('cron')->project,
|
|
|
|
|
'completed' => 0,
|
|
|
|
|
])
|
|
|
|
|
->andWhere(['IS', 'dateStart', NULL])
|
|
|
|
|
->andWhere(['IS', 'dateEnd', NULL])
|
|
|
|
|
->andWhere(['<=', 'dateAdd', date('Y-m-d H:i:s')])
|
|
|
|
|
->orderBy('priority DESC')
|
|
|
|
|
->all();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setCompleted()
|
|
|
|
|
{
|
|
|
|
|
$this->dateEnd = date('Y-m-d H:i:s');
|
|
|
|
|
$this->completed = 1;
|
|
|
|
|
if ($this->save() && $this->period > 0)
|
|
|
|
|
{
|
|
|
|
|
$model = new MoleTask;
|
|
|
|
|
$model->attributes = $this->attributes;
|
|
|
|
|
$model->isReady = 0;
|
|
|
|
|
$model->completed = 0;
|
|
|
|
|
$model->dateStart = null;
|
|
|
|
|
$model->dateEnd = null;
|
2021-01-15 13:20:39 +03:00
|
|
|
|
$model->dateAdd = date('Y-m-d H:i:s', (strtotime($this->dateAdd . " +$this->period seconds")));
|
2020-10-26 14:08:52 +03:00
|
|
|
|
$model->save();
|
|
|
|
|
}
|
2019-12-24 17:04:30 +03:00
|
|
|
|
}
|
2020-10-26 14:08:52 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Добавление агента (обертка)
|
|
|
|
|
* @param string $controller
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @param array $params
|
|
|
|
|
* @param int $priority
|
|
|
|
|
* @param int $period
|
|
|
|
|
* @param date $dateAdd
|
|
|
|
|
* @param string $project
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public static function add($controller, $name, $params = array(), $priority = 0, $period = 0, $dateAdd = false, $project = false)
|
|
|
|
|
{
|
|
|
|
|
$model = new MoleTask();
|
|
|
|
|
$model->controller = $controller;
|
|
|
|
|
$model->name = $name;
|
|
|
|
|
$model->params = serialize($params);
|
|
|
|
|
$model->priority = $priority;
|
|
|
|
|
$model->period = $period;
|
|
|
|
|
$model->dateAdd = $dateAdd ?: date('Y-m-d H:i:s');
|
|
|
|
|
$model->project = $project ?: Yii::$app->getModule('cron')->project;
|
|
|
|
|
$model->type = $model->project . '.' . $model->controller; // для совместимости
|
|
|
|
|
return $model->save();
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-23 16:28:30 +03:00
|
|
|
|
}
|