/** * Execute the Command * * @access protected * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { if (!file_exists(\Skeleton\Database\Migration\Config::$migration_directory)) { $output->writeln('<error>Config::$migration_directory is not set to a valid directory</error>'); return 1; } $migration = \Skeleton\Database\Migration::get_by_version($input->getArgument('name')); try { $migration->up(); $output->writeln(get_class($migration) . "\t" . ' <info>ok</info>'); } catch (\Exception $e) { $output->writeln(get_class($migration) . "\t" . ' <error>' . $e->getMessage() . '</error>'); return 1; } return 0; }
/** * Get specific version * * @access public * @param string $version * @return Migration */ public static function get_by_version($version) { $migrations = self::get_all(); if (strpos($version, '/') === false) { $version = 'project/' . $version; } list($package, $version) = explode('/', $version); $migrations = \Skeleton\Database\Migration::get_between_versions($package); foreach ($migrations as $migration) { if (preg_match('@\\\\([\\w]+)$@', get_class($migration), $matches)) { $classname = $matches[1]; } else { $classname = get_class($migration); } if ($version == $classname) { return $migration; } } throw new \Exception('The specified version does not exists.'); }