/** * Run the command */ public function run($parameters) { if ($this->isReceivedOption('table')) { $tableName = $this->getOption('table'); } else { $tableName = 'all'; } $path = ''; if ($this->isReceivedOption('directory')) { $path = $this->getOption('directory') . '/'; } if ($this->isReceivedOption('migrations')) { $migrationsDir = $path . $this->getOption('migrations'); } else { $migrationsDir = $path . 'app/migrations'; } $exportData = $this->getOption('data'); $originalVersion = $this->getOption('version'); $action = $this->getOption(array('action', 1)); if ($action == 'generate') { Migrations::generate(array('directory' => $path, 'tableName' => $tableName, 'exportData' => $exportData, 'migrationsDir' => $migrationsDir, 'originalVersion' => $originalVersion, 'force' => $this->isReceivedOption('force'))); } else { if ($action == 'run') { Migrations::run(array('directory' => $path, 'migrationsDir' => $migrationsDir, 'force' => $this->isReceivedOption('force'))); } } }
/** * Generates migrations */ public function generateAction() { if ($this->request->isPost()) { $exportData = ''; $tableName = $this->request->getPost('table-name', 'string'); $version = $this->request->getPost('version', 'string'); $force = $this->request->getPost('force', 'int'); $migrationsDir = $this->_getMigrationsDir(); try { \Phalcon\Migrations::generate(array('config' => Tools::getConfig(), 'directory' => null, 'tableName' => $tableName, 'exportData' => $exportData, 'migrationsDir' => $migrationsDir, 'originalVersion' => $version, 'force' => $force)); $this->flash->success("The migration was generated successfully"); } catch (BuilderException $e) { $this->flash->error($e->getMessage()); } } return $this->dispatcher->forward(array('controller' => 'migrations', 'action' => 'index')); }
/** * {@inheritdoc} * * @param array $parameters * @return mixed */ public function run(array $parameters) { if ($this->isReceivedOption('table')) { $tableName = $this->getOption('table'); } else { $tableName = 'all'; } $path = ''; if ($this->isReceivedOption('directory')) { $path = $this->getOption('directory'); } $path = realpath($path) . DIRECTORY_SEPARATOR; if ($this->isReceivedOption('config')) { $config = $this->loadConfig($path . $this->getOption('config')); } else { $config = $this->getConfig($path); } if ($this->isReceivedOption('migrations')) { $migrationsDir = $path . $this->getOption('migrations'); } elseif (isset($config['application']['migrationsDir'])) { $migrationsDir = $config['application']['migrationsDir']; if (!$this->path->isAbsolutePath($migrationsDir)) { $migrationsDir = $path . $migrationsDir; } } else { if (file_exists($path . 'app')) { $migrationsDir = $path . 'app/migrations'; } elseif (file_exists($path . 'apps')) { $migrationsDir = $path . 'apps/migrations'; } else { $migrationsDir = $path . 'migrations'; } } $exportData = $this->getOption('data'); $originalVersion = $this->getOption('version'); $action = $this->getOption(array('action', 1)); $version = $this->getOption('version'); if ($action == 'generate') { Migrations::generate(array('directory' => $path, 'tableName' => $tableName, 'exportData' => $exportData, 'migrationsDir' => $migrationsDir, 'originalVersion' => $originalVersion, 'force' => $this->isReceivedOption('force'), 'no-ai' => $this->isReceivedOption('no-auto-increment'), 'config' => $config)); } else { if ($action == 'run') { Migrations::run(array('directory' => $path, 'tableName' => $tableName, 'migrationsDir' => $migrationsDir, 'force' => $this->isReceivedOption('force'), 'config' => $config, 'version' => $version)); } } }
/** * {@inheritdoc} * * @param array $parameters * * @return mixed */ public function run(array $parameters) { $path = $this->isReceivedOption('directory') ? $this->getOption('directory') : ''; $path = realpath($path) . DIRECTORY_SEPARATOR; if ($this->isReceivedOption('config')) { $config = $this->loadConfig($path . $this->getOption('config')); } else { $config = $this->getConfig($path); } if ($this->isReceivedOption('migrations')) { $migrationsDir = $path . $this->getOption('migrations'); } elseif (isset($config['application']['migrationsDir'])) { $migrationsDir = $config['application']['migrationsDir']; if (!$this->path->isAbsolutePath($migrationsDir)) { $migrationsDir = $path . $migrationsDir; } } elseif (file_exists($path . 'app')) { $migrationsDir = $path . 'app/migrations'; } elseif (file_exists($path . 'apps')) { $migrationsDir = $path . 'apps/migrations'; } else { $migrationsDir = $path . 'migrations'; } // keep migrations log in db // either "log-in-db" option or "logInDb" config variable from "application" block $migrationsInDb = false; if ($this->isReceivedOption('log-in-db')) { $migrationsInDb = true; } elseif (isset($config['application']['logInDb'])) { $migrationsInDb = $config['application']['logInDb']; } // migrations naming is timestamp-based rather than traditional, dotted versions // either "ts-based" option or "migrationsTsBased" config variable from "application" block $migrationsTsBased = false; if ($this->isReceivedOption('ts-based')) { $migrationsTsBased = true; } elseif (isset($config['application']['migrationsTsBased'])) { $migrationsTsBased = $config['application']['migrationsTsBased']; } $tableName = $this->isReceivedOption('table') ? $this->getOption('table') : 'all'; $descr = $this->getOption('descr'); $exportData = $this->getOption('data'); $action = $this->getOption(['action', 1]); $version = $this->getOption('version'); switch ($action) { case 'generate': Migrations::generate(['directory' => $path, 'tableName' => $tableName, 'exportData' => $exportData, 'migrationsDir' => $migrationsDir, 'version' => $version, 'force' => $this->isReceivedOption('force'), 'noAutoIncrement' => $this->isReceivedOption('no-auto-increment'), 'config' => $config, 'descr' => $descr]); break; case 'run': Migrations::run(['directory' => $path, 'tableName' => $tableName, 'migrationsDir' => $migrationsDir, 'force' => $this->isReceivedOption('force'), 'tsBased' => $migrationsTsBased, 'config' => $config, 'version' => $version, 'migrationsInDb' => $migrationsInDb]); break; case 'list': Migrations::listAll(['directory' => $path, 'tableName' => $tableName, 'migrationsDir' => $migrationsDir, 'force' => $this->isReceivedOption('force'), 'tsBased' => $migrationsTsBased, 'config' => $config, 'version' => $version, 'migrationsInDb' => $migrationsInDb]); break; } }