Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Avoid the database driver to try to create the maintenance table at every request #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Drivers/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public function setOptions($options)
$this->pdoDriver = new DsnQuery($this->options);
} else {
if (isset($this->options['connection'])) {
$this->pdoDriver = new DefaultQuery($this->doctrine->getManager($this->options['connection']));
$this->pdoDriver = new DefaultQuery($this->doctrine->getManager($this->options['connection']), $this->options);
} else {
$this->pdoDriver = new DefaultQuery($this->doctrine->getManager());
$this->pdoDriver = new DefaultQuery($this->doctrine->getManager(), $this->options);
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions Drivers/Query/DefaultQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ class DefaultQuery extends PdoQuery
const NAME_TABLE = 'lexik_maintenance';

/**
* @param EntityManager $em Entity Manager
* @param EntityManager $em Entity Manager
* @param array $options Options driver
*/
public function __construct(EntityManager $em)
public function __construct(EntityManager $em, array $options = array())
{
$this->em = $em;
parent::__construct($options);
}

/**
Expand All @@ -35,7 +37,9 @@ public function initDb()
if (null === $this->db) {
$db = $this->em->getConnection();
$this->db = $db;
$this->createTableQuery();
if (!isset($this->options['table_created']) || !$this->options['table_created']) {
$this->createTableQuery();
}
}

return $this->db;
Expand Down
5 changes: 3 additions & 2 deletions Drivers/Query/DsnQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ class DsnQuery extends PdoQuery
public function initDb()
{
if (null === $this->db) {

if (!class_exists('PDO') || !in_array('mysql', \PDO::getAvailableDrivers(), true)) {
throw new \RuntimeException('You need to enable PDO_Mysql extension for the profiler to run properly.');
}

$db = new \PDO($this->options['dsn'], $this->options['user'], $this->options['password']);
$this->db = $db;
$this->createTableQuery();
if (!isset($this->options['table_created']) || !$this->options['table_created']) {
$this->createTableQuery();
}
}

return $this->db;
Expand Down