From 3c30d99d99338acd9a7e093ce9af5b86b8d0bc3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien?= Date: Mon, 29 Aug 2016 18:38:39 +0200 Subject: [PATCH] Add a 'table_created' option to the DatabaseDriver so that the bundle does not try to create again the table at every request on the application --- Drivers/DatabaseDriver.php | 4 ++-- Drivers/Query/DefaultQuery.php | 10 +++++++--- Drivers/Query/DsnQuery.php | 5 +++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Drivers/DatabaseDriver.php b/Drivers/DatabaseDriver.php index 2a8490d..ec8b847 100644 --- a/Drivers/DatabaseDriver.php +++ b/Drivers/DatabaseDriver.php @@ -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); } } } diff --git a/Drivers/Query/DefaultQuery.php b/Drivers/Query/DefaultQuery.php index e8dabc4..3dc79a4 100644 --- a/Drivers/Query/DefaultQuery.php +++ b/Drivers/Query/DefaultQuery.php @@ -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); } /** @@ -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; diff --git a/Drivers/Query/DsnQuery.php b/Drivers/Query/DsnQuery.php index 80ed449..a7740b9 100644 --- a/Drivers/Query/DsnQuery.php +++ b/Drivers/Query/DsnQuery.php @@ -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;