/** * Executa todos os migrations do phinx * * @param InputInterface $input * @param OutputInterface $output * @return bool|int|null */ protected function execute(InputInterface $input, OutputInterface $output) { $migrations = []; //migrations app $migrations[] = APPDIR . 'migrations'; //find migrations extensions $migrations_extensions = glob(Util::pathExtension() . '*/app/migrations', GLOB_ONLYDIR); $migrations = array_merge($migrations, $migrations_extensions); foreach ($migrations as $migration) { $migration = str_replace('//', '/', $migration); $_SERVER['PHINX_MIGRATION_PATH'] = $migration; //init phinx $app = new \Phinx\Console\PhinxApplication(); $wrap = new \Phinx\Wrapper\TextWrapper($app); //set parser $wrap->setOption('parser', 'php'); //set config file $wrap->setOption('configuration', APPDIR . 'phinx.php'); // Get the environment and target version parameters. $env = ENV; //execute migrate $output_func = $wrap->getMigrate($env); $output->writeln($output_func); } return true; }
public function action_get_index_collection() { $db = service('db.config'); $phinx_config = ['configuration' => realpath(APPPATH . '../application/phinx.php'), 'parser' => 'php']; $phinx_app = new Phinx\Console\PhinxApplication(); $phinx_wrapper = new Phinx\Wrapper\TextWrapper($phinx_app, $phinx_config); $migration_results = call_user_func([$phinx_wrapper, 'getMigrate'], 'ushahidi', null); $error = $phinx_wrapper->getExitCode() > 0; $this->_response_payload = ['results' => explode("\n", $migration_results, -1)]; }
public function action_get_index_collection($command = 'status') { $user = service('session.user'); if ('admin' != $user->role) { throw new HTTP_Exception_403('Must be an admin to access this service'); } $commands = ['status' => 'getStatus', 'rollback' => 'getRollback']; // add return status if invalid command is selected if (!array_key_exists($command, $commands)) { $command = 'status'; } $db = service('db.config'); $phinx_config = ['configuration' => realpath(APPPATH . '../application/phinx.php'), 'parser' => 'php']; $phinx_app = new Phinx\Console\PhinxApplication(); $phinx_wrapper = new Phinx\Wrapper\TextWrapper($phinx_app, $phinx_config); $migration_results = call_user_func([$phinx_wrapper, $commands[$command]], 'ushahidi', null); $error = $phinx_wrapper->getExitCode() > 0; $this->_response_payload = ['results' => explode("\n", $migration_results, -1)]; }
// This script can be run as a router with the built in PHP web server: // // php -S localhost:8000 app/web.php // // Or can be run from any other web server with: // // require 'phinx/app/web.php'; // // This script uses the following query string arguments: // // - (string) "e" environment name // - (string) "t" target version // - (boolean) "debug" enable debugging? // Get the phinx console application and inject it into TextWrapper. $app = (require __DIR__ . '/phinx.php'); $wrap = new Phinx\Wrapper\TextWrapper($app); // Mapping of route names to commands. $routes = ['status' => 'getStatus', 'migrate' => 'getMigrate', 'rollback' => 'getRollback']; // Extract the requested command from the URL, default to "status". $command = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'); if (!$command) { $command = 'status'; } // Verify that the command exists, or list available commands. if (!isset($routes[$command])) { $commands = implode(', ', array_keys($routes)); header('Content-Type: text/plain', true, 404); die("Command not found! Valid commands are: {$commands}."); } // Get the environment and target version parameters. $env = isset($_GET['e']) ? $_GET['e'] : null;