private function singleImport($config, OutputInterface &$output, $entity_key = null) { $this->connection = $this->connectionFactory->createConnection($config['database']); $this->connection->getConfiguration()->getSQLLogger(null); if ($entity_key) { if (!isset($config['maps'][$entity_key])) { throw new \Exception("Entity alias not found: " . $entity_key); } $map = $config['maps'][$entity_key]; if (!$this->container->has($map['old_data']['service_id'])) { throw new \Exception("Service not exists: " . $map['old_data']['service_id']); } $result = $this->importEntity($map); $output->writeln("<info>Total " . count($result) . " {$entity_key} imported </info>"); } else { foreach ((array) $config['maps'] as $key => $map) { if (!$this->container->has($map['old_data']['service_id'])) { throw new \Exception("Service not exists: " . $map['old_data']['service_id']); } $offset = 0; do { $result = $this->importEntity($map); $output->writeln("<info>Total " . count($result) . " {$key} imported </info>"); if (!$result) { break; } $offset++; $this->setOffset($offset); } while (true); } } $this->connection->close(); }
/** * Initializes the database (once). * * @throws \Doctrine\DBAL\DBALException * @throws \Doctrine\ORM\ORMException * @throws \Doctrine\ORM\Tools\ToolsException */ protected function setUp() { if (null === static::$_conn) { $dbPath = __DIR__ . '/../../../db.sqlite'; if (file_exists($dbPath)) { unlink($dbPath); } $params = ['driver' => 'pdo_sqlite', 'path' => $dbPath]; static::$_conn = DriverManager::getConnection($params); static::$_conn->getConfiguration()->setSQLLogger(null); } if (null === static::$_em) { $paths = [__DIR__ . '/../../../../../src/Ekyna/Commerce/Bridge/Doctrine/ORM/Resources/mapping']; $isDevMode = true; $config = Setup::createXMLMetadataConfiguration($paths, $isDevMode); $em = EntityManager::create(static::$_conn, $config); $classes = []; foreach (static::$_classes as $class) { array_push($classes, $em->getClassMetadata($class)); } $schemaTool = new SchemaTool($em); $schemaTool->dropSchema($classes); $schemaTool->createSchema($classes); // Load fixtures $loader = new Loader(); $loader->loadFromDirectory(__DIR__ . '/../../../../../src/Ekyna/Commerce/Bridge/Doctrine/Fixtures'); $purger = new ORMPurger(); $executor = new ORMExecutor($em, $purger); $executor->execute($loader->getFixtures()); static::$_em = $em; } }
public function setConnection(Connection $conn) { $this->conn = $conn; if ($this->debug) { $this->logger = new DebugStack(); $this->conn->getConfiguration()->setSQLLogger($this->logger); } }
/** * @param $sql * @return \Doctrine\DBAL\Driver\Statement * @throws \Doctrine\DBAL\DBALException */ public static function runQuery($sql) { if (null === static::$dblaConnInstance) { static::$dblaConnInstance = DriverManager::getConnection(static::getParamsConnection(), new Configuration()); static::$dblaConnInstance->getConfiguration()->setSQLLogger(self::logger()); } return static::$dblaConnInstance->query($sql); }
/** * Set a caching method. * * It will not override an already set result cache * * @param Doctrine\Common\Cache\Cache a Cache interface */ public function setResultCache(Cache $cache) { $config = $this->conn->getConfiguration(); $this->hasResultCache = null != $config->getResultCacheImpl(); if (!$this->hasResultCache) { $config->setResultCacheImpl($cache); $this->hasResultCache = true; } }
protected function setUp() { if (!isset(self::$_sharedConn)) { self::$_sharedConn = TestUtil::getConnection(); } $this->_conn = self::$_sharedConn; $this->_sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack(); $this->_conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack); }
public function setUp() { if (!isset(self::$_sharedConn)) { $params = array('driverClass' => 'Crate\\DBAL\\Driver\\PDOCrate\\Driver', 'host' => 'localhost', 'port' => 4200); self::$_sharedConn = \Doctrine\DBAL\DriverManager::getConnection($params); } $this->_conn = self::$_sharedConn; $this->_sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack(); $this->_conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack); }
/** * @param \Doctrine\DBAL\Connection $connection * @throws \Nette\InvalidStateException */ public function setConnection(Doctrine\DBAL\Connection $connection) { if ($this->connection !== NULL) { throw new Nette\InvalidStateException("Doctrine Panel is already bound to connection."); } if (($logger = $connection->getConfiguration()->getSQLLogger()) instanceof Doctrine\DBAL\Logging\LoggerChain) { $logger->addLogger($this); } else { $connection->getConfiguration()->setSQLLogger($this); } $this->connection = $connection; }
protected function _getConnection() { if (!isset(self::$_conn)) { self::$_conn = DriverManager::getConnection($this->_getDbParams(), new Configuration()); self::$_conn->getEventManager()->addEventSubscriber(new ORMSchemaEventSubscriber()); Configurator::configure(self::$_conn->getConfiguration()); if (!Type::hasType('tsvector')) { Type::addType('tsvector', 'Doctrine\\DBAL\\Types\\TextType'); } $platform = self::$_conn->getDatabasePlatform(); $platform->registerDoctrineTypeMapping('tsvector', 'tsvector'); } return self::$_conn; }
protected function _getConnection() { if (!isset(self::$_conn)) { $dbParams = array('driver' => $GLOBALS['db_type'], 'user' => $GLOBALS['db_username'], 'password' => $GLOBALS['db_password'], 'host' => $GLOBALS['db_host'], 'dbname' => $GLOBALS['db_name'], 'port' => $GLOBALS['db_port']); self::$_conn = DriverManager::getConnection($dbParams, new Configuration()); self::$_conn->getEventManager()->addEventSubscriber(new ORMSchemaEventSubscriber()); Configurator::configure(self::$_conn->getConfiguration()); if (!Type::hasType('tsvector')) { Type::addType('tsvector', 'Doctrine\\DBAL\\Types\\TextType'); } $platform = self::$_conn->getDatabasePlatform(); $platform->registerDoctrineTypeMapping('tsvector', 'tsvector'); } return self::$_conn; }
/** * @param Schema $targetSchema * @param \Doctrine\DBAL\Connection $connection * @return \Doctrine\DBAL\Schema\SchemaDiff * @throws DBALException */ protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { // adjust varchar columns with a length higher then getVarcharMaxLength to clob foreach ($targetSchema->getTables() as $table) { foreach ($table->getColumns() as $column) { if ($column->getType() instanceof StringType) { if ($column->getLength() > $connection->getDatabasePlatform()->getVarcharMaxLength()) { $column->setType(Type::getType('text')); $column->setLength(null); } } } } $filterExpression = $this->getFilterExpression(); $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); $sourceSchema = $connection->getSchemaManager()->createSchema(); // remove tables we don't know about /** @var $table \Doctrine\DBAL\Schema\Table */ foreach ($sourceSchema->getTables() as $table) { if (!$targetSchema->hasTable($table->getName())) { $sourceSchema->dropTable($table->getName()); } } // remove sequences we don't know about foreach ($sourceSchema->getSequences() as $table) { if (!$targetSchema->hasSequence($table->getName())) { $sourceSchema->dropSequence($table->getName()); } } $comparator = new Comparator(); return $comparator->compare($sourceSchema, $targetSchema); }
/** * Initializes a new <tt>StandardEntityPersister</tt> that uses the given EntityManager * and persists instances of the class described by the given class metadata descriptor. * * @param EntityManager $em * @param ClassMetadata $class */ public function __construct(EntityManager $em, ClassMetadata $class) { $this->_em = $em; $this->_class = $class; $this->_conn = $em->getConnection(); $this->_sqlLogger = $this->_conn->getConfiguration()->getSqlLogger(); $this->_platform = $this->_conn->getDatabasePlatform(); }
public function enableLogging() { if ($this->connection === NULL) { throw new Kdyby\Doctrine\InvalidStateException("Doctrine Panel is not bound to connection."); } $config = $this->connection->getConfiguration(); $logger = $config->getSQLLogger(); if ($logger instanceof Doctrine\DBAL\Logging\LoggerChain) { $logger->addLogger($this); } else { $config->setSQLLogger($this); } }
/** * Executes the statement with the currently bound parameters. * * @param array|null $params * * @return boolean TRUE on success, FALSE on failure. * * @throws \Doctrine\DBAL\DBALException */ public function execute($params = null) { if (is_array($params)) { $this->params = $params; } $logger = $this->conn->getConfiguration()->getSQLLogger(); if ($logger) { $logger->startQuery($this->sql, $this->params, $this->types); } try { $stmt = $this->stmt->execute($params); } catch (\Exception $ex) { throw DBALException::driverExceptionDuringQuery($ex, $this->sql, $this->conn->resolveParams($this->params, $this->types)); } if ($logger) { $logger->stopQuery(); } $this->params = array(); $this->types = array(); return $stmt; }
protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { $filterExpression = $this->getFilterExpression(); $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); $sourceSchema = $connection->getSchemaManager()->createSchema(); // remove tables we don't know about /** @var $table \Doctrine\DBAL\Schema\Table */ foreach ($sourceSchema->getTables() as $table) { if (!$targetSchema->hasTable($table->getName())) { $sourceSchema->dropTable($table->getName()); } } // remove sequences we don't know about foreach ($sourceSchema->getSequences() as $table) { if (!$targetSchema->hasSequence($table->getName())) { $sourceSchema->dropSequence($table->getName()); } } $comparator = new Comparator(); return $comparator->compare($sourceSchema, $targetSchema); }
private function connectToDatabase(Connection $db, $databaseName) { $db->close(); $db->__construct(['dbname' => $databaseName] + $db->getParams(), $db->getDriver(), $db->getConfiguration(), $db->getEventManager()); $db->connect(); }
/** * Pretty dumb test, however we want to check that the DebugStack correctly implements the interface. * * @group DBAL-11 */ public function testDebugSQLStack() { $logger = new \Doctrine\DBAL\Logging\DebugStack(); $this->_conn->getConfiguration()->setSQLLogger($logger); $this->assertSame($logger, $this->_conn->getConfiguration()->getSQLLogger()); }
/** * @return string|null */ protected function getFilterSchemaAssetsExpression() { return $this->_conn->getConfiguration()->getFilterSchemaAssetsExpression(); }
/** * @param Connection $conn * @param string $generatorTableName */ public function __construct(Connection $conn, $generatorTableName = 'sequences') { $params = $conn->getParams(); if ($params['driver'] == 'pdo_sqlite') { throw new \Doctrine\DBAL\DBALException("Cannot use TableGenerator with SQLite."); } $this->conn = DriverManager::getConnection($params, $conn->getConfiguration(), $conn->getEventManager()); $this->generatorTableName = $generatorTableName; }
private function getDbMockBuilder(Connection $db) { return $this->getMockBuilder('\\Doctrine\\DBAL\\Connection')->setConstructorArgs([$db->getParams(), $db->getDriver(), $db->getConfiguration(), $db->getEventManager()])->enableOriginalConstructor(); }
public function testGetConfiguration() { $config = $this->_conn->getConfiguration(); $this->assertType('Doctrine\\DBAL\\Configuration', $config); }