comparison managedb.php @ 1120:b2bca5f6d0ff default tip

Cosmetic cleanup: remove trailing whitespace.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 13 Dec 2020 13:47:13 +0200
parents 24e6915fc0fb
children
comparison
equal deleted inserted replaced
1119:a4daa7ea7479 1120:b2bca5f6d0ff
142 break; 142 break;
143 } 143 }
144 } 144 }
145 145
146 return $status; 146 return $status;
147 } 147 }
148 148
149 149
150 function stAddSettingsGroup($inDB, $outDB, $groups, $groupData, $groupTable, $table, $upgrade) 150 function stAddSettingsGroup($inDB, $outDB, $groups, $groupData, $groupTable, $table, $upgrade)
151 { 151 {
152 echo ($upgrade ? "Adding settings to" : "Upgrading settings in")." '".$table."' table.\n"; 152 echo ($upgrade ? "Adding settings to" : "Upgrading settings in")." '".$table."' table.\n";
155 if (!isset($groupData[$groupID])) 155 if (!isset($groupData[$groupID]))
156 { 156 {
157 echo "Group data not set for settings group ID '".$groupID."'.\n"; 157 echo "Group data not set for settings group ID '".$groupID."'.\n";
158 return FALSE; 158 return FALSE;
159 } 159 }
160 160
161 // Add group, if needed 161 // Add group, if needed
162 echo " - Group '".$groupID."' -> ".$groupData[$groupID][1]."."; 162 echo " - Group '".$groupID."' -> ".$groupData[$groupID][1].".";
163 $sql = stDBPrepareSQL($outDB, 163 $sql = stDBPrepareSQL($outDB,
164 "INSERT INTO ".$groupTable." (name,description) VALUES (%s,%s)", 164 "INSERT INTO ".$groupTable." (name,description) VALUES (%s,%s)",
165 $groupData[$groupID][0], $groupData[$groupID][1]); 165 $groupData[$groupID][0], $groupData[$groupID][1]);
167 if (($gid = stDBExecSQLInsert($outDB, $sql)) === FALSE) 167 if (($gid = stDBExecSQLInsert($outDB, $sql)) === FALSE)
168 { 168 {
169 echo "\nFailed to add group '".$groupID."'\n"; 169 echo "\nFailed to add group '".$groupID."'\n";
170 return FALSE; 170 return FALSE;
171 } 171 }
172 172
173 // Add settings to the group 173 // Add settings to the group
174 stDBBeginTransaction($outDB); 174 stDBBeginTransaction($outDB);
175 if (stDoAddSettings($inDB, $outDB, $settings, $table, $upgrade, $gid) === FALSE) 175 if (stDoAddSettings($inDB, $outDB, $settings, $table, $upgrade, $gid) === FALSE)
176 { 176 {
177 echo "\nFailed to add settings to group '".$groupID."'\n"; 177 echo "\nFailed to add settings to group '".$groupID."'\n";
258 258
259 echo "Migrating tables...\n"; 259 echo "Migrating tables...\n";
260 $status = TRUE; 260 $status = TRUE;
261 $dbName = $outDB->getAttribute(PDO::ATTR_DRIVER_NAME); 261 $dbName = $outDB->getAttribute(PDO::ATTR_DRIVER_NAME);
262 stDBBeginTransaction($outDB); 262 stDBBeginTransaction($outDB);
263 263
264 foreach ($sqlTables as $table => $schema) 264 foreach ($sqlTables as $table => $schema)
265 { 265 {
266 // Do not migrate excluded tables (or excluded tables with old names) 266 // Do not migrate excluded tables (or excluded tables with old names)
267 $sequences = array(); 267 $sequences = array();
268 $inTable = $upgrade ? stUpgradeMap("table", $table) : $table; 268 $inTable = $upgrade ? stUpgradeMap("table", $table) : $table;
280 foreach ($query as $row) 280 foreach ($query as $row)
281 { 281 {
282 // Convert to new schema, as needed 282 // Convert to new schema, as needed
283 $avals = array(); 283 $avals = array();
284 $acols = array(); 284 $acols = array();
285 285
286 foreach ($schema as $col) 286 foreach ($schema as $col)
287 { 287 {
288 // If input has schema column, add it to output 288 // If input has schema column, add it to output
289 if (isset($row[$col[0]])) 289 if (isset($row[$col[0]]))
290 { 290 {
391 if (strtolower($table) != $table) 391 if (strtolower($table) != $table)
392 { 392 {
393 echo "Invalid table definition '".$table."', table name must be lower case.\n"; 393 echo "Invalid table definition '".$table."', table name must be lower case.\n";
394 $errors = TRUE; 394 $errors = TRUE;
395 } 395 }
396 396
397 foreach ($data as $def) 397 foreach ($data as $def)
398 if (strtolower($def[0]) != $def[0]) 398 if (strtolower($def[0]) != $def[0])
399 { 399 {
400 echo "Invalid table definition '".$table."', column key '".$def[0]."' must be lower case.\n"; 400 echo "Invalid table definition '".$table."', column key '".$def[0]."' must be lower case.\n";
401 $errors = TRUE; 401 $errors = TRUE;
430 { 430 {
431 stAddSettingsNormal($inDB, $inDB, $dbMetaData, "dbmeta", FALSE, FALSE); 431 stAddSettingsNormal($inDB, $inDB, $dbMetaData, "dbmeta", FALSE, FALSE);
432 stAddSettingsGroup($inDB, $inDB, $siteDefaultSettings, $siteSettingsGroups, "settings_groups", "settings", FALSE); 432 stAddSettingsGroup($inDB, $inDB, $siteDefaultSettings, $siteSettingsGroups, "settings_groups", "settings", FALSE);
433 stAddSettingsNormal($inDB, $inDB, $siteDisplayVars, "display_vars", FALSE, FALSE); 433 stAddSettingsNormal($inDB, $inDB, $siteDisplayVars, "display_vars", FALSE, FALSE);
434 } 434 }
435 435
436 if ($addTestData) 436 if ($addTestData)
437 stAddTestData($inDB); 437 stAddTestData($inDB);
438 438
439 stSetDBPermissions($inSpec); 439 stSetDBPermissions($inSpec);
440 break; 440 break;
477 477
478 echo "Database at version ".$currVersion.", upgrading to ".$dbVersion."\n"; 478 echo "Database at version ".$currVersion.", upgrading to ".$dbVersion."\n";
479 echo "Using OUTPUT database spec '".$outSpec."'.\n"; 479 echo "Using OUTPUT database spec '".$outSpec."'.\n";
480 480
481 // Possibly bail out incompatible upgrades here 481 // Possibly bail out incompatible upgrades here
482 482
483 // Create tables 483 // Create tables
484 if (!stCreateTables($outDB, TRUE)) 484 if (!stCreateTables($outDB, TRUE))
485 exit; 485 exit;
486 486
487 // Migrate data from setting tables .. 487 // Migrate data from setting tables ..
494 stAddSettingsNormal($inDB, $outDB, $dbMetaData, "dbmeta", TRUE); 494 stAddSettingsNormal($inDB, $outDB, $dbMetaData, "dbmeta", TRUE);
495 495
496 // Migrate other tables 496 // Migrate other tables
497 if (!stMigrateTables($inDB, $outDB, $upgrade, array("settings", "display_vars", "dbmeta", "settings_groups"))) 497 if (!stMigrateTables($inDB, $outDB, $upgrade, array("settings", "display_vars", "dbmeta", "settings_groups")))
498 exit; 498 exit;
499 499
500 // Set new database version 500 // Set new database version
501 echo "Setting dbVersion.\n"; 501 echo "Setting dbVersion.\n";
502 stSetDBMeta($outDB, "dbVersion", $dbVersion); 502 stSetDBMeta($outDB, "dbVersion", $dbVersion);
503 echo "Upgrade complete.\n"; 503 echo "Upgrade complete.\n";
504 504