2019-12-23 16:28:30 +03:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace dominion\cron;
|
|
|
|
|
|
2019-12-24 17:04:30 +03:00
|
|
|
|
use yii\base\BootstrapInterface;
|
|
|
|
|
use yii\i18n\PhpMessageSource;
|
2021-04-26 16:47:55 +03:00
|
|
|
|
use dominion\cron\models\MoleTask;
|
2019-12-24 17:04:30 +03:00
|
|
|
|
|
2019-12-23 16:28:30 +03:00
|
|
|
|
/**
|
|
|
|
|
* cron module definition class
|
|
|
|
|
*/
|
2019-12-24 17:04:30 +03:00
|
|
|
|
class Module extends \yii\base\Module implements BootstrapInterface
|
2019-12-23 16:28:30 +03:00
|
|
|
|
{
|
2019-12-24 17:04:30 +03:00
|
|
|
|
public $admins = [];
|
|
|
|
|
public $project = 'yii';
|
2019-12-23 16:28:30 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
2019-12-24 17:04:30 +03:00
|
|
|
|
public $controllerNamespace = 'dominion\cron\controllers';
|
2019-12-23 16:28:30 +03:00
|
|
|
|
|
2019-12-24 13:54:32 +03:00
|
|
|
|
public function bootstrap($app)
|
|
|
|
|
{
|
2019-12-24 17:04:30 +03:00
|
|
|
|
if ($app instanceof \yii\web\Application)
|
|
|
|
|
{
|
|
|
|
|
$app->getUrlManager()->addRules([
|
|
|
|
|
['class' => 'yii\web\UrlRule', 'pattern' => $this->id, 'route' => $this->id . '/default/index'],
|
|
|
|
|
['class' => 'yii\web\UrlRule', 'pattern' => $this->id . '/<id:\w+>', 'route' => $this->id . '/default/view'],
|
|
|
|
|
['class' => 'yii\web\UrlRule', 'pattern' => $this->id . '/<controller:[\w\-]+>/<action:[\w\-]+>', 'route' => $this->id . '/<controller>/<action>'],
|
|
|
|
|
], false);
|
|
|
|
|
}
|
|
|
|
|
elseif ($app instanceof \yii\console\Application)
|
|
|
|
|
{
|
2019-12-24 13:54:32 +03:00
|
|
|
|
$app->controllerMap[$this->id] = [
|
|
|
|
|
'class' => 'dominion\cron\console\MoleController',
|
2019-12-24 17:04:30 +03:00
|
|
|
|
// 'module' => $this,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isset($app->get('i18n')->translations['mole*']))
|
|
|
|
|
{
|
|
|
|
|
$app->get('i18n')->translations['mole*'] = [
|
|
|
|
|
'class' => PhpMessageSource::className(),
|
|
|
|
|
'basePath' => __DIR__ . '/messages',
|
|
|
|
|
'sourceLanguage' => 'en-US'
|
2019-12-24 13:54:32 +03:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-26 16:47:55 +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 function add($controller, $name, $params = array(), $priority = 0, $period = 0, $dateAdd = false, $project = false)
|
|
|
|
|
{
|
|
|
|
|
return MoleTask::add($controller, $name, $params, $priority, $period, $dateAdd, $project);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Выбираем все строки с project
|
|
|
|
|
*/
|
|
|
|
|
public function getAllTask($project = false)
|
|
|
|
|
{
|
|
|
|
|
$model = new MoleTask();
|
|
|
|
|
return $model->getAllTask($project);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-24 17:04:30 +03:00
|
|
|
|
|
2019-12-23 16:28:30 +03:00
|
|
|
|
}
|