Add basis for database upgrades

This commit is contained in:
kaetemi 2014-09-05 11:07:25 +02:00
parent 856213a2aa
commit daf80ea104
3 changed files with 124 additions and 7 deletions

View file

@ -18,7 +18,7 @@ ini_set( 'display_errors', 'on' );
class SystemExit extends Exception {}
try {
if (!file_exists( '../config.php')) {
if (!file_exists('../role_support')) {
header("Cache-Control: max-age=1");
header('Location: ../setup', true, 303);
throw new SystemExit();

View file

@ -0,0 +1,108 @@
<?php
function set_db_version($continue_r, $name, $version) {
$continue = $continue_r;
if (file_put_contents("db_version_" . $name, (string)$version)) {
} else {
printalert("danger", "Failed to set database version");
$continue = false;
}
return $continue;
}
function get_db_version($name) {
if (!file_exists("db_version_" . $name)) {
return 0;
}
return (int)file_get_contents("db_version_" . $name);
}
function connect_database($continue, $name) {
$con = null;
global $cfg;
if ($continue) {
$con = mysqli_connect(
$cfg['db'][$name]['host'],
$cfg['db'][$name]['user'],
$cfg['db'][$name]['pass'],
$cfg['db'][$name]['name']);
if (mysqli_connect_errno()) {
printalert("danger", "Failed to connect to the <em>" . $name . "</em> SQL server: " . mysqli_connect_error());
$con = null;
} else {
printalert("success", "Connected to the <em>" . $name . "</em> SQL server");
}
}
return $con;
}
function disconnect_database($con, $name) {
if ($con) {
mysqli_close($con);
printalert("info", "Disconnected from the <em>" . $name . "</em> SQL server");
}
}
function upgrade_service_databases($continue_r) {
$continue = $continue_r;
$con = null;
$con = connect_database($continue, "shard");
$continue = ($con != null);
if ($continue && get_db_version("shard") < 1) {
$continue = update_database_structure($continue, $con, "nel_00001.sql");
$continue = set_db_version($continue, "shard", 1);
}
disconnect_database($con, "shard");
$con = null;
$con = connect_database($continue, "tool");
$continue = ($con != null);
if ($continue && get_db_version("tool") < 1) {
$continue = update_database_structure($continue, $con, "nel_tool_00001.sql");
$continue = set_db_version($continue, "tool", 1);
}
disconnect_database($con, "tool");
return $continue;
}
function upgrade_support_databases($continue_r) {
$continue = $continue_r;
$con = null;
$con = connect_database($continue, "web");
$continue = ($con != null);
if ($continue && get_db_version("web") < 1) {
$continue = update_database_structure($continue, $con, "nel_ams_00001.sql");
$continue = set_db_version($continue, "web", 1);
}
disconnect_database($con, "web");
$con = null;
$con = connect_database($continue, "lib");
$continue = ($con != null);
if ($continue && get_db_version("lib") < 1) {
$continue = update_database_structure($continue, $con, "nel_ams_lib_00001.sql");
$continue = set_db_version($continue, "lib", 1);
}
if ($continue && get_db_version("lib") < 2) {
$continue = update_database_structure($continue, $con, "nel_ams_lib_00002.sql");
$continue = set_db_version($continue, "lib", 2);
}
disconnect_database($con, "lib");
return $continue;
}
function upgrade_domain_databases($continue_r) {
$continue = $continue_r;
return $continue;
}
?>

View file

@ -75,11 +75,9 @@ include('header.php');
if ($roleService) {
// Create NeL database
$continue = create_use_database($continue, $con, $_POST["nelDatabase"]);
$continue = update_database_structure($continue, $con, "nel_00001.sql");
// Create NeL Tools database
$continue = create_use_database($continue, $con, $_POST["toolDatabase"]);
$continue = update_database_structure($continue, $con, "nel_tool_00001.sql");
}
if ($con) {
@ -101,12 +99,9 @@ include('header.php');
// Create AMS database
$continue = create_use_database($continue, $con, $_POST["amsDatabase"]);
$continue = update_database_structure($continue, $con, "nel_ams_00001.sql");
// Create AMS Library database
$continue = create_use_database($continue, $con, $_POST["amsLibDatabase"]);
$continue = update_database_structure($continue, $con, "nel_ams_lib_00001.sql");
$continue = update_database_structure($continue, $con, "nel_ams_lib_00002.sql");
if ($con) {
mysqli_close($con);
@ -158,6 +153,20 @@ include('header.php');
}
}
require_once('database.php');
if ($roleSupport) {
$continue = upgrade_support_databases($continue);
}
if ($roleService) {
$continue = upgrade_service_databases($continue);
}
if ($roleDomain) {
$continue = upgrade_domain_databases($continue);
}
if ($roleSupport) {
// Load AMS Library
if ($continue) {
@ -191,7 +200,7 @@ include('header.php');
}
}
if ($continue && $roleSupport) {
if ($continue && $roleService) {
if (file_put_contents("role_service", "1")) {
printalert("success", "Service role successfully installed");
} else {