<commit_before><?php

namespace TwentyFifth\Migrations\Command;

use TwentyFifth\Migrations\Manager\SchemaManager;
use TwentyFifth\Migrations\Manager\FileManager;

use Symfony\Component\Console;
use Bisna\Doctrine\Container as DoctrineContainer;

abstract class AbstractCommand
	extends Console\Command\Command
{
	private $bisna_container;

	/* @var \Zend_Config */
	private $config;

	/** @var SchemaManager */
	protected $schema_manager;

	/** @var FileManager */
	protected $file_manager;

	protected $errors = array();

	public function __construct($name = null)
	{
		parent::__construct($name);

		$this->config = new \Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);

		$this->bisna_container = new DoctrineContainer($this->config->resources->doctrine->toArray());
	}

	protected function outputErrorsAndExit(Console\Output\OutputInterface $output, $code = 1)
	{
		$output->writeln($this->errors);
		$output->writeln($this->getSynopsis());
		exit($code);
	}

	public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
	{
		try {
			$this->schema_manager = new SchemaManager($this->getConnection());
			$this->file_manager = new FileManager(APPLICATION_PATH . '/../docs/sql/');
		} catch (\Exception $e) {
			$this->errors[] = $e->getMessage();
			$this->outputErrorsAndExit($output, 1);
		}
	}

	/**
	 * @return \Doctrine\DBAL\Connection
	 */
	protected function getConnection()
	{
		return $this->bisna_container->getConnection();
	}

	protected function getMissingMigrations()
	{
		$all_migrations = $this->file_manager->getOrderedFileList();
		return $this->schema_manager->getNotAppliedMigrations($all_migrations);
	}
}<commit_msg>implement database override<commit_after><?php

namespace TwentyFifth\Migrations\Command;

use TwentyFifth\Migrations\Manager\SchemaManager;
use TwentyFifth\Migrations\Manager\FileManager;

use Symfony\Component\Console;
use Symfony\Component\Console\Input\InputOption;
use Bisna\Doctrine\Container as DoctrineContainer;

abstract class AbstractCommand
	extends Console\Command\Command
{
	private $bisna_container;

	/* @var \Zend_Config */
	private $config;

	/** @var SchemaManager */
	protected $schema_manager;

	/** @var FileManager */
	protected $file_manager;

	protected $errors = array();

	public function __construct($name = null)
	{
		parent::__construct($name);

		$this->addOption('database',null,InputOption::VALUE_REQUIRED,'Override Database');

		$this->config = new \Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
	}

	protected function outputErrorsAndExit(Console\Output\OutputInterface $output, $code = 1)
	{
		$output->writeln($this->errors);
		$output->writeln($this->getSynopsis());
		exit($code);
	}

	public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
	{
		$database = (string) $input->getOption('database');

		try {
			$this->schema_manager = new SchemaManager($this->getConnection($database));
			$this->file_manager = new FileManager(APPLICATION_PATH . '/../docs/sql/');
		} catch (\Exception $e) {
			$this->errors[] = $e->getMessage();
			$this->outputErrorsAndExit($output, 1);
		}
	}

	/**
	 * get Config as an Array with the possibility to override the database name
	 *
	 * @param string $database
	 *
	 * @return array
	 */
	protected function getConfig($database = '')
	{
		$config = $this->config->resources->doctrine->toArray();
		if (strlen(trim($database)) == 0) {
			return $config;
		}

		// override database name
		$defaultConnection = $config['dbal']['defaultConnection'];
		$config['dbal']['connections'][$defaultConnection]['parameters']['dbname'] = $database;
		return $config;
	}

	/**
	 * @param string $database
	 *
	 * @return \Doctrine\DBAL\Connection
	 */
	protected function getConnection($database)
	{
		if (is_null($this->bisna_container)) {
			$this->bisna_container = new DoctrineContainer($this->getConfig($database));
		}
		return $this->bisna_container->getConnection();
	}

	protected function getMissingMigrations()
	{
		$all_migrations = $this->file_manager->getOrderedFileList();
		return $this->schema_manager->getNotAppliedMigrations($all_migrations);
	}
}
{'fraction_non_alphanumeric': 0.14789398958826314, 'fraction_numerical': 0.001183151916706105, 'mean_word_length': 5.1798245614035086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5624618', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1297, 'n_words': 235}