'Set migration namespace', '-g' => 'Set database group', '-all' => 'Set for all namespaces, will ignore (-n) option', ]; /** * Ensures that all migrations have been run. * * @param array $params */ public function run(array $params = []) { $runner = Services::migrations(); $runner->clearCliMessages(); CLI::write(lang('Migrations.latest'), 'yellow'); $namespace = $params['-n'] ?? CLI::getOption('n'); $group = $params['-g'] ?? CLI::getOption('g'); try { // Check for 'all' namespaces if ($this->isAllNamespace($params)) { $runner->setNamespace(null); } // Check for a specified namespace elseif ($namespace) { $runner->setNamespace($namespace); } if (! $runner->latest($group)) { CLI::write(lang('Migrations.generalFault'), 'red'); } $messages = $runner->getCliMessages(); foreach ($messages as $message) { CLI::write($message); } CLI::write('Done'); } catch (\Exception $e) { $this->showError($e); } } /** * To migrate all namespaces to the latest migration * * Demo: * 1. command line: php spark migrate:latest -all * 2. command file: $this->call('migrate:latest', ['-g' => 'test','-all']); * * @param array $params * @return boolean */ private function isAllNamespace(array $params): bool { if (array_search('-all', $params) !== false) { return true; } return ! is_null(CLI::getOption('all')); } }