15 function set_db_version($continue_r, $name, $version) {
16 $continue = $continue_r;
19 if (file_put_contents("db_version_" . $name, (string)$version)) {
21 printalert("danger", "Failed to set database version");
29 function get_db_version($name) {
30 if (!file_exists("db_version_" . $name)) {
33 return (int)file_get_contents("db_version_" . $name);
36 function connect_database($continue, $name) {
41 $con = mysqli_connect(
42 $cfg['db'][$name]['host'],
43 $cfg['db'][$name]['user'],
44 $cfg['db'][$name]['pass'],
45 $cfg['db'][$name]['name']);
46 if (mysqli_connect_errno()) {
47 printalert("danger", "Failed to connect to the <em>" . $name . "</em> SQL server: " . mysqli_connect_error());
50 printalert("success", "Connected to the <em>" . $name . "</em> SQL server");
57 function disconnect_database($con, $name) {
60 printalert("info", "Disconnected from the <em>" . $name . "</em> SQL server");
64 function upgrade_service_databases($continue_r) {
65 $continue = $continue_r;
68 $con = connect_database($continue, "shard");
69 $continue = ($con != null);
71 for ($i = 1; $i <= $db_nel; $i++
) {
72 if ($continue && get_db_version("shard") < $i) {
73 $continue = update_database_structure($continue, $con, "nel_" . str_pad($i, 5, "0", STR_PAD_LEFT
) . ".sql");
74 $continue = set_db_version($continue, "shard", $i);
77 disconnect_database($con, "shard");
80 $con = connect_database($continue, "tool");
81 $continue = ($con != null);
83 for ($i = 1; $i <= $db_nel_tool; $i++
) {
84 if ($continue && get_db_version("tool") < $i) {
85 $continue = update_database_structure($continue, $con, "nel_tool_" . str_pad($i, 5, "0", STR_PAD_LEFT
) . ".sql");
86 $continue = set_db_version($continue, "tool", $i);
89 disconnect_database($con, "tool");
94 function upgrade_support_databases($continue_r) {
95 $continue = $continue_r;
98 $con = connect_database($continue, "web");
99 $continue = ($con != null);
101 for ($i = 1; $i <= $db_nel_ams; $i++
) {
102 if ($continue && get_db_version("web") < $i) {
103 $continue = update_database_structure($continue, $con, "nel_ams_" . str_pad($i, 5, "0", STR_PAD_LEFT
) . ".sql");
104 $continue = set_db_version($continue, "web", $i);
107 disconnect_database($con, "web");
110 $con = connect_database($continue, "lib");
111 $continue = ($con != null);
112 global $db_nel_ams_lib;
113 for ($i = 1; $i <= $db_nel_ams_lib; $i++
) {
114 if ($continue && get_db_version("lib") < $i) {
115 $continue = update_database_structure($continue, $con, "nel_ams_lib_" . str_pad($i, 5, "0", STR_PAD_LEFT
) . ".sql");
116 $continue = set_db_version($continue, "lib", $i);
119 disconnect_database($con, "lib");
124 function upgrade_domain_databases($continue_r) {
125 $continue = $continue_r;
128 $con = connect_database($continue, "ring");
129 $continue = ($con != null);
130 global $db_ring_domain;
131 for ($i = 1; $i <= $db_ring_domain; $i++
) {
132 if ($continue && get_db_version("ring") < $i) {
133 $continue = update_database_structure($continue, $con, "ring_domain_" . str_pad($i, 5, "0", STR_PAD_LEFT
) . ".sql");
134 $continue = set_db_version($continue, "ring", $i);
137 disconnect_database($con, "ring");