setDescription('Setup dbs for tests environment'); } 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.' )); } $settings = Yaml::parse(file_get_contents(__DIR__ . '/../../../../../resources/hudson/InstallDBs.yml')); $dbs = array(); $dbs[] = $settings['database']['ab_name']; $dbs[] = $settings['database']['db_name']; $schema = $this->container['orm.em']->getConnection()->getSchemaManager(); foreach($dbs as $name) { $output->writeln('Creating database "'.$name.'"...OK'); $schema->dropAndCreateDatabase($name); } $this->container['orm.em']->getConnection()->executeUpdate(' GRANT ALL PRIVILEGES ON '.$settings['database']['ab_name'].'.* TO \''.$settings['database']['user'].'\'@\''.$settings['database']['host'].'\' IDENTIFIED BY \''.$settings['database']['password'].'\' WITH GRANT OPTION '); $this->container['orm.em']->getConnection()->executeUpdate(' GRANT ALL PRIVILEGES ON '.$settings['database']['db_name'].'.* TO \''.$settings['database']['user'].'\'@\''.$settings['database']['host'].'\' IDENTIFIED BY \''.$settings['database']['password'].'\' WITH GRANT OPTION '); $this->container['orm.em']->getConnection()->executeUpdate('SET @@global.sql_mode= ""'); return 0; } }