We now have a pre update script (#5425)

* We now have a pre update script

* Some optimized stuff
This commit is contained in:
Michael Vogel 2018-07-20 21:47:16 +02:00 committed by Hypolite Petovan
parent b26da6096b
commit 4bbcb61a9e
3 changed files with 40 additions and 19 deletions

View File

@ -703,10 +703,17 @@ function update_db()
return; return;
} }
// run the pre_update_nnnn functions in update.php
for ($x = $stored + 1; $x <= $current; $x++) {
$r = run_update_function($x, 'pre_update');
if (!$r) {
break;
}
}
Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, time()); Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, time());
// run update routine // update the structure in one call
// it update the structure in one call
$retval = DBStructure::update(false, true); $retval = DBStructure::update(false, true);
if ($retval) { if ($retval) {
DBStructure::updateFail( DBStructure::updateFail(
@ -718,9 +725,9 @@ function update_db()
Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success'); Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success');
} }
// run any left update_nnnn functions in update.php // run the update_nnnn functions in update.php
for ($x = $stored + 1; $x <= $current; $x++) { for ($x = $stored + 1; $x <= $current; $x++) {
$r = run_update_function($x); $r = run_update_function($x, 'update');
if (!$r) { if (!$r) {
break; break;
} }
@ -731,9 +738,11 @@ function update_db()
return; return;
} }
function run_update_function($x) function run_update_function($x, $prefix)
{ {
if (function_exists('update_' . $x)) { $funcname = $prefix . '_' . $x;
if (function_exists($funcname)) {
// There could be a lot of processes running or about to run. // There could be a lot of processes running or about to run.
// We want exactly one process to run the update command. // We want exactly one process to run the update command.
// So store the fact that we're taking responsibility // So store the fact that we're taking responsibility
@ -741,16 +750,14 @@ function run_update_function($x)
// If the update fails or times-out completely you may need to // If the update fails or times-out completely you may need to
// delete the config entry to try again. // delete the config entry to try again.
$t = Config::get('database', 'update_' . $x); $t = Config::get('database', $funcname);
if (!is_null($t)) { if (!is_null($t)) {
return false; return false;
} }
Config::set('database', 'update_' . $x, time()); Config::set('database', $funcname, time());
// call the specific update // call the specific update
$retval = $funcname();
$func = 'update_' . $x;
$retval = $func();
if ($retval) { if ($retval) {
//send the administrator an e-mail //send the administrator an e-mail
@ -760,13 +767,17 @@ function run_update_function($x)
); );
return false; return false;
} else { } else {
Config::set('database', 'update_' . $x, 'success'); Config::set('database', $funcname, 'success');
if ($post_update) {
Config::set('system', 'build', $x); Config::set('system', 'build', $x);
}
return true; return true;
} }
} else { } else {
Config::set('database', 'update_' . $x, 'success'); Config::set('database', $funcname, 'success');
if ($post_update) {
Config::set('system', 'build', $x); Config::set('system', 'build', $x);
}
return true; return true;
} }
} }

View File

@ -69,8 +69,6 @@ HELP;
$output = DBStructure::update(true, false); $output = DBStructure::update(true, false);
break; break;
case "update": case "update":
$output = DBStructure::update(true, true);
$build = Core\Config::get('system', 'build'); $build = Core\Config::get('system', 'build');
if (empty($build)) { if (empty($build)) {
Core\Config::set('system', 'build', DB_UPDATE_VERSION); Core\Config::set('system', 'build', DB_UPDATE_VERSION);
@ -80,9 +78,19 @@ HELP;
$stored = intval($build); $stored = intval($build);
$current = intval(DB_UPDATE_VERSION); $current = intval(DB_UPDATE_VERSION);
// run any left update_nnnn functions in update.php // run the pre_update_nnnn functions in update.php
for ($x = $stored; $x < $current; $x ++) { for ($x = $stored; $x < $current; $x ++) {
$r = run_update_function($x); $r = run_update_function($x, 'pre_update');
if (!$r) {
break;
}
}
$output = DBStructure::update(true, true);
// run the update_nnnn functions in update.php
for ($x = $stored; $x < $current; $x ++) {
$r = run_update_function($x, 'update');
if (!$r) { if (!$r) {
break; break;
} }

View File

@ -33,6 +33,8 @@ require_once 'include/dba.php';
* 1. Create a function "update_4712()" here in the update.php * 1. Create a function "update_4712()" here in the update.php
* 2. Apply the needed structural changes in src/Database/DBStructure.php * 2. Apply the needed structural changes in src/Database/DBStructure.php
* 3. Set DB_UPDATE_VERSION in boot.php to 4712. * 3. Set DB_UPDATE_VERSION in boot.php to 4712.
*
* If you need to run a script before the database update, name the function "pre_update_4712()"
*/ */
function update_1178() { function update_1178() {