[FIX] Properly run all upgrades
This commit is contained in:
parent
ab2a065b9a
commit
a9d7726617
@ -19,6 +19,15 @@ class Setting extends Base {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flush our local cache, may be required for upgrades
|
||||||
|
* or other places where we need live data
|
||||||
|
**/
|
||||||
|
public function flushCache() {
|
||||||
|
$this->cache = array();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a value from our table
|
* Fetch a value from our table
|
||||||
* @param name string Setting name
|
* @param name string Setting name
|
||||||
|
|||||||
@ -13,6 +13,12 @@ $db_version_now = $setting->getValue('DB_VERSION');
|
|||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
function run_db_upgrade($db_version_now) {
|
function run_db_upgrade($db_version_now) {
|
||||||
|
// Dirty, but need it here
|
||||||
|
global $setting;
|
||||||
|
|
||||||
|
// Drop caches from our settings for live data
|
||||||
|
$setting->flushCache();
|
||||||
|
|
||||||
// Find upgrades
|
// Find upgrades
|
||||||
$files = glob(dirname(__FILE__) . "/definitions/${db_version_now}_to_*");
|
$files = glob(dirname(__FILE__) . "/definitions/${db_version_now}_to_*");
|
||||||
if (count($files) == 0) die('No upgrade definitions found for ' . $db_version_now . PHP_EOL);
|
if (count($files) == 0) die('No upgrade definitions found for ' . $db_version_now . PHP_EOL);
|
||||||
@ -23,14 +29,19 @@ function run_db_upgrade($db_version_now) {
|
|||||||
if (!require_once($file)) die('Failed to load upgrade definition: ' . $file);
|
if (!require_once($file)) die('Failed to load upgrade definition: ' . $file);
|
||||||
echo "+ Running upgrade from $db_version_now to $db_version_to" . PHP_EOL;
|
echo "+ Running upgrade from $db_version_now to $db_version_to" . PHP_EOL;
|
||||||
$run = "run_$run_string";
|
$run = "run_$run_string";
|
||||||
$run();
|
if (function_exists($run)) {
|
||||||
run_db_upgrade($db_version_to);
|
$run();
|
||||||
|
run_db_upgrade($db_version_to);
|
||||||
|
} else {
|
||||||
|
echo 'Could find upgrade function ' . $run . '!' . PHP_EOL;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function execute_db_upgrade($aSql) {
|
function execute_db_upgrade($aSql) {
|
||||||
global $mysqli;
|
global $mysqli;
|
||||||
// Run the upgrade
|
// Run the upgrade
|
||||||
echo '- Starting database migration to version ' . $db_version_new . PHP_EOL;
|
echo '- Starting database migration ' . PHP_EOL;
|
||||||
foreach ($aSql as $sql) {
|
foreach ($aSql as $sql) {
|
||||||
echo '- Preparing: ' . $sql . PHP_EOL;
|
echo '- Preparing: ' . $sql . PHP_EOL;
|
||||||
$stmt = $mysqli->prepare($sql);
|
$stmt = $mysqli->prepare($sql);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user