示例#1
0
 /**
  * Снимаем онлайн у тех, у кого за последнее время активность == 0
  */
 public function actionRefreshOnline()
 {
     $oldTime = time() - \Yii::$app->params['onlineLength'];
     $userUpdated = User::updateAll(['<=', 'updated', $oldTime]);
     $this->stdout(Console::wrapText("- {$userUpdated} отправлено в оффлайн", 10), Console::BOLD);
     $this->stdout("\n");
 }
 /**
  * Удаление старыъ записей (сессии, логов)
  */
 public function actionGarbageCollector()
 {
     $logMain = LogMain::deleteAll(['<=', 'created', time() - Time::SEC_TO_MONTH]);
     $session = Session::deleteAll(['<=', 'expire', time() - \Yii::$app->session->getTimeout()]);
     $this->stdout('- ' . $this->ansiFormat(LogMain::tableName(), Console::FG_YELLOW));
     $this->stdout(' ');
     $this->stdout(Console::wrapText("удалено {$logMain} записей", 10), Console::BOLD);
     $this->stdout("\n");
     $this->stdout('- ' . $this->ansiFormat(Session::tableName(), Console::FG_YELLOW));
     $this->stdout(' ');
     $this->stdout(Console::wrapText("удалено {$session} записей", 10), Console::BOLD);
     $this->stdout("\n");
 }
示例#3
0
 public function actionNormalize()
 {
     /**
      * @var $tag Tag
      */
     $updated = 0;
     $deleted = 0;
     $list = [];
     foreach (Tag::find()->each() as $tag) {
         $name = mb_strtolower($tag->name);
         if (isset($list[$name])) {
             TagEvent::updateAll(['tag_id' => $list[$name]], ['tag_id' => $tag->id]);
             $tag->delete();
             $deleted++;
             continue;
         }
         $list[$name] = $tag->id;
     }
     $this->stdout(Console::wrapText("- {$updated} updated, {$deleted} deleted", 10), Console::BOLD);
     $this->stdout("\n");
 }
示例#4
0
 /**
  * Displays the overall information of the command.
  * @param Controller $controller the controller instance
  */
 protected function getCommandHelp($controller)
 {
     $controller->color = $this->color;
     $this->stdout("\nDESCRIPTION\n", Console::BOLD);
     $comment = $controller->getHelp();
     if ($comment !== '') {
         $this->stdout("\n{$comment}\n\n");
     }
     $actions = $this->getActions($controller);
     if (!empty($actions)) {
         $this->stdout("\nSUB-COMMANDS\n\n", Console::BOLD);
         $prefix = $controller->getUniqueId();
         $maxlen = 5;
         foreach ($actions as $action) {
             $len = strlen($prefix . '/' . $action) + 2 + ($action === $controller->defaultAction ? 10 : 0);
             if ($maxlen < $len) {
                 $maxlen = $len;
             }
         }
         foreach ($actions as $action) {
             $this->stdout('- ' . $this->ansiFormat($prefix . '/' . $action, Console::FG_YELLOW));
             $len = strlen($prefix . '/' . $action) + 2;
             if ($action === $controller->defaultAction) {
                 $this->stdout(' (default)', Console::FG_GREEN);
                 $len += 10;
             }
             $summary = $controller->getActionHelpSummary($controller->createAction($action));
             if ($summary !== '') {
                 $this->stdout(str_repeat(' ', $maxlen - $len + 2) . Console::wrapText($summary, $maxlen + 2));
             }
             $this->stdout("\n");
         }
         $scriptName = $this->getScriptName();
         $this->stdout("\nTo see the detailed information about individual sub-commands, enter:\n");
         $this->stdout("\n  {$scriptName} " . $this->ansiFormat('help', Console::FG_YELLOW) . ' ' . $this->ansiFormat('<sub-command>', Console::FG_CYAN) . "\n\n");
     }
 }
示例#5
0
 /**
  * Displays all available commands.
  */
 protected function getDefaultHelp()
 {
     $commands = $this->getCommandDescriptions();
     $this->stdout("\nThis is Yii version " . \Yii::getVersion() . ".\n");
     if (!empty($commands)) {
         $this->stdout("\nThe following commands are available:\n\n", Console::BOLD);
         $len = 0;
         foreach ($commands as $command => $description) {
             $result = Yii::$app->createController($command);
             if ($result !== false) {
                 /** @var $controller Controller */
                 list($controller, $actionID) = $result;
                 $actions = $this->getActions($controller);
                 if (!empty($actions)) {
                     $prefix = $controller->getUniqueId();
                     foreach ($actions as $action) {
                         $string = $prefix . '/' . $action;
                         if ($action === $controller->defaultAction) {
                             $string .= ' (default)';
                         }
                         if (($l = strlen($string)) > $len) {
                             $len = $l;
                         }
                     }
                 }
             } elseif (($l = strlen($command)) > $len) {
                 $len = $l;
             }
         }
         foreach ($commands as $command => $description) {
             $this->stdout('- ' . $this->ansiFormat($command, Console::FG_YELLOW));
             $this->stdout(str_repeat(' ', $len + 4 - strlen($command)));
             $this->stdout(Console::wrapText($description, $len + 4 + 2), Console::BOLD);
             $this->stdout("\n");
             $result = Yii::$app->createController($command);
             if ($result !== false) {
                 list($controller, $actionID) = $result;
                 $actions = $this->getActions($controller);
                 if (!empty($actions)) {
                     $prefix = $controller->getUniqueId();
                     foreach ($actions as $action) {
                         $string = '  ' . $prefix . '/' . $action;
                         $this->stdout('  ' . $this->ansiFormat($string, Console::FG_GREEN));
                         if ($action === $controller->defaultAction) {
                             $string .= ' (default)';
                             $this->stdout(' (default)', Console::FG_YELLOW);
                         }
                         $summary = $controller->getActionHelpSummary($controller->createAction($action));
                         if ($summary !== '') {
                             $this->stdout(str_repeat(' ', $len + 4 - strlen($string)));
                             $this->stdout(Console::wrapText($summary, $len + 4 + 2));
                         }
                         $this->stdout("\n");
                     }
                 }
                 $this->stdout("\n");
             }
         }
         $scriptName = $this->getScriptName();
         $this->stdout("\nTo see the help of each command, enter:\n", Console::BOLD);
         $this->stdout("\n  {$scriptName} " . $this->ansiFormat('help', Console::FG_YELLOW) . ' ' . $this->ansiFormat('<command-name>', Console::FG_CYAN) . "\n\n");
     } else {
         $this->stdout("\nNo commands are found.\n\n", Console::BOLD);
     }
 }