public function run($options = array()) { Yentu::greet(); $db = DatabaseManipulator::create(); DatabaseItem::setDriver($db); ChangeReverser::setDriver($db); $previousMigration = ''; if (isset($options['default-schema'])) { $this->schemaCondition = "default_schema = ?"; $this->schemaConditionData[] = $options['default-schema']; } if (empty($options)) { $session = $db->getLastSession(); $operations = $db->query("SELECT id, method, arguments, migration, default_schema FROM yentu_history WHERE {$this->schemaCondition} session = ? ORDER BY id DESC", $this->schemaConditionData + [$session]); } else { $operations = []; foreach ($options['stand_alones'] as $set) { $operations += $this->getOperations($db, $set); } } foreach ($operations as $operation) { if ($previousMigration !== $operation['migration']) { ClearIce::output("Rolling back '{$operation['migration']}' migration" . ($operation['default_schema'] != '' ? " on `{$operation['default_schema']}` schema." : ".") . "\n"); $previousMigration = $operation['migration']; } ChangeReverser::call($operation['method'], json_decode($operation['arguments'], true)); $db->query('DELETE FROM yentu_history WHERE id = ?', array($operation['id'])); } }
public function run($options = array()) { Yentu::greet(); $this->db = DatabaseManipulator::create(); $this->initializeCodeWriter(); $files = scandir(Yentu::getPath("migrations")); if (count($files) > 2) { throw new \yentu\exceptions\CommandException("Cannot run imports. Your migrations directory is not empty"); } $description = $this->db->getDescription(); $this->code->add('begin()'); if (isset($description['schemata'])) { $this->importSchemata($description['schemata']); } if (isset($description['tables'])) { $this->importTables($description['tables']); } if (isset($description['views'])) { $this->importViews($description['views']); } $this->importForeignKeys(); $this->code->add('->end();'); $this->newVersion = date('YmdHis', time()); $path = Yentu::getPath("migrations/{$this->newVersion}_import.php"); file_put_contents($path, $this->code); \clearice\ClearIce::output("Created `{$path}`\n"); if (!$this->db->getAssertor()->doesTableExist('yentu_history')) { $this->db->createHistory(); } $this->db->setVersion($this->newVersion); $this->db->disconnect(); return $description; }
private function displayMigrations($descriptions) { foreach ($descriptions as $description) { if (trim($description) == '') { continue; } ClearIce::output(" {$description}\n"); } }
public function testLevelThreshold() { ClearIce::setOutputLevel(ClearIce::OUTPUT_LEVEL_0); ClearIce::output("Hello"); $this->assertFileNotExists($this->stdout); ClearIce::setOutputLevel(ClearIce::OUTPUT_LEVEL_1); ClearIce::output("Hello\n"); $this->assertStringEqualsFile($this->stdout, "Hello\n"); }
public function runTask($options) { ClearIce::output("Setting up app namespace {$options['namespace']} ... "); Filesystem::createDirectoryStructure(['src' => ['modules' => ['home'], 'lib'], 'config', 'logs', 'views' => ['default', 'home']], './'); $data = ['namespace' => $options['namespace'], 'date' => date("Y-m-d H:i:s")]; $this->writeFile(__DIR__ . "/../../code_templates/misc/htaccess.template", $data, '.htaccess'); $this->writeFile(__DIR__ . "/../../code_templates/php/index.php.template", $data, 'index.php'); $this->writeFile(__DIR__ . "/../../code_templates/php/HomeController.php.template", $data, 'src/modules/home/HomeController.php'); $this->writeFile(__DIR__ . "/../../code_templates/php/home_index.tpl.php.template", $data, 'views/default/home_index.tpl.php'); $this->writeFile(__DIR__ . "/../../code_templates/php/main.tpl.php.template", $data, 'views/default/main.tpl.php'); ClearIce::output("OK\n"); }
public function query($query, $bind = false) { try { if ($this->dumpQuery) { echo "{$query}\n"; } ClearIce::output("\n > Running Query [{$query}]", ClearIce::OUTPUT_LEVEL_3); if ($this->disableQuery !== true) { return $this->connection->query($query, $bind); } } catch (\ntentan\atiaa\exceptions\DatabaseDriverException $e) { throw new exceptions\DatabaseManipulatorException($e->getMessage()); } }
public function createFile($name) { $this->checkExisting($name); $this->checkName($name); $this->checkPermission(); $timestamp = date('YmdHis', time()); $code = new \yentu\CodeWriter(); $code->add(''); $code->add('begin()'); $code->add(''); $code->add('->end();'); $path = Yentu::getPath("migrations/{$timestamp}_{$name}.php"); file_put_contents($path, $code); \clearice\ClearIce::output("Added {$path} for new migration.\n"); }
public function run($options) { ClearIce::output("Stopping ajumamoro daemon ... "); $options = Configuration::init($options); $pidFile = Configuration::get('pid_file', './ajumamoro.pid'); if (file_exists($pidFile) && is_readable($pidFile)) { $pid = file_get_contents($pidFile); if (posix_kill($pid, SIGTERM)) { unlink($pidFile); ClearIce::output("OK\n"); } else { ClearIce::output("Failed\nCould not kill running instance.\n"); } } else { ClearIce::output("Failed\nNo instances detected.\n"); } }
public function run($options) { if (isset($options['config'])) { Config::readPath($options['config'], 'ajumamoro'); } if ($options['daemon'] === true) { ClearIce::output("Starting ajumamoro daemon ... "); Logger::init(Config::get('ajumamoro:log_file', './ajumamoro.log'), 'ajumamoro'); if ($this->checkExistingInstance() === false) { $pid = $this->startDaemon($options); ClearIce::output($pid > 0 ? "OK [PID:{$pid}]\n" : "Failed\n"); } else { ClearIce::output("Failed\nAn instance already exists.\n"); } } else { Logger::init('php://output', 'ajumamoro'); Runner::mainLoop(); } }
/** * Display the greeting for the CLI user interface. */ public static function greet() { $version = Yentu::getVersion(); $welcome = <<<WELCOME Yentu Database Migration Tool Version {$version} WELCOME; ClearIce::output($welcome); }
public function run($options) { \clearice\ClearIce::output(json_encode($options)); }
public function reverse() { if ($this->driver === null) { return; } ClearIce::output("Attempting to reverse all changes ... "); if ($this->getChanges() > 0) { ClearIce::pushOutputLevel(0); $rollback = new \yentu\commands\Rollback(); $rollback->run(array()); ClearIce::popOutputLevel(); } ClearIce::output("OK\n"); }
$options = ClearIce::parse(); if (isset($options['verbose'])) { ClearIce::setOutputLevel($options['verbose']); } try { if (isset($options['__command__'])) { if (isset($options['home'])) { Yentu::setDefaultHome($options['home']); } $class = "\\yentu\\commands\\" . ucfirst($options['__command__']); unset($options['__command__']); Config::readPath(Yentu::getPath('config'), 'yentu'); $command = new $class(); $command->run($options); } else { ClearIce::output(ClearIce::getHelpMessage()); } } catch (\yentu\exceptions\CommandException $e) { ClearIce::resetOutputLevel(); ClearIce::error("Error! " . $e->getMessage() . "\n"); } catch (\ntentan\atiaa\exceptions\DatabaseDriverException $e) { ClearIce::resetOutputLevel(); ClearIce::error("Database driver failed: " . $e->getMessage() . "\n"); Yentu::reverseCommand($command); } catch (\yentu\exceptions\DatabaseManipulatorException $e) { ClearIce::resetOutputLevel(); ClearIce::error("Failed to perform database action: " . $e->getMessage() . "\n"); Yentu::reverseCommand($command); } catch (\ntentan\atiaa\DescriptionException $e) { ClearIce::resetOutputLevel(); ClearIce::error("Failed to perform database action: " . $e->getMessage() . "\n");
public function run($options = array()) { Yentu::greet(); if (file_exists(Yentu::getPath(''))) { throw new CommandException("Could not initialize yentu. Your project has already been initialized with yentu."); } else { if (!is_writable(dirname(Yentu::getPath('')))) { throw new CommandException("Your current directory is not writable."); } } $params = $this->getParams($options); if (count($params) == 0 && defined('STDOUT')) { global $argv; throw new CommandException("You didn't provide any parameters for initialization. Please execute " . "`{$argv[0]} init -i` to initialize yentu interractively. " . "You can also try `{$argv[0]} init --help` for more information."); } $this->createConfigFile($params); Config::readPath(Yentu::getPath('config'), 'yentu'); $db = \yentu\DatabaseManipulator::create($params); if ($db->getAssertor()->doesTableExist('yentu_history')) { throw new CommandException("Could not initialize yentu. Your database has already been initialized with yentu."); } $db->createHistory(); $db->disconnect(); ClearIce::output("Yentu successfully initialized.\n"); }
public function outputProgress() { if ($this->expectedOperations > 0) { if ($this->operations % 74 === 0) { ClearIce::output(sprintf("%4d%%\n", $this->operations / $this->expectedOperations * 100)); } else { ClearIce::output(sprintf("%4d%%\n", $this->operations / $this->expectedOperations * 100), ClearIce::OUTPUT_LEVEL_2); } } }