From 52ab1c1b7256b5dfed8fc1d527d4bd04b8ff0c27 Mon Sep 17 00:00:00 2001 From: gmorel Date: Fri, 4 Oct 2013 16:52:29 +0200 Subject: [PATCH] Working : Allow fixtures in module, refactor explode on sql file : add \n otherwise any ; in the db crashes everything --- core/lib/Thelia/Install/Database.php | 30 +++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/core/lib/Thelia/Install/Database.php b/core/lib/Thelia/Install/Database.php index 648a6431a..d17bd7c3d 100644 --- a/core/lib/Thelia/Install/Database.php +++ b/core/lib/Thelia/Install/Database.php @@ -40,21 +40,33 @@ class Database /** * Insert all sql needed in database + * Default insert /install/thelia.sql and /install/insert.sql * - * @param $dbName + * @param string $dbName Database name + * @param array $extraSqlFiles SQL Files uri to insert */ - public function insertSql($dbName = null) + public function insertSql($dbName = null, array $extraSqlFiles = null) { - if($dbName) { + if ($dbName) { $this->connection->query(sprintf("use %s", $dbName)); } $sql = array(); - $sql = array_merge( - $sql, - $this->prepareSql(file_get_contents(THELIA_ROOT . "/install/thelia.sql")), - $this->prepareSql(file_get_contents(THELIA_ROOT . "/install/insert.sql")) - ); + + if (null === $extraSqlFiles) { + $sql = array_merge( + $sql, + $this->prepareSql(file_get_contents(THELIA_ROOT . '/install/thelia.sql')), + $this->prepareSql(file_get_contents(THELIA_ROOT . '/install/insert.sql')) + ); + } else { + foreach ($extraSqlFiles as $fileToInsert) { + $sql = array_merge( + $sql, + $this->prepareSql(file_get_contents($fileToInsert)) + ); + } + } for ($i = 0; $i < count($sql); $i ++) { if (!empty($sql[$i])) { @@ -75,7 +87,7 @@ class Database $sql = trim($sql); $query = array(); - $tab = explode(";", $sql); + $tab = explode(";\n", $sql); for ($i=0; $i