Exemplo n.º 1
0
 /**
  * Update database schema according to models metadata.
  *
  * @param string|null $model   Model name to update. Example: \Test\Model\Class.
  * @param bool        $cleanup Cleanup database? Drop not related tables.
  *
  * @return void
  */
 public function updateAction($model = null, $cleanup = false)
 {
     $schema = new Schema($this->getDI());
     if ($model) {
         if (!class_exists($model)) {
             print ConsoleUtil::error('Model with class "' . $model . '" doesn\'t exists.') . PHP_EOL;
             return;
         }
         $count = current($schema->updateTable($model));
         if ($count) {
             print ConsoleUtil::headLine('Table update for model: ' . $model);
             print ConsoleUtil::commandLine('Executed queries:', $count, ConsoleUtil::FG_CYAN);
         } else {
             print ConsoleUtil::success('Table is up to date');
         }
         print PHP_EOL;
     } else {
         $queriesCount = $schema->updateDatabase($cleanup);
         if (!empty($queriesCount)) {
             print ConsoleUtil::headLine('Database update:');
             foreach ($queriesCount as $model => $count) {
                 print ConsoleUtil::commandLine($model . ':', $count, ConsoleUtil::FG_CYAN);
             }
         } else {
             print ConsoleUtil::success('Database is up to date');
         }
         print PHP_EOL;
     }
 }
Exemplo n.º 2
0
 /**
  * Remove widgets if their is unused.
  *
  * @param array $widgets Widgets list.
  *
  * @return void
  */
 protected function _removeUnusedWidgets($widgets)
 {
     // Get widgets from databases.
     print ConsoleUtil::headLine('Checking unused widgets...');
     foreach (Widget::find() as $widget) {
         if (!in_array($widget->name, $widgets)) {
             $this->_info('Removing unused widget: ' . $widget->name . PHP_EOL);
             $widget->delete();
         }
     }
     print PHP_EOL;
 }
Exemplo n.º 3
0
 /**
  * Output available commands.
  *
  * @return void
  */
 public function printAvailableCommands()
 {
     print ConsoleUtil::headLine('Available commands:');
     foreach ($this->_commands as $command) {
         print ConsoleUtil::commandLine(join(', ', $command->getCommands()), $command->getDescription());
     }
     print PHP_EOL;
 }
Exemplo n.º 4
0
 /**
  * Prints the available options in the script.
  *
  * @param string $action Action name.
  *
  * @throws CommandsException
  * @return void
  */
 public function printParameters($action)
 {
     if (!$action) {
         return;
     }
     if (empty($this->_actions[$action])) {
         throw new CommandsException("Action '{$action}' not found in this command.");
     }
     if (empty($this->_actions[$action]['params'])) {
         return;
     }
     print ConsoleUtil::headLine('Available parameters:');
     foreach ($this->_actions[$action]['params'] as $parameter) {
         $cmd = ' --' . $parameter['name'];
         $type = '';
         if ($parameter['defaultValueType'] != 'boolean') {
             $cmd .= '=' . $parameter['defaultValueType'];
             $type = ' (' . $parameter['type'] . ')';
         }
         print '  ';
         print ConsoleUtil::colorize($cmd, ConsoleUtil::FG_CYAN);
         print ConsoleUtil::colorize($type, ConsoleUtil::FG_YELLOW);
         print ConsoleUtil::tab(ConsoleUtil::COMMENT_START_POSITION, strlen($cmd . $type) + 6);
         print ConsoleUtil::colorize($parameter['description'], ConsoleUtil::FG_BROWN);
         print PHP_EOL;
     }
 }