/** * 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; } }
/** * 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; }
/** * Prints the help for current command. * * @param string|null $action Action name. * * @return void */ public function getHelp($action = null) { $commandName = $this->getName(); if ($action) { if (empty($this->_actions[$action])) { print ConsoleUtil::warningLine("Action '{$action}' not found in this command."); return; } print ConsoleUtil::headLine('Help for "' . $commandName . ' ' . $action . '":'); if (isset($this->_actions[$action]) && isset($this->_actions[$action]['description'])) { print ConsoleUtil::textLine($this->_actions[$action]['description']); } else { print ConsoleUtil::textLine($this->getDescription()); } $this->printParameters($action); return; } else { print ConsoleUtil::headLine('Help:'); print ConsoleUtil::textLine($this->getDescription()); } foreach ($this->getActions() as $actionName => $metadata) { $description = isset($metadata['description']) ? $metadata['description'] : ''; print ConsoleUtil::commandLine($commandName . ' ' . $actionName, $description); } print PHP_EOL; }