setAliases(['generate']) ->setDescription('Generate a blank migration class.') ->addOption( 'namespace', null, InputOption::VALUE_REQUIRED, 'The namespace to use for the migration (must be in the list of configured namespaces)' ) ->setHelp(<<%command.name% command generates a blank migration class: %command.full_name% EOT ); parent::configure(); } protected function execute(InputInterface $input, OutputInterface $output): int { $configuration = $this->getDependencyFactory()->getConfiguration(); $migrationGenerator = $this->getDependencyFactory()->getMigrationGenerator(); $namespace = $input->getOption('namespace'); if ($namespace === '') { $namespace = null; } $dirs = $configuration->getMigrationDirectories(); if ($namespace === null) { $namespace = key($dirs); } elseif (! isset($dirs[$namespace])) { throw new Exception(sprintf('Path not defined for the namespace %s', $namespace)); } assert(is_string($namespace)); $fqcn = $this->getDependencyFactory()->getClassNameGenerator()->generateClassName($namespace); $path = $migrationGenerator->generateMigration($fqcn); $output->writeln($this->getOutput($path, $fqcn)); return 0; } /** * @param string $path * @param string $fqcn * @return array */ private function getOutput(string $path, string $fqcn): array { return [ sprintf('Generated new migration class to "%s"', realpath($path)), '', sprintf( 'To run just this migration for testing purposes, you can use sudo -u www-data php index.php \'\oat\tao\scripts\tools\Migrations\' -c execute -v \'%s\'', $fqcn ), '', sprintf( 'To revert the migration you can use sudo -u www-data php index.php \'\oat\tao\scripts\tools\Migrations\' -c rollback -v \'%s\'', $fqcn ), ]; } }