setDescription('Reset environment') ->addOption('name', null, InputOption::VALUE_OPTIONAL, 'Databox name to reset, in case of multiple databox are mounted', null) ->addOption('dependencies', null, InputOption::VALUE_NONE, 'Fetch dependencies', null) ->addOption('v3.1', null, InputOption::VALUE_NONE, 'Reset with v3.1 fixtures', null) ->addOption('uninstall', null, InputOption::VALUE_NONE, 'Uninstall Phraseanet', null); ; } protected function doExecute(InputInterface $input, OutputInterface $output) { if (!$this->container['phraseanet.configuration']->isSetup()) { throw new RuntimeException(sprintf( 'Phraseanet is not setup. You can run bin/setup system::install command to install Phraseanet.' )); } // get dbs $conf = $this->container['phraseanet.configuration']->getConfig(); $dbs = array('ab' => $conf['main']['database']['dbname'], 'dbs' => array(), 'setup_dbs' => array()); foreach($this->container['phraseanet.appbox']->get_databoxes() as $databox) { $dbs['dbs'][] = $databox->get_dbname(); } //uninstall if ($input->getOption('uninstall')) { $command = $this->getApplication()->find('system:uninstall'); $output->writeln('Uninstalling...OK'); $input = new ArrayInput(array( 'command' => 'system:uninstall' )); $command->run($input, $output); } //run composer //run bower if ($input->getOption('dependencies')) { $command = $this->getApplication()->find('dependencies:composer'); $input = new ArrayInput(array( 'command' => 'dependencies:composer' )); $command->run($input, $output); $command = $this->getApplication()->find('dependencies:bower'); $input = new ArrayInput(array( 'command' => 'dependencies:bower' )); $command->run($input, $output); } if (count($dbs['dbs']) > 1) { if ($input->getOption('name')) { $dbName = $input->getOption('name'); } else { $dialog = $this->getHelperSet()->get('dialog'); $dbName = $dialog->ask( $output, _('Please enter the databox name to reset') ); } } else { $dbName = current($dbs['dbs']); } $schema = $this->container['EM']->getConnection()->getSchemaManager(); $output->writeln('Creating database "'.$dbs['ab'].'"...OK'); $schema->dropAndCreateDatabase($dbs['ab']); $output->writeln('Creating database "'.$dbName.'"...OK'); $schema->dropAndCreateDatabase($dbName); // inject v3.1 fixtures if ($input->getOption('v3.1')) { $this->container['filesystem']->copy($this->container['root.path'].'/hudson/connexion.inc', $this->container['root.path'].'/config/connexion.inc'); $this->container['filesystem']->copy($this->container['root.path'].'/hudson/_GV.php', $this->container['root.path'].'/config/_GV.php'); $command = $this->getApplication()->find('dbal:import'); $content = file_get_contents($this->container['root.path'] . '/hudson/fixtures.sql'); $content = str_replace('ab_test', $dbs['ab'], $content); $content = str_replace('db_test', $dbName, $content); $tmpFile = tempnam(sys_get_temp_dir(), 'fixtures-v3.1-'); $this->container['filesystem']->dumpFile($tmpFile, $content); $input = new ArrayInput(array( 'command' => 'dbal:import', 'file' => $tmpFile )); $verbosity = $output->getVerbosity(); $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); $command->run($input, $output); $output->setVerbosity($verbosity); $output->writeln('Importing Phraseanet v3.1 fixtures...OK'); } // create setup dbs $command = $this->getApplication()->find('ini:setup-tests-dbs'); $input = new ArrayInput(array( 'command' => 'ini:setup-tests-dbs' )); $command->run($input, $output); return 0; } }