/** * Returns an array of string. They are the absolute pathes of the evolution files.<br> * The files must have the .sql extension and the name must be a numeric.<br> * Example: * <ul> * <li>1.sql</li> * <li>2.sql</li> * </ul> * * @param string $path Relative path to the folder containing the evolutions. * @return \string[] List of absolute path of the evolution files. * @throws FileNotFoundException */ public static function getList($path) { $absolutePath = $path; $workingFolder = getcwd(); if (file_exists($absolutePath) == false) { $absolutePath = realpath(sprintf('%s/%s', $workingFolder, $path)); } if (file_exists($absolutePath) === false) { throw new FileNotFoundException($absolutePath); } $dh = opendir($absolutePath); $files = array(); while (false !== ($filename = readdir($dh))) { if (in_array($filename, array('.', '..'))) { continue; } if (StringBook::is($filename)->endsWith('.sql') === false) { continue; } $basename = basename($filename, '.sql'); if (is_numeric($basename) === false) { continue; } $files[] = realpath(sprintf('%s%s%s', $absolutePath, DIRECTORY_SEPARATOR, $filename)); } return $files; }
public function run() { $controller = null; try { $this->checkArgumentCount(); $this->checkCommand(); $settingsFilePath = null; $evolutionsFolderPath = null; $to = null; for ($k = 0; $k < count($this->argumentList); $k++) { $currentArgument = $this->argumentList[$k]; if (StringBook::is($currentArgument)->startsWith(CommandLineArgument::ARGUMENT_SETTINGS_FILE_PATH)) { $settingsFilePath = substr($currentArgument, strlen(CommandLineArgument::ARGUMENT_SETTINGS_FILE_PATH)); continue; } if (StringBook::is($currentArgument)->startsWith(CommandLineArgument::ARGUMENT_EVOLUTIONS_FOLDER_PATH)) { $evolutionsFolderPath = substr($currentArgument, strlen(CommandLineArgument::ARGUMENT_EVOLUTIONS_FOLDER_PATH)); continue; } if (StringBook::is($currentArgument)->startsWith(CommandLineArgument::ARGUMENT_TO)) { $to = substr($currentArgument, strlen(CommandLineArgument::ARGUMENT_TO)); continue; } } if ($settingsFilePath == null || $evolutionsFolderPath == null) { throw new \Exception(sprintf('Command, %s and %s are mandatory.', CommandLineArgument::ARGUMENT_EVOLUTIONS_FOLDER_PATH, CommandLineArgument::ARGUMENT_SETTINGS_FILE_PATH)); } switch ($this->command) { case CommandLineArgument::COMMAND_INIT: $controller = new InitController($settingsFilePath, $evolutionsFolderPath, $to); $controller->init(); break; case CommandLineArgument::COMMAND_APPLY: $controller = new ApplyController($settingsFilePath, $evolutionsFolderPath, $to); $controller->apply(); break; case CommandLineArgument::COMMAND_REVERT: $controller = new RevertController($settingsFilePath, $evolutionsFolderPath, $to); $controller->revert(); break; } } catch (\Exception $ex) { echo PHP_EOL; echo "There were some errors:"; echo PHP_EOL; echo sprintf("\t - %s", $ex->getMessage()); echo PHP_EOL; } finally { try { if ($controller != null) { $controller->getDriver()->close(); } } catch (\Exception $ex) { } } }