diff --git a/Bootstrap.php b/Bootstrap.php deleted file mode 100644 index 83b4b0b..0000000 --- a/Bootstrap.php +++ /dev/null @@ -1,27 +0,0 @@ -get('i18n')->translations['user*'])) - { - $app->get('i18n')->translations['user*'] = [ - 'class' => PhpMessageSource::className(), - 'basePath' => __DIR__ . '/messages', - 'sourceLanguage' => 'ru-RU' - ]; - } - } - -} diff --git a/Module.php b/Module.php index 32667bd..b5d97f3 100644 --- a/Module.php +++ b/Module.php @@ -21,4 +21,14 @@ class Module extends \yii\base\Module // custom initialization code goes here } + public function bootstrap($app) + { + if ($app instanceof \yii\console\Application) { + $app->controllerMap[$this->id] = [ + 'class' => 'dominion\cron\console\MoleController', + 'module' => $this, + ]; + } + } + } diff --git a/console/MoleController.php b/console/MoleController.php new file mode 100644 index 0000000..7619ce9 --- /dev/null +++ b/console/MoleController.php @@ -0,0 +1,69 @@ + + * @since 0.1 + */ +class MoleController extends Controller +{ + + /** + * Запуск всех агентов для проекта yii из mole_task + * @return int Exit code + */ + public function actionIndex() + { + $filePatch = __DIR__.'/../runtime/lock.lock'; + if(!file_exists($filePatch)) + { + $fp = fopen($filePatch, "w"); + fwrite($fp, ""); + fclose($fp); + } + $file = fopen($filePatch, 'r+'); + + if (flock($file, LOCK_EX | LOCK_NB)) + { + $model = new MoleTask; + $tasks = $model->getAllTask(); + foreach ($tasks as $task) + { + try + { + $task->dateStart = date('Y-m-d H:i:s'); + $task->save(); + $class = 'app\commands\\' . $task->controller; + if (class_exists($class)) + { + $control = new $class($task->controller, 'product'); + $control->actionIndex(unserialize($task->params)); + } + $task->dateEnd = date('Y-m-d H:i:s'); + $task->completed = 1; + $task->save(); + } catch (\yii\elasticsearch\Exception $ex) + { + $task->dateStart = null; + $task->save(); + print_r($ex); + } + } + } + return ExitCode::OK; + } + +} diff --git a/messages/message.php b/messages/message.php index 24adeb3..44daf6c 100644 --- a/messages/message.php +++ b/messages/message.php @@ -1,5 +1,6 @@ __DIR__ . '/../', 'messagePath' => __DIR__, diff --git a/messages/ru-RU/mole.php b/messages/ru-RU/mole.php index 3fb021c..e8e7370 100644 --- a/messages/ru-RU/mole.php +++ b/messages/ru-RU/mole.php @@ -1,4 +1,5 @@ 'wwww', + "ID" => 'wwww111', + 'Task List' => 'Список задач' ]; \ No newline at end of file diff --git a/views/default/index.php b/views/default/index.php index a8d3503..c80d368 100644 --- a/views/default/index.php +++ b/views/default/index.php @@ -19,8 +19,7 @@ use yii\widgets\Pjax; * @var \yii\data\ActiveDataProvider $dataProvider * @var \dektrium\user\models\UserSearch $searchModel */ -$this->title = Yii::t('app', 'User List'); -$this->params['breadcrumbs'][] = ['label' => Yii::t('user', 'Manage users'), 'url' => ['']]; +$this->title = Yii::t('mole', 'Task List'); $this->params['breadcrumbs'][] = $this->title; ?>