Merge pull request #8 from thelia/fixtures_for_modules

Allow fixtures in module
This commit is contained in:
Manuel Raynaud
2013-10-07 00:16:02 -07:00

View File

@@ -40,21 +40,33 @@ class Database
/** /**
* Insert all sql needed in 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)); $this->connection->query(sprintf("use %s", $dbName));
} }
$sql = array(); $sql = array();
$sql = array_merge(
$sql, if (null === $extraSqlFiles) {
$this->prepareSql(file_get_contents(THELIA_ROOT . "/install/thelia.sql")), $sql = array_merge(
$this->prepareSql(file_get_contents(THELIA_ROOT . "/install/insert.sql")) $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 ++) { for ($i = 0; $i < count($sql); $i ++) {
if (!empty($sql[$i])) { if (!empty($sql[$i])) {
@@ -75,7 +87,7 @@ class Database
$sql = trim($sql); $sql = trim($sql);
$query = array(); $query = array();
$tab = explode(";", $sql); $tab = explode(";\n", $sql);
for ($i=0; $i<count($tab); $i++) { for ($i=0; $i<count($tab); $i++) {
$queryTemp = str_replace("-CODE-", ";',", $tab[$i]); $queryTemp = str_replace("-CODE-", ";',", $tab[$i]);