public function __construct($dbname, $tablename, $sql) { $dbm = new DatabaseManager(); $this->pdo = $dbm->getPdo($dbname); $this->tablename = $tablename; $this->sql = SqlFormatter::format($sql, false); }
/** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) { $dburl = $input->getArgument('dburl'); $filename = $input->getArgument('filename'); $autoUuidField = $input->getArgument('autouuidfield'); $locale = $input->getOption('locale'); $seed = $input->getOption('seed'); if (!file_exists($filename)) { throw new FileNotFoundException($filename); } $manager = new DatabaseManager(); $pdo = $manager->getPdo($dburl, 'default'); $providers = array(); $loader = new AliceLoader($locale, $providers, $seed); $instantiator = new TableRecordInstantiator(); if ($autoUuidField) { $instantiator->setAutoUuidColumn($autoUuidField); } $loader->addInstantiator($instantiator); $output->writeln(sprintf("Loading '%s' into %s", $filename, $dburl)); $objects = $loader->load($filename); $output->writeln(sprintf("Persisting '%s' objects in database '%s'", count($objects), $dburl)); $persister = new PdoPersister($pdo, $output, $input->getOption('dry-run')); if (!is_null($input->getOption('append'))) { $persister->reset($objects); } $persister->persist($objects); $output->writeln("Done"); }
public function __construct($dbname, $tablename, $indexes = null, $skipdrop = false) { $dbm = new DatabaseManager(); $this->pdo = $dbm->getPdo($dbname); $this->tablename = $tablename; $this->indexes = $indexes; if ($skipdrop == 'true') { $this->skipdrop = true; } }
/** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) { $url = $input->getArgument('url'); $filename = $input->getArgument('filename'); $apply = $input->getOption('apply'); $dbmanager = new DatabaseManager(); $databaseConfig = $dbmanager->getDatabaseConfig($url); $config = $databaseConfig->getConnectionConfig('default'); $dsn = sprintf('%s:host=%s;port=%d', $config->getDriver(), $config->getHost(), $config->getPort()); $dbname = $config->getDatabaseName(); try { $pdo = new PDO($dsn, $config->getUsername(), $config->getPassword()); } catch (\Exception $e) { throw new RuntimeException("Can't connect to server with provided address and credentials"); } $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $pdo->query("SELECT COUNT(*) FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '" . $dbname . "'"); if (!$stmt->fetchColumn()) { $output->writeln("<info>Creating database</info>"); $stmt = $pdo->query("CREATE DATABASE " . $dbname . ""); } else { $output->writeln("<error>Database exists...</error>"); } $loader = LoaderFactory::getInstance()->getLoader($filename); $toSchema = $loader->loadSchema($filename); $config = new Configuration(); $connectionParams = array('url' => $dbmanager->getUrlByDatabaseName($url)); $connection = DriverManager::getConnection($connectionParams, $config); $connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); $output->writeln(sprintf('<info>Loading file <comment>`%s`</comment> into database <comment>`%s`</comment></info>', $filename, $url)); $schemaManager = $connection->getSchemaManager(); $fromSchema = $schemaManager->createSchema(); $comparator = new Comparator(); $schemaDiff = $comparator->compare($fromSchema, $toSchema); $platform = $connection->getDatabasePlatform(); $queries = $schemaDiff->toSaveSql($platform); if (!count($queries)) { $output->writeln("<info>No schema changes required</info>"); return; } if ($apply) { $output->writeln("<info>APPLYING...</info>"); foreach ($queries as $query) { $output->writeln(sprintf('<info>Running: <comment>%s</comment></info>', $query)); $stmt = $connection->query($query); } } else { $output->writeln("<info>CHANGES: The following SQL statements need to be executed to synchronise the schema (use <comment>--apply</comment>)</info>"); foreach ($queries as $query) { $output->writeln($query); } } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $dbname = $input->getArgument('dbname'); $manager = new DatabaseManager(); $databaseconfig = $manager->getDatabaseConfigByDatabaseName($dbname); echo "NAME: [" . $databaseconfig->getName() . "]\n"; foreach ($databaseconfig->getConnectionConfigs() as $connectionconfig) { echo " Connection [" . $connectionconfig->getName() . "]\n"; echo " dsn: [" . $connectionconfig->getDsn() . "]\n"; echo " username: [" . $connectionconfig->getUsername() . "]\n"; echo " password: [" . $connectionconfig->getPassword() . "]\n"; echo " host: [" . $connectionconfig->getHost() . "]\n"; echo " port: [" . $connectionconfig->getPort() . "]\n"; echo "\n"; } $pdo = $manager->getPdo($dbname, 'default'); }
/** * @param string $dbname * @param string $sql */ public function __construct($dbname, $sql) { $dbm = new DatabaseManager(); $this->pdo = $dbm->getPdo($dbname); $this->sql = $sql; }