Mercurial > hg > fapweb
annotate managedb.php @ 1115:24e6915fc0fb
Move database field length definitions from msite.inc.php to dbdefs.inc.php
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 14 Oct 2019 10:33:39 +0300 |
parents | 0a2117349f46 |
children | b2bca5f6d0ff |
rev | line source |
---|---|
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 #!/usr/bin/php |
1074 | 2 <?php |
804 | 3 // |
4 // FAPWeb Database management utility | |
1072 | 5 // (C) Copyright 2012-2017 Tecnic Software productions (TNSP) |
804 | 6 // |
1024
2a96426159f1
Fix configuration file checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
1019
diff
changeset
|
7 if (!file_exists(realpath(dirname(__FILE__))."/mconfig.inc.php")) |
1019
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
8 { |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
9 die( |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
10 "ERROR: Missing site configuration file. Please copy ". |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
11 "'mconfig.inc.php.example' to 'mconfig.inc.php' and ". |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
12 "edit it as needed.\n"); |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
13 } |
22b6442d5cb3
Add error messages for missing mconfig.inc.php.
Matti Hamalainen <ccr@tnsp.org>
parents:
1001
diff
changeset
|
14 |
175
8df523e6326a
User require_once instead of require.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
15 require_once "mconfig.inc.php"; |
8df523e6326a
User require_once instead of require.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
16 require_once "msite.inc.php"; |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 |
479
86ee2b42a995
Move CLI helper functions to msitegen, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
426
diff
changeset
|
18 stCheckCLIExec(); |
50
184a4188555c
Move CLI helper functions to createdb.php, as they are now only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
47
diff
changeset
|
19 |
555
206196b610fd
Move site specific things to dbdefs.inc.php
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
20 |
542
8c1a53532be0
Rename various database tables and column names for better SQL compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
21 $currVersion = -1; |
555
206196b610fd
Move site specific things to dbdefs.inc.php
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
22 $dbMetaData = array( |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
23 "dbVersion" => array(VT_INT, $dbVersion, "Database version"), |
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
24 ); |
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
25 |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
26 // Add database meta table into tables to be created |
555
206196b610fd
Move site specific things to dbdefs.inc.php
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
27 $sqlTables["dbmeta"] = array( |
206196b610fd
Move site specific things to dbdefs.inc.php
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
28 array("key" , "VARCHAR(32)", "PRIMARY KEY"), |
206196b610fd
Move site specific things to dbdefs.inc.php
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
29 array("vtype" , "INT"), |
206196b610fd
Move site specific things to dbdefs.inc.php
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
30 array("vstr" , "VARCHAR(128)"), |
206196b610fd
Move site specific things to dbdefs.inc.php
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
31 array("vtext" , "TEXT"), |
206196b610fd
Move site specific things to dbdefs.inc.php
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
32 array("vint" , "INT"), |
206196b610fd
Move site specific things to dbdefs.inc.php
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
33 array("sdesc" , "VARCHAR(128)"), |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 ); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 |
515 | 36 |
88
784953d60ba5
More work on test data generation.
Matti Hamalainen <ccr@tnsp.org>
parents:
85
diff
changeset
|
37 |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 // |
36 | 39 // Helper functions |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 // |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
41 function stCreateTables($dbh, $upgrade) |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 global $sqlTables; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 echo "Creating tables...\n"; |
503
3232f682f0d2
Change how table schemas are defined, in preparation for future database
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
45 foreach ($sqlTables as $name => $schemaData) |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 echo " - '".$name."'\n"; |
540
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
48 stDBExecSQL($dbh, "DROP TABLE IF EXISTS ".$name); |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
49 if (!stDBCreateOneTable($dbh, $name, stDBGetTableSchema($dbh, $schemaData))) |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
50 { |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
51 if (!$upgrade) |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
52 return FALSE; |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
53 else |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
54 echo "\nFailed to create table '".$name."'\n"; |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
55 } |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 return TRUE; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 |
540
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
61 function stUpgradeMap($type, $name) |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
62 { |
540
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
63 global $upgradeMappings, $currVersion, $dbVersion; |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
64 |
540
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
65 $converted = FALSE; |
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
66 $tmpName = $name; |
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
67 |
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
68 for ($ver = $currVersion; $ver <= $dbVersion; $ver++) |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
69 { |
540
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
70 if (isset($upgradeMappings[$ver]) && |
590
94b9bf155fdb
Revert a completely broken change. :S
Matti Hamalainen <ccr@tnsp.org>
parents:
586
diff
changeset
|
71 isset($upgradeMappings[$ver][$tmpName]) && |
94b9bf155fdb
Revert a completely broken change. :S
Matti Hamalainen <ccr@tnsp.org>
parents:
586
diff
changeset
|
72 isset($upgradeMappings[$ver][$tmpName][$type])) |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
73 { |
590
94b9bf155fdb
Revert a completely broken change. :S
Matti Hamalainen <ccr@tnsp.org>
parents:
586
diff
changeset
|
74 $tmpName = $upgradeMappings[$ver][$tmpName][$type]; |
540
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
75 $converted = TRUE; |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
76 } |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
77 } |
540
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
78 |
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
79 if ($converted) |
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
80 return $tmpName; |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
81 else |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
82 switch ($type) |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
83 { |
540
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
84 case "table": return $name; |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
85 case "key": return $name; |
540
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
86 default: die("Invalid upgrade type '".$type."'.\n"); |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
87 } |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
88 } |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
89 |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
90 |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
91 function stDoAddSettings($inDB, $outDB, $settings, $table, $upgrade, $group = FALSE) |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 { |
519 | 93 $status = TRUE; |
94 | |
139
75cf14ee99a7
More work on party information system.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
95 foreach ($settings as $key => $data) |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 { |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1074
diff
changeset
|
97 $sql = FALSE; |
551
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
98 |
515 | 99 // Get setting type |
80 | 100 switch ($data[0]) |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 case VT_TEXT: $type = "%s"; $var = "vtext"; break; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 case VT_STR: $type = "%s"; $var = "vstr"; break; |
72
63a6caf59e5c
Fix creation of boolean settings, and add '%b' formatter into stPrepareSQL().
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
104 case VT_BOOL: $type = "%b"; $var = "vint"; break; |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 case VT_INT: $type = "%d"; $var = "vint"; break; |
80 | 106 default: die("Invalid type in default settings '".$key."', type=".$data[0]."\n"); |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
109 $sqlFmt = |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
110 "INSERT INTO ".$table." (key,vtype,".$var.",sdesc". |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
111 ($group !== FALSE ? ",vgroup" : "").") VALUES (%s,%d,".$type.",%s". |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
112 ($group !== FALSE ? ",%d" : "").")"; |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
113 |
515 | 114 // Check if we are upgrading |
551
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
115 if ($upgrade) |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
116 { |
551
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
117 // Map the key, in case the name has changed |
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
118 $inKey = stUpgradeMap("key", $key); |
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
119 $inTable = stUpgradeMap("table", $table); |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
120 |
551
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
121 if (($res = stDBFetchSQL($inDB, stDBPrepareSQL($inDB, "SELECT * FROM ".$inTable." WHERE key=%s", $inKey))) !== FALSE) |
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
122 { |
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
123 // Yup, upgrade the data, if we can |
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
124 if ($res["vtype"] != $data[0]) |
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
125 die("Oops! Data type of '".$key."' does not match in table '".$table.". DB upgrade failed.\n"); |
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
126 |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
127 $sql = stDBPrepareSQL($outDB, $sqlFmt, |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
128 $key, $data[0], $res[$var], $data[2], $group); |
551
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
129 } |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
130 } |
551
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
131 |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1074
diff
changeset
|
132 if ($sql === FALSE) |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
133 { |
515 | 134 // Normal insertion of default data |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
135 $sql = stDBPrepareSQL($outDB, $sqlFmt, |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
136 $key, $data[0], $data[1], $data[2], $group); |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
137 } |
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
138 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
139 if (stDBExecSQL($outDB, $sql) === FALSE) |
519 | 140 { |
141 $status = FALSE; | |
142 break; | |
143 } | |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
144 } |
519 | 145 |
146 return $status; | |
147 } | |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
148 |
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
149 |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
150 function stAddSettingsGroup($inDB, $outDB, $groups, $groupData, $groupTable, $table, $upgrade) |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
151 { |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
152 echo ($upgrade ? "Adding settings to" : "Upgrading settings in")." '".$table."' table.\n"; |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
153 foreach ($groups as $groupID => $settings) |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
154 { |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
155 if (!isset($groupData[$groupID])) |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
156 { |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
157 echo "Group data not set for settings group ID '".$groupID."'.\n"; |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
158 return FALSE; |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
159 } |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
160 |
629
894a4a6bfb5f
Better fix for the DB migration issue.
Matti Hamalainen <ccr@tnsp.org>
parents:
628
diff
changeset
|
161 // Add group, if needed |
894a4a6bfb5f
Better fix for the DB migration issue.
Matti Hamalainen <ccr@tnsp.org>
parents:
628
diff
changeset
|
162 echo " - Group '".$groupID."' -> ".$groupData[$groupID][1]."."; |
894a4a6bfb5f
Better fix for the DB migration issue.
Matti Hamalainen <ccr@tnsp.org>
parents:
628
diff
changeset
|
163 $sql = stDBPrepareSQL($outDB, |
894a4a6bfb5f
Better fix for the DB migration issue.
Matti Hamalainen <ccr@tnsp.org>
parents:
628
diff
changeset
|
164 "INSERT INTO ".$groupTable." (name,description) VALUES (%s,%s)", |
894a4a6bfb5f
Better fix for the DB migration issue.
Matti Hamalainen <ccr@tnsp.org>
parents:
628
diff
changeset
|
165 $groupData[$groupID][0], $groupData[$groupID][1]); |
894a4a6bfb5f
Better fix for the DB migration issue.
Matti Hamalainen <ccr@tnsp.org>
parents:
628
diff
changeset
|
166 |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1074
diff
changeset
|
167 if (($gid = stDBExecSQLInsert($outDB, $sql)) === FALSE) |
628
914d57c80059
Fix database migrations now that we create settings groups.
Matti Hamalainen <ccr@tnsp.org>
parents:
620
diff
changeset
|
168 { |
629
894a4a6bfb5f
Better fix for the DB migration issue.
Matti Hamalainen <ccr@tnsp.org>
parents:
628
diff
changeset
|
169 echo "\nFailed to add group '".$groupID."'\n"; |
894a4a6bfb5f
Better fix for the DB migration issue.
Matti Hamalainen <ccr@tnsp.org>
parents:
628
diff
changeset
|
170 return FALSE; |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
171 } |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
172 |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
173 // Add settings to the group |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
174 stDBBeginTransaction($outDB); |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1074
diff
changeset
|
175 if (stDoAddSettings($inDB, $outDB, $settings, $table, $upgrade, $gid) === FALSE) |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
176 { |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
177 echo "\nFailed to add settings to group '".$groupID."'\n"; |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
178 return FALSE; |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
179 } |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
180 stDBCommitTransaction($outDB); |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
181 echo "\n"; |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
182 } |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
183 |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
184 return TRUE; |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
185 } |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
186 |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
187 |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
188 function stAddSettingsNormal($inDB, $outDB, $settings, $table, $upgrade) |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
189 { |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
190 stDBBeginTransaction($outDB); |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
191 echo ($upgrade ? "Adding settings to" : "Upgrading settings in")." '".$table."' table."; |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
192 $status = stDoAddSettings($inDB, $outDB, $settings, $table, $upgrade); |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
193 echo "\n"; |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
194 if ($status !== FALSE) |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
195 stDBCommitTransaction($outDB); |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
196 return $status; |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
197 } |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
198 |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
199 |
519 | 200 function stAddTestData($outDB) |
85
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
201 { |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
202 global $siteTestData; |
519 | 203 |
85
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
204 echo "Adding test data.\n"; |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
205 |
519 | 206 $status = TRUE; |
581 | 207 stDBBeginTransaction($outDB); |
519 | 208 |
85
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
209 foreach ($siteTestData as $table => $data) |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
210 { |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
211 echo " - ".$table."...\n"; |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
212 if (count($data) >= 3) |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
213 { |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
214 for ($n = 2; $n < count($data); $n++) |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
215 { |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
216 $arr = array_merge( |
519 | 217 array($outDB, "INSERT INTO ".$table." (".$data[0].") VALUES (".$data[1].")"), |
85
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
218 $data[$n]); |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
219 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
220 $sql = call_user_func_array('stDBPrepareSQL', $arr); |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1074
diff
changeset
|
221 if (stDBExecSQL($outDB, $sql) === FALSE) |
519 | 222 { |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1074
diff
changeset
|
223 $status = FALSE; |
519 | 224 break; |
225 } | |
85
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
226 } |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
227 } |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
228 else |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
229 { |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
230 echo " Invalid table / data definition.\n"; |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
231 } |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
232 } |
519 | 233 |
581 | 234 stDBCommitTransaction($outDB); |
519 | 235 return $status; |
85
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
236 } |
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
237 |
499 | 238 |
504
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
239 function stGetSQLTypeParam($dbh, $def, $value) |
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
240 { |
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
241 switch (substr($def, 0, 3)) |
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
242 { |
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
243 case "INT": |
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
244 return intval($value); |
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
245 |
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
246 case "VAR": |
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
247 case "TEX": |
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
248 return $dbh->quote($value); |
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
249 |
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
250 default: die("Unknown type ".$col[1].".\n"); |
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
251 } |
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
252 } |
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
253 |
519 | 254 |
551
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
255 function stMigrateTables($inDB, $outDB, $upgrade, $excluded) |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
256 { |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
257 global $sqlTables; |
519 | 258 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
259 echo "Migrating tables...\n"; |
519 | 260 $status = TRUE; |
553
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
261 $dbName = $outDB->getAttribute(PDO::ATTR_DRIVER_NAME); |
581 | 262 stDBBeginTransaction($outDB); |
519 | 263 |
553
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
264 foreach ($sqlTables as $table => $schema) |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
265 { |
553
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
266 // Do not migrate excluded tables (or excluded tables with old names) |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
267 $sequences = array(); |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
268 $inTable = $upgrade ? stUpgradeMap("table", $table) : $table; |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
269 if ($inTable === FALSE || in_array($inTable, $excluded) || in_array($table, $excluded)) |
553
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
270 continue; |
504
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
271 |
553
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
272 // Process each row of the input table |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
273 echo " - '".$table."' "; |
776
81807c56153e
Add some error checking for missing source tables in upgrades.
Matti Hamalainen <ccr@tnsp.org>
parents:
630
diff
changeset
|
274 $query = stDBExecSQL($inDB, "SELECT * FROM ".$inTable); |
81807c56153e
Add some error checking for missing source tables in upgrades.
Matti Hamalainen <ccr@tnsp.org>
parents:
630
diff
changeset
|
275 if ($query === FALSE) |
81807c56153e
Add some error checking for missing source tables in upgrades.
Matti Hamalainen <ccr@tnsp.org>
parents:
630
diff
changeset
|
276 { |
81807c56153e
Add some error checking for missing source tables in upgrades.
Matti Hamalainen <ccr@tnsp.org>
parents:
630
diff
changeset
|
277 echo "SKIPPED!"; |
81807c56153e
Add some error checking for missing source tables in upgrades.
Matti Hamalainen <ccr@tnsp.org>
parents:
630
diff
changeset
|
278 } |
81807c56153e
Add some error checking for missing source tables in upgrades.
Matti Hamalainen <ccr@tnsp.org>
parents:
630
diff
changeset
|
279 else |
81807c56153e
Add some error checking for missing source tables in upgrades.
Matti Hamalainen <ccr@tnsp.org>
parents:
630
diff
changeset
|
280 foreach ($query as $row) |
504
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
281 { |
553
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
282 // Convert to new schema, as needed |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
283 $avals = array(); |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
284 $acols = array(); |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
285 |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
286 foreach ($schema as $col) |
504
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
287 { |
553
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
288 // If input has schema column, add it to output |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
289 if (isset($row[$col[0]])) |
504
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
290 { |
553
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
291 $avals[] = stGetSQLTypeParam($outDB, $col[1], $row[$col[0]]); |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
292 $acols[] = $col[0]; |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
293 } |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
294 |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
295 // If the column should have autoincrement, add it to sequences |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
296 if (in_array("AUTOINCREMENT", $col)) |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
297 $sequences[] = $col[0]; |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
298 } |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
299 |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
300 $sql = "INSERT INTO ".$table." (".implode(",", $acols).") VALUES (".implode(",", $avals).")"; |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1074
diff
changeset
|
301 if (stDBExecSQL($outDB, $sql) === FALSE) |
553
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
302 { |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
303 $status = FALSE; |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
304 break; |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
305 } |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
306 echo "."; |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
307 } |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
308 |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
309 // Perform some specialities here |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
310 switch ($dbName) |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
311 { |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
312 case "pgsql": |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
313 // For PostgreSQL we need to update sequences |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
314 foreach ($sequences as $seq) |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
315 { |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1074
diff
changeset
|
316 if (($max_id = stDBFetchSQLColumn($outDB, "SELECT MAX(".$seq.") FROM ".$table)) !== FALSE && |
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1074
diff
changeset
|
317 ($seq_id = stDBFetchSQLColumn($outDB, "SELECT nextval('".$table."_".$seq."_seq')")) !== FALSE && |
553
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
318 ($seq_id <= $max_id)) |
540
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
319 { |
553
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
320 echo "SEQFIX"; |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
321 stDBExecSQL($outDB, "SELECT setval('".$table."_".$seq."_seq', ".$max_id.")"); |
540
ab08640b4302
Improve database upgrade code.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
322 } |
504
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
323 } |
553
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
324 break; |
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
325 } |
504
a491865e0684
Implement tables migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
326 |
553
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
327 echo "\n"; |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
328 } |
519 | 329 |
581 | 330 stDBCommitTransaction($outDB); |
519 | 331 |
332 return $status; | |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
333 } |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
334 |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
335 |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
336 function stSetDBPermissions($spec) |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
337 { |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
338 if (substr($spec, 0, 7) == "sqlite:") |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
339 { |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
340 $filename = substr($spec, 7); |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
341 echo |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
342 "NOTICE! It seems you have SQLite database in use, changing permission ". |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
343 "of the target file '".$filename."' to 0600, for security. You may have to ". |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
344 "loosen up that for the things to actually work, but be careful. Having your ". |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
345 "database world-readable in the web is NOT good.\n"; |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
346 |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
347 if (chmod($filename, 0600) === FALSE) |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
348 { |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
349 echo "ERROR! Could not set permissions of '".$filename."!\n"; |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
350 } |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
351 } |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
352 } |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
353 |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
354 |
36 | 355 // |
356 // Main program starts | |
357 // | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
358 if ($argc < 2) |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
359 { |
482
e0fd4c7ae8fb
Update commandline help, remove the commandline option for target database
Matti Hamalainen <ccr@tnsp.org>
parents:
479
diff
changeset
|
360 echo |
529
ddbc84031a7b
Rename createdb.php to managedb.php
Matti Hamalainen <ccr@tnsp.org>
parents:
528
diff
changeset
|
361 "ManageDB - Manage FAPWeb SQL database\n". |
1072 | 362 "(C) Copyright 2012-2017 ccr/TNSP\n". |
482
e0fd4c7ae8fb
Update commandline help, remove the commandline option for target database
Matti Hamalainen <ccr@tnsp.org>
parents:
479
diff
changeset
|
363 "\n". |
e0fd4c7ae8fb
Update commandline help, remove the commandline option for target database
Matti Hamalainen <ccr@tnsp.org>
parents:
479
diff
changeset
|
364 "Usage: ".$argv[0]." <mode> [args]\n". |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
365 "Where mode is one of following:\n". |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
366 "\n". |
525
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
367 " new <dbspec> Create a new database with given PDO spec\n". |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
368 " or default to the one in mconfig.inc.php\n". |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 "\n". |
525
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
370 " test <dbspec> Like new, but add initial test data.\n". |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
371 "\n". |
525
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
372 " upgrade <input_dbspec> <output_dbspec>\n". |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
373 " Upgrade current database, if possible.\n". |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
374 " Output to new database (DO NOT USE SAME as current!)\n". |
516 | 375 "\n". |
1035
d8b14f80a6f0
Add force_ugprade command.
Matti Hamalainen <ccr@tnsp.org>
parents:
1024
diff
changeset
|
376 " force_upgrade <input_dbspec> <output_dbspec>\n". |
1040 | 377 " Like 'upgrade' but without version check.\n". |
1035
d8b14f80a6f0
Add force_ugprade command.
Matti Hamalainen <ccr@tnsp.org>
parents:
1024
diff
changeset
|
378 " DO NOT USE unless you know what you are doing.\n". |
d8b14f80a6f0
Add force_ugprade command.
Matti Hamalainen <ccr@tnsp.org>
parents:
1024
diff
changeset
|
379 "\n". |
525
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
380 " migrate <input_dbspec> <output_dbspec>\n". |
516 | 381 " Like upgrade, but no version check. Creates\n". |
382 " a copy of the database to the output spec.\n". | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
383 "\n"; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
384 exit; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
385 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
386 |
541
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
387 // Validate tables data |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
388 $errors = FALSE; |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
389 foreach ($sqlTables as $table => $data) |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
390 { |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
391 if (strtolower($table) != $table) |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
392 { |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
393 echo "Invalid table definition '".$table."', table name must be lower case.\n"; |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
394 $errors = TRUE; |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
395 } |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
396 |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
397 foreach ($data as $def) |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
398 if (strtolower($def[0]) != $def[0]) |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
399 { |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
400 echo "Invalid table definition '".$table."', column key '".$def[0]."' must be lower case.\n"; |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
401 $errors = TRUE; |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
402 } |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
403 } |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
404 |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
405 if ($errors) |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
406 die("Errors in table definitions.\n"); |
e5a088dd3a4b
Validate current table schema before actions.
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
407 |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
408 |
85
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
409 // Act according to specified command |
489 | 410 $addTestData = FALSE; |
551
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
411 $upgrade = FALSE; |
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
412 |
27
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
413 switch (stCArgLC(1)) |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
414 { |
85
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
415 case "test": |
489 | 416 $addTestData = TRUE; |
85
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
417 |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
418 case "new": |
525
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
419 // Try to connect to database |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1074
diff
changeset
|
420 if (($inSpec = stCArg(2)) === FALSE) |
525
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
421 die("No PDO database spec specified.\n"); |
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
422 |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1074
diff
changeset
|
423 if (($inDB = stConnectSQLDBSpec($inSpec)) === FALSE) |
525
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
424 die("Could not connect to SQL database '".$inSpec."'.\n"); |
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
425 |
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
426 echo "Using database spec '".$inSpec."'.\n"; |
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
427 |
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
428 // Create tables, add defaults |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
429 if (stCreateTables($inDB, FALSE)) |
139
75cf14ee99a7
More work on party information system.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
430 { |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
431 stAddSettingsNormal($inDB, $inDB, $dbMetaData, "dbmeta", FALSE, FALSE); |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
432 stAddSettingsGroup($inDB, $inDB, $siteDefaultSettings, $siteSettingsGroups, "settings_groups", "settings", FALSE); |
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
433 stAddSettingsNormal($inDB, $inDB, $siteDisplayVars, "display_vars", FALSE, FALSE); |
139
75cf14ee99a7
More work on party information system.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
434 } |
27
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
435 |
489 | 436 if ($addTestData) |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
437 stAddTestData($inDB); |
85
50d6c69836a1
Add test data mode for database creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
81
diff
changeset
|
438 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
439 stSetDBPermissions($inSpec); |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
440 break; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
441 |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
442 case "upgrade": |
1035
d8b14f80a6f0
Add force_ugprade command.
Matti Hamalainen <ccr@tnsp.org>
parents:
1024
diff
changeset
|
443 case "force_upgrade": |
551
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
444 $upgrade = TRUE; |
bed441ced78e
Improve migration and upgrade procedures.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
445 |
516 | 446 case "migrate": |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
447 // |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
448 // Attempt to upgrade database |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
449 // |
525
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
450 if ($argc < 4) |
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
451 die("Usage: ".$argv[0]." upgrade <input_dbspec> <output_dbspec>\n"); |
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
452 |
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
453 $inSpec = stCArg(2); |
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
454 $outSpec = stCArg(3); |
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
455 |
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
456 if ($outSpec == $inSpec) |
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
457 die("The input and output databases CAN NOT BE SAME.\nBe VERY CAREFUL to not accidentally specify same db!\n"); |
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
458 |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
459 echo "Using INPUT database spec '".$inSpec."'.\n"; |
525
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
460 |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1074
diff
changeset
|
461 if (($inDB = stConnectSQLDBSpec($inSpec)) === FALSE) |
525
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
462 die("Could not connect to SQL database '".$inSpec."'.\n"); |
d7302b3a479e
Change database tool commandline a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
463 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
464 // Check the current version first ... |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
465 if (($currVersion = stGetDBMeta($inDB, "dbVersion")) === FALSE) |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
466 $currVersion = -1; |
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
467 |
516 | 468 if ($currVersion == $dbVersion && stCArgLC(1) == "upgrade") |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
469 { |
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
470 echo "Database is already version ".$dbVersion.", no upgrading needed.\n"; |
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
471 } |
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
472 else |
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
473 { |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
474 // Okay, we shall create an upgraded version .. |
1104
0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
Matti Hamalainen <ccr@tnsp.org>
parents:
1074
diff
changeset
|
475 if (($outDB = stConnectSQLDBSpec($outSpec)) === FALSE) |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
476 die("Could not connect to SQL database '".$outSpec."'.\n"); |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
477 |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
478 echo "Database at version ".$currVersion.", upgrading to ".$dbVersion."\n"; |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
479 echo "Using OUTPUT database spec '".$outSpec."'.\n"; |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
480 |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
481 // Possibly bail out incompatible upgrades here |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
482 |
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
483 // Create tables |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
484 if (!stCreateTables($outDB, TRUE)) |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
485 exit; |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
486 |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
487 // Migrate data from setting tables .. |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
488 if (!stAddSettingsGroup($inDB, $outDB, $siteDefaultSettings, $siteSettingsGroups, "settings_groups", "settings", TRUE)) |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
489 exit; |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
490 |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
491 if (!stAddSettingsNormal($inDB, $outDB, $siteDisplayVars, "display_vars", TRUE)) |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
492 exit; |
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
493 |
620
8444fe96120e
Implement setting groups for admin interface settings. This is just the
Matti Hamalainen <ccr@tnsp.org>
parents:
616
diff
changeset
|
494 stAddSettingsNormal($inDB, $outDB, $dbMetaData, "dbmeta", TRUE); |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
495 |
503
3232f682f0d2
Change how table schemas are defined, in preparation for future database
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
496 // Migrate other tables |
629
894a4a6bfb5f
Better fix for the DB migration issue.
Matti Hamalainen <ccr@tnsp.org>
parents:
628
diff
changeset
|
497 if (!stMigrateTables($inDB, $outDB, $upgrade, array("settings", "display_vars", "dbmeta", "settings_groups"))) |
503
3232f682f0d2
Change how table schemas are defined, in preparation for future database
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
498 exit; |
553
f13e7a513db1
Fix sequences after database upgrade or migration.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
499 |
616 | 500 // Set new database version |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
501 echo "Setting dbVersion.\n"; |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
502 stSetDBMeta($outDB, "dbVersion", $dbVersion); |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
503 echo "Upgrade complete.\n"; |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
504 |
502
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
505 stSetDBPermissions($inSpec); |
d2a38070e18f
Partially refactor database upgrading .. not finished yet, and the
Matti Hamalainen <ccr@tnsp.org>
parents:
500
diff
changeset
|
506 stSetDBPermissions($outSpec); |
199
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
507 } |
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
508 break; |
dbc6f214b825
Work on a database upgrade function.
Matti Hamalainen <ccr@tnsp.org>
parents:
185
diff
changeset
|
509 |
27
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
510 default: |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
511 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n"; |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
512 break; |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
513 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
514 |
28 | 515 |
516 // | |
517 // Clean up permissions | |
518 // | |
835
1cc9af3f90f0
Renamed the site tool, fix it here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
804
diff
changeset
|
519 foreach (array("managedb.php", "faptool.php") as $filename) |
28 | 520 { |
630 | 521 if (@chmod($filename, 0700) === FALSE) |
28 | 522 { |
490
505f46b8bb14
Separate variable from string flow.
Matti Hamalainen <ccr@tnsp.org>
parents:
489
diff
changeset
|
523 echo "ERROR! Could not set permissions for '".$filename."'!\n"; |
28 | 524 } |
525 } | |
526 | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
527 ?> |