/** * Returns the connection name that should be used for the migrations. * * @param Symfony\Component\Console\Input\InputInterface $input the input object * @return string */ protected function getConnectionName(InputInterface $input) { $connection = 'default'; if ($input->getOption('connection')) { $connection = $this->input->getOption('connection'); } return $connection; }
/** * Overrides the original method from phinx in order to return a tailored * Config object containing the connection details for the database. * * @return Phinx\Config\Config */ public function getConfig() { if ($this->configuration) { return $this->configuration; } $folder = 'Migrations'; if ($this->input->getOption('source')) { $folder = $this->input->getOption('source'); } $dir = ROOT . DS . 'config' . DS . $folder; $plugin = null; if ($this->input->getOption('plugin')) { $plugin = $this->input->getOption('plugin'); $dir = Plugin::path($plugin) . 'config' . DS . $folder; } if (!is_dir($dir)) { mkdir($dir, 0777, true); } $plugin = $plugin ? Inflector::underscore($plugin) . '_' : ''; $plugin = str_replace(array('\\', '/', '.'), '_', $plugin); $connection = 'default'; if ($this->input->getOption('connection')) { $connection = $this->input->getOption('connection'); } $config = ConnectionManager::config($connection); return $this->configuration = new Config(['paths' => ['migrations' => $dir], 'environments' => ['default_migration_table' => $plugin . 'phinxlog', 'default_database' => 'default', 'default' => ['adapter' => $this->getAdapterName($config['driver']), 'host' => isset($config['host']) ? $config['host'] : null, 'user' => isset($config['username']) ? $config['username'] : null, 'pass' => isset($config['password']) ? $config['password'] : null, 'port' => isset($config['port']) ? $config['port'] : null, 'name' => $config['database'], 'charset' => $config['encoding']]]]); }