close() public method

Closes the connection.
public close ( ) : void
return void
Ejemplo n.º 1
1
 public function shutdown()
 {
     if ($this->connection->isTransactionActive()) {
         $this->rollback();
     }
     $this->connection->close();
 }
 /**
  * @return Connection
  */
 public function getConnection()
 {
     if (false === $this->connection->ping()) {
         $this->connection->close();
         $this->connection->connect();
     }
     return $this->connection;
 }
Ejemplo n.º 3
1
 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();
 }
Ejemplo n.º 4
1
 protected function pingIt(Connection $con)
 {
     if ($con->ping() === false) {
         $con->close();
         $con->connect();
     }
     return $con;
 }
Ejemplo n.º 5
0
 /**
  * Retrieves hte index database.
  *
  * @return Connection
  */
 public function getConnection()
 {
     if (!$this->connection) {
         $isNewDatabase = !file_exists($this->databasePath);
         $configuration = new Configuration();
         $this->connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => $this->databasePath], $configuration);
         $outOfDate = null;
         if ($isNewDatabase) {
             $this->createDatabaseTables($this->connection);
             // NOTE: This causes a database write and will cause locking problems if multiple PHP processes are
             // spawned and another one is also writing (e.g. indexing).
             $this->connection->executeQuery('PRAGMA user_version=' . $this->databaseVersion);
         } else {
             $version = $this->connection->executeQuery('PRAGMA user_version')->fetchColumn();
             if ($version < $this->databaseVersion) {
                 $this->connection->close();
                 $this->connection = null;
                 @unlink($this->databasePath);
                 return $this->getConnection();
                 // Do it again.
             }
         }
     }
     // Have to be a douche about this as these PRAGMA's seem to reset, even though the connection is not closed.
     $this->connection->executeQuery('PRAGMA foreign_keys=ON');
     // Data could become corrupted if the operating system were to crash during synchronization, but this
     // matters very little as we will just reindex the project next time. In the meantime, this majorly reduces
     // hard disk I/O during indexing and increases indexing speed dramatically (dropped from over a minute to a
     // couple of seconds for a very small (!) project).
     $this->connection->executeQuery('PRAGMA synchronous=OFF');
     return $this->connection;
 }
 protected function resetSharedConn()
 {
     if (self::$_sharedConn) {
         self::$_sharedConn->close();
         self::$_sharedConn = null;
     }
 }
Ejemplo n.º 7
0
 /**
  * This method checks whether the connection is still open or reconnects otherwise.
  *
  * The connection might drop in some scenarios, where the server has a configured timeout and the handling
  * of the result set takes longer. To prevent failures of the dumper, the connection will be opened again.
  */
 public function reconnectIfNecessary()
 {
     if (!$this->connection->ping()) {
         $this->connection->close();
         $this->connect();
     }
 }
 public function tearDown()
 {
     $this->connection->close();
     $this->eventStore = null;
     $this->eventNameResolver = null;
     $this->serializer = null;
     $this->connection = null;
 }
Ejemplo n.º 9
0
 /**
  * @return Job[]
  */
 public function getAll()
 {
     $this->conn->connect();
     $stmt = $this->conn->query("select * from {$this->table_name}");
     $stmt->setFetchMode(\PDO::FETCH_CLASS, '\\ebussola\\job\\job\\Job');
     $stmt->execute();
     $jobs = $stmt->fetchAll();
     $this->conn->close();
     return $jobs;
 }
Ejemplo n.º 10
0
 /**
  * close Doctrine Dbal and ORM connection and reset everything to default.
  */
 public function close()
 {
     $this->Conn->close();
     if (is_object($this->EntityManager) && method_exists($this->EntityManager, 'close')) {
         $this->EntityManager->close();
     }
     if (function_exists('gc_collect_cycles')) {
         gc_collect_cycles();
     }
     $this->Conn = '';
     $this->EntityManager = '';
     $this->table_prefix = '';
     $this->table_siteid_prefix = '';
 }
 /**
  * {@inheritDoc}
  */
 public function close($force = false)
 {
     if ($force) {
         parent::close();
         $this->unsetPersistedConnection();
     }
 }
Ejemplo n.º 12
0
 /**
  * {@inheritDoc}
  */
 public function logout()
 {
     if ($this->loggedIn) {
         $this->loggedIn = false;
         $this->conn->close();
         $this->conn = null;
     }
 }
Ejemplo n.º 13
0
 public function preTask(Worker $worker, array $options = null)
 {
     if ($worker instanceof DoctrineAwareWorker) {
         if ($this->connection) {
             try {
                 $this->connection->executeQuery('SELECT 1');
             } catch (DBALException $e) {
                 if ($e->getPrevious()->getCode() == "HY000") {
                     $this->logger->info('Reconnecting doctrine', ['e' => $e]);
                     $this->connection->close();
                 } else {
                     throw $e;
                 }
             }
         }
     }
 }
Ejemplo n.º 14
0
 public function testHeartBeatException()
 {
     $this->setExpectedException('\\RuntimeException', 'Counld not connect to database');
     $this->getDatabaseTester()->getConnection();
     $config1 = new DoctrineConfig($this->connection);
     $this->assertEquals(0, $config1->getMachine());
     $this->connection->close();
     $config1->heartbeat();
 }
Ejemplo n.º 15
0
 private static final function initializeDatabase()
 {
     if (!self::$dbReused) {
         self::runCommand('doctrine:database:drop', array('--force' => true));
         self::runCommand('doctrine:database:create');
         self::$conn->close();
         self::$conn->connect();
         foreach (self::$dbInitializer->getMigrationFiles() as $file) {
             self::runCommand('dbal:import', array('file' => $file));
         }
     }
 }
 /**
  * It attempts to reconnect if connection is non responsive. Failing to reconnect triggers a critical error.
  * If connection is responsive or successfully reconnected it rethrows, relying on the bus retries
  * to re-execute everything from the beginning.
  *
  * @param \Exception $e
  *
  * @return \Exception|CriticalErrorException
  */
 private function attemptToReconnectPresumedLostConnection(\Exception $e)
 {
     // presumably, any exception caught here is related to some connection error
     if (!$this->connection->ping()) {
         // if pinging fails, we try to reconnect
         try {
             $this->connection->close();
             $this->connection->connect();
         } catch (\Exception $e) {
             // if reconnecting fails, there is no way that the bus can continue to function
             return new CriticalErrorException("Database connection failed.", 0, $e);
         }
     }
     return $e;
 }
 /**
  * Closes connection if open, opens a unbuffered connection.
  *
  * @param Connection $connection
  *
  * @throws InvalidArgumentException
  */
 public static function unbufferConnection(Connection $connection)
 {
     /** @var PDOConnection $wrappedConnection */
     $wrappedConnection = $connection->getWrappedConnection();
     if (!$wrappedConnection instanceof PDOConnection) {
         throw new InvalidArgumentException('unbufferConection can only be used with pdo_mysql Doctrine driver.');
     }
     if ($wrappedConnection->getAttribute(PDO::ATTR_DRIVER_NAME) != 'mysql') {
         throw new InvalidArgumentException('unbufferConection can only be used with PDO mysql driver, got "' . $wrappedConnection->getAttribute(PDO::ATTR_DRIVER_NAME) . '" instead.');
     }
     if ($connection->isConnected()) {
         $connection->close();
     }
     $connection->getWrappedConnection()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
     $connection->connect();
 }
Ejemplo n.º 18
0
 /**
  * Generates SQL for installation.
  *
  * @param object $originalData
  *
  * @return array|bool Array containing the flash message data on a failure, boolean true on success
  */
 public function installSchema()
 {
     $sm = $this->db->getSchemaManager();
     try {
         //check to see if the table already exist
         $tables = $sm->listTableNames();
     } catch (\Exception $e) {
         $this->db->close();
         throw $e;
     }
     $this->platform = $sm->getDatabasePlatform();
     $backupPrefix = !empty($this->dbParams['backup_prefix']) ? $this->dbParams['backup_prefix'] : 'bak_';
     $metadatas = $this->em->getMetadataFactory()->getAllMetadata();
     if (empty($metadatas)) {
         $this->db->close();
         return false;
     }
     $schemaTool = new SchemaTool($this->em);
     $installSchema = $schemaTool->getSchemaFromMetadata($metadatas);
     $mauticTables = [];
     foreach ($installSchema->getTables() as $m) {
         $tableName = $m->getName();
         $mauticTables[$tableName] = $this->generateBackupName($this->dbParams['table_prefix'], $backupPrefix, $tableName);
     }
     $sql = ['SET foreign_key_checks = 0;'];
     if ($this->dbParams['backup_tables']) {
         $sql = array_merge($sql, $this->backupExistingSchema($tables, $mauticTables, $backupPrefix));
     } else {
         $sql = array_merge($sql, $this->dropExistingSchema($tables, $mauticTables));
     }
     $sql = array_merge($sql, $installSchema->toSql($this->platform));
     // Execute drop queries
     if (!empty($sql)) {
         foreach ($sql as $q) {
             try {
                 $this->db->query($q);
             } catch (\Exception $exception) {
                 $this->db->close();
                 throw $exception;
             }
         }
     }
     $this->db->close();
     return true;
 }
 /**
  * {@inheritDoc}
  */
 public function close()
 {
     unset($this->connections['master']);
     unset($this->connections['slave']);
     parent::close();
     $this->_conn = null;
     $this->connections = array('master' => null, 'slave' => null);
 }
 private function closeConnection(Connection $connection)
 {
     $connection->close();
 }
Ejemplo n.º 21
0
 public function testConnectionIsClosed()
 {
     $this->_conn->close();
     $this->setExpectedException('Doctrine\\DBAL\\Exception\\DriverException');
     $this->_conn->quoteIdentifier('Bug');
 }
Ejemplo n.º 22
0
 /**
  * Close this connection.
  */
 public function close()
 {
     $this->_conn->close();
 }
Ejemplo n.º 23
0
 public function tearDown()
 {
     $this->conn->close();
     imap_close($this->imap->getImapStream());
 }
 /**
  * {@inheritDoc}
  */
 public function close()
 {
     unset($this->connections['master']);
     unset($this->connections['slave']);
     parent::close();
 }
Ejemplo n.º 25
0
 private function keepalive(Connection $db)
 {
     if (false === $db->ping()) {
         $db->close();
         $db->connect();
     }
 }
Ejemplo n.º 26
0
 private function shutdown()
 {
     if ($this->connection !== null && $this->connection->isConnected()) {
         $this->connection->close();
     }
 }
Ejemplo n.º 27
0
 /**
  * {@inheritDoc}
  */
 public function close()
 {
     if ($this->isConnected()) {
         parent::close();
         $this->_isConnected = false;
     }
 }
Ejemplo n.º 28
0
 private function connectToDatabase(Connection $db, $databaseName)
 {
     $db->close();
     $db->__construct(['dbname' => $databaseName] + $db->getParams(), $db->getDriver(), $db->getConfiguration(), $db->getEventManager());
     $db->connect();
 }
Ejemplo n.º 29
0
 private function dropAndCreateDB(Connection $connection)
 {
     // Drop and recreate the database
     if ($connection->getDatabasePlatform()->supportsCreateDropDatabase()) {
         $dbname = $connection->getDatabase();
         $connection->close();
         $connection->getSchemaManager()->dropAndCreateDatabase($dbname);
         $connection->connect();
     } else {
         $sm = $connection->getSchemaManager();
         /* @var $schema Schema */
         $schema = $sm->createSchema();
         $stmts = $schema->toDropSql($connection->getDatabasePlatform());
         foreach ($stmts as $stmt) {
             $connection->exec($stmt);
         }
     }
 }
Ejemplo n.º 30
0
 /**
  * This method can be called to explicitly close the connection
  */
 public function closeForReal()
 {
     parent::close();
 }