Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / web / public_php / setup / database.php
blob6137cb00f84a6ed2f717ee2b4ae976db96268464
1 <?php
3 // Service
4 $db_nel = 4;
5 $db_nel_tool = 2;
7 // Support
8 $db_nel_ams = 2;
9 $db_nel_ams_lib = 7;
11 // Domain
12 $db_ring_domain = 1;
15 function set_db_version($continue_r, $name, $version) {
16 $continue = $continue_r;
18 if ($continue) {
19 if (file_put_contents("db_version_" . $name, (string)$version)) {
20 } else {
21 printalert("danger", "Failed to set database version");
22 $continue = false;
26 return $continue;
29 function get_db_version($name) {
30 if (!file_exists("db_version_" . $name)) {
31 return 0;
33 return (int)file_get_contents("db_version_" . $name);
36 function connect_database($continue, $name) {
37 $con = null;
39 global $cfg;
40 if ($continue) {
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());
48 $con = null;
49 } else {
50 printalert("success", "Connected to the <em>" . $name . "</em> SQL server");
54 return $con;
57 function disconnect_database($con, $name) {
58 if ($con) {
59 mysqli_close($con);
60 printalert("info", "Disconnected from the <em>" . $name . "</em> SQL server");
64 function upgrade_service_databases($continue_r) {
65 $continue = $continue_r;
67 $con = null;
68 $con = connect_database($continue, "shard");
69 $continue = ($con != null);
70 global $db_nel;
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");
79 $con = null;
80 $con = connect_database($continue, "tool");
81 $continue = ($con != null);
82 global $db_nel_tool;
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");
91 return $continue;
94 function upgrade_support_databases($continue_r) {
95 $continue = $continue_r;
97 $con = null;
98 $con = connect_database($continue, "web");
99 $continue = ($con != null);
100 global $db_nel_ams;
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");
109 $con = null;
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");
121 return $continue;
124 function upgrade_domain_databases($continue_r) {
125 $continue = $continue_r;
127 $con = null;
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");
139 return $continue;