Commit 89d044fc authored by Cédric Houbart's avatar Cédric Houbart
Browse files

Set database scripts in type subdirectory

parent 0e97ed3d
......@@ -27,14 +27,23 @@ class Installer {
const NEED_DB_DOWNGRADE = 3;
static function install($country) {
$uid = get_user_id();
$type = get_db_type($uid);
$pdo = PDOBuilder::getPDO();
$file = ABSPATH . "/install/database/create.sql";
$pdo->query(\file_get_contents($file));
$file = ABSPATH . "/install/database/" . $type . "/create.sql";
if (!\file_exists($file)) {
return false;
}
if ($pdo->query(\file_get_contents($file)) === false) {
return false;
}
// Load country data
if ($country !== null) {
$cfile = ABSPATH . "/install/database/data_" . $country . ".sql";
$cfile = ABSPATH . "/install/database/" . $type
. "/data_" . $country . ".sql";
$pdo->query(\file_get_contents($cfile));
}
return true;
}
/** Upgrade database from given version to the latest. */
......@@ -43,12 +52,16 @@ class Installer {
$version = Installer::getVersion();
}
while ($version != DB_VERSION) {
$uid = get_user_id();
$type = get_db_type($uid);
$pdo = PDOBuilder::getPDO();
// Load generic sql update for current version
$file = ABSPATH . "/install/database/upgrade-" . $version . ".sql";
$file = ABSPATH . "/install/database/" . $type
. "/upgrade-" . $version . ".sql";
$pdo->query(\file_get_contents($file));
// Check for localized update data for current version
$file = ABSPATH . "/install/database/upgrade-" . $version . "_" . $country . ".sql";
$file = ABSPATH . "/install/database/" . $type
. "upgrade-" . $version . "_" . $country . ".sql";
if (\file_exists($file)) {
$pdo->query(\file_get_contents($file));
}
......@@ -60,7 +73,7 @@ class Installer {
$pdo = PDOBuilder::getPDO();
$sql = "SELECT VERSION FROM APPLICATIONS WHERE ID = :id";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(":id", "pasteque");
$stmt->bindValue(":id", "postech");
$stmt->execute();
$data = $stmt->fetch();
if ($data !== false) {
......
......@@ -31,9 +31,10 @@ class InstallDbTest extends \PHPUnit_Framework_TestCase {
}
public function testInstallStruct() {
Installer::install(null);
$this->assertEquals(Installer::install(null), true,
"Installation failed");
$pdo = PDOBuilder::getPDO();
$this->assertEquals(Installer::getVersion(), DB_VERSION,
$this->assertEquals(DB_VERSION, Installer::getVersion(),
"Version doesn't match");
// Check data insert
$sql = "SELECT * FROM RESOURCES WHERE ID = 14";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment