private function createConfigFile(Connection $abConn, $serverName, $binaryData, $dataPath) { $config = $this->app['configuration.store']->initialize()->getConfig(); $config['main']['database']['host'] = $abConn->getHost(); $config['main']['database']['port'] = $abConn->getPort(); $config['main']['database']['user'] = $abConn->getUsername(); $config['main']['database']['password'] = $abConn->getPassword(); $config['main']['database']['dbname'] = $abConn->getDatabase(); $config['main']['database']['driver'] = 'pdo_mysql'; $config['main']['database']['charset'] = 'UTF8'; $config['main']['binaries'] = $binaryData; $config['servername'] = $serverName; $config['main']['key'] = $this->app['random.medium']->generateString(16); if (null === ($dataPath = realpath($dataPath))) { throw new \InvalidArgumentException(sprintf('Path %s does not exist.', $dataPath)); } $config['main']['storage']['subdefs'] = $dataPath; $config['main']['storage']['cache'] = realpath(__DIR__ . '/../../../../cache'); $config['main']['storage']['log'] = realpath(__DIR__ . '/../../../../logs'); $config['main']['storage']['download'] = realpath(__DIR__ . '/../../../../tmp/download'); $config['main']['storage']['lazaret'] = realpath(__DIR__ . '/../../../../tmp/lazaret'); $config['main']['storage']['caption'] = realpath(__DIR__ . '/../../../../tmp/caption'); $config['registry'] = $this->app['registry.manipulator']->getRegistryData(); $this->app['configuration.store']->setConfig($config); }
private function getDBConn(InputInterface $input, OutputInterface $output, Connection $abConn, DialogHelper $dialog) { $dbConn = $template = $info = null; if (!$input->getOption('databox')) { do { $retry = false; $dbName = $dialog->ask($output, 'DataBox name, will not be created if empty : ', null); if ($dbName) { try { $info = ['host' => $abConn->getHost(), 'port' => $abConn->getPort(), 'user' => $abConn->getUsername(), 'password' => $abConn->getPassword(), 'dbname' => $dbName]; $dbConn = $this->container['dbal.provider']($info); $dbConn->connect(); $output->writeln("\n\t<info>Data-Box : Connection successful !</info>\n"); do { $template = $dialog->ask($output, 'Choose a language template for metadata structure, available are fr (french) and en (english) (en) : ', 'en'); } while (!in_array($template, ['en', 'fr'])); $output->writeln("\n\tLanguage selected is <info>'{$template}'</info>\n"); } catch (\Exception $e) { $retry = true; } } else { $output->writeln("\n\tNo databox will be created\n"); } } while ($retry); } else { $info = ['host' => $input->getOption('db-host'), 'port' => $input->getOption('db-port'), 'user' => $input->getOption('db-user'), 'password' => $input->getOption('db-password'), 'dbname' => $input->getOption('databox')]; $dbConn = $this->container['dbal.provider']($info); $dbConn->connect(); $output->writeln("\n\t<info>Data-Box : Connection successful !</info>\n"); $template = $input->getOption('db-template') ?: 'en'; } // add dbs.option & orm.options services to use orm.em later if ($dbConn && $info) { $this->container['dbs.options'] = array_merge($this->container['db.options.from_info']($info), $this->container['dbs.options']); $this->container['orm.ems.options'] = array_merge($this->container['orm.em.options.from_info']($info), $this->container['orm.ems.options']); } return [$dbConn, $template]; }
public static function create(Application $app, Connection $connection, \SplFileInfo $data_template) { if (!file_exists($data_template->getRealPath())) { throw new \InvalidArgumentException($data_template->getRealPath() . " does not exist"); } $sql = 'SELECT sbas_id FROM sbas WHERE host = :host AND port = :port AND dbname = :dbname AND user = :user AND pwd = :password'; $host = $connection->getHost(); $port = $connection->getPort(); $dbname = $connection->getDatabase(); $user = $connection->getUsername(); $password = $connection->getPassword(); $params = [':host' => $host, ':port' => $port, ':dbname' => $dbname, ':user' => $user, ':password' => $password]; $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); if ($row) { return $app['phraseanet.appbox']->get_databox((int) $row['sbas_id']); } try { $sql = 'CREATE DATABASE `' . $dbname . '` CHARACTER SET utf8 COLLATE utf8_unicode_ci'; $stmt = $connection->prepare($sql); $stmt->execute(); $stmt->closeCursor(); } catch (\Exception $e) { } $sql = 'USE `' . $dbname . '`'; $stmt = $connection->prepare($sql); $stmt->execute(); $stmt->closeCursor(); $sql = 'SELECT MAX(ord) as ord FROM sbas'; $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); if ($row) { $ord = $row['ord'] + 1; } $params[':ord'] = $ord; $sql = 'INSERT INTO sbas (sbas_id, ord, host, port, dbname, sqlengine, user, pwd) VALUES (null, :ord, :host, :port, :dbname, "MYSQL", :user, :password)'; $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); $sbas_id = (int) $app['phraseanet.appbox']->get_connection()->lastInsertId(); $app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_LIST_BASES); $databox = $app['phraseanet.appbox']->get_databox($sbas_id); $databox->insert_datas(); $databox->setNewStructure($data_template, $app['conf']->get(['main', 'storage', 'subdefs'])); return $databox; }