From fbee858ae942085165253ffb1d103f08499e1c8b Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 5 Sep 2014 11:07:25 +0200 Subject: [PATCH 1/2] Add basis for database upgrades --- code/web/public_php/ams/index.php | 2 +- code/web/public_php/setup/database.php | 108 +++++++++++++++++++++++++ code/web/public_php/setup/install.php | 21 +++-- 3 files changed, 124 insertions(+), 7 deletions(-) create mode 100644 code/web/public_php/setup/database.php diff --git a/code/web/public_php/ams/index.php b/code/web/public_php/ams/index.php index 1ab707e79..de2e93235 100644 --- a/code/web/public_php/ams/index.php +++ b/code/web/public_php/ams/index.php @@ -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(); diff --git a/code/web/public_php/setup/database.php b/code/web/public_php/setup/database.php new file mode 100644 index 000000000..421efa301 --- /dev/null +++ b/code/web/public_php/setup/database.php @@ -0,0 +1,108 @@ +" . $name . " SQL server: " . mysqli_connect_error()); + $con = null; + } else { + printalert("success", "Connected to the " . $name . " SQL server"); + } + } + + return $con; +} + +function disconnect_database($con, $name) { + if ($con) { + mysqli_close($con); + printalert("info", "Disconnected from the " . $name . " 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; +} + +?> diff --git a/code/web/public_php/setup/install.php b/code/web/public_php/setup/install.php index 8fdade460..cc98b9432 100644 --- a/code/web/public_php/setup/install.php +++ b/code/web/public_php/setup/install.php @@ -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 { From 98735ea86e3a87a80fa6d7b22b862ae048f0fdf3 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 5 Sep 2014 11:21:21 +0200 Subject: [PATCH 2/2] Validate setup password --- code/web/public_php/setup/auth.php | 16 +++++++++++++--- code/web/public_php/setup/database.php | 9 +++++++++ code/web/public_php/setup/install.php | 15 ++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/code/web/public_php/setup/auth.php b/code/web/public_php/setup/auth.php index 8289289f9..b31646042 100644 --- a/code/web/public_php/setup/auth.php +++ b/code/web/public_php/setup/auth.php @@ -9,24 +9,34 @@ try { $pageTitle = "Authenticate"; include('header.php'); +require_once('config.php'); + ?>
- + + +

Continue

- + + +
diff --git a/code/web/public_php/setup/database.php b/code/web/public_php/setup/database.php index 421efa301..564e74039 100644 --- a/code/web/public_php/setup/database.php +++ b/code/web/public_php/setup/database.php @@ -102,6 +102,15 @@ function upgrade_support_databases($continue_r) { function upgrade_domain_databases($continue_r) { $continue = $continue_r; + $con = null; + $con = connect_database($continue, "ring"); + $continue = ($con != null); + if ($continue && get_db_version("ring") < 1) { + $continue = update_database_structure($continue, $con, "ring_domain_00001.sql"); + $continue = set_db_version($continue, "ring", 1); + } + disconnect_database($con, "ring"); + return $continue; } diff --git a/code/web/public_php/setup/install.php b/code/web/public_php/setup/install.php index cc98b9432..496161724 100644 --- a/code/web/public_php/setup/install.php +++ b/code/web/public_php/setup/install.php @@ -80,6 +80,11 @@ include('header.php'); $continue = create_use_database($continue, $con, $_POST["toolDatabase"]); } + if ($roleDomain) { + // Create Ring database + $continue = create_use_database($continue, $con, $_POST["domainDatabase"]); + } + if ($con) { mysqli_close($con); printalert("info", "Disconnected from the Service SQL server"); @@ -167,6 +172,10 @@ include('header.php'); $continue = upgrade_domain_databases($continue); } + if ($roleService) { + // TODO: Create the default admin user + } + if ($roleSupport) { // Load AMS Library if ($continue) { @@ -200,6 +209,10 @@ include('header.php'); } } + if ($roleDomain) { + // TODO: Register the domain with the nel database etc + } + if ($continue && $roleService) { if (file_put_contents("role_service", "1")) { printalert("success", "Service role successfully installed"); @@ -423,7 +436,7 @@ include('header.php');
-

Domain

+

Domain (Multiple domains require separate installations, as they may run different versions)