diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 60def990ef8..43c3e57e5e7 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -8734,47 +8734,6 @@ function moodle_major_version($fromdisk = false) { } } -/** - * Sets maximum expected time needed for upgrade task. - * Please always make sure that upgrade will not run longer! - * - * The script may be automatically aborted if upgrade times out. - * - * @category upgrade - * @param int $max_execution_time in seconds (can not be less than 60 s) - * @todo MDL-32293 - Move this function to lib/upgradelib.php - */ -function upgrade_set_timeout($max_execution_time=300) { - global $CFG; - - if (!isset($CFG->upgraderunning) or $CFG->upgraderunning < time()) { - $upgraderunning = get_config(null, 'upgraderunning'); - } else { - $upgraderunning = $CFG->upgraderunning; - } - - if (!$upgraderunning) { - // upgrade not running or aborted - print_error('upgradetimedout', 'admin', "$CFG->wwwroot/$CFG->admin/"); - die; - } - - if ($max_execution_time < 60) { - // protection against 0 here - $max_execution_time = 60; - } - - $expected_end = time() + $max_execution_time; - - if ($expected_end < $upgraderunning + 10 and $expected_end > $upgraderunning - 10) { - // no need to store new end, it is nearly the same ;-) - return; - } - - set_time_limit($max_execution_time); - set_config('upgraderunning', $expected_end); // keep upgrade locked until this time -} - /// MISCELLANEOUS //////////////////////////////////////////////////////////////////// /** diff --git a/lib/upgradelib.php b/lib/upgradelib.php index 6db42165dc7..a7c540ef9c5 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -97,6 +97,46 @@ class plugin_defective_exception extends moodle_exception { } } +/** + * Sets maximum expected time needed for upgrade task. + * Please always make sure that upgrade will not run longer! + * + * The script may be automatically aborted if upgrade times out. + * + * @category upgrade + * @param int $max_execution_time in seconds (can not be less than 60 s) + */ +function upgrade_set_timeout($max_execution_time=300) { + global $CFG; + + if (!isset($CFG->upgraderunning) or $CFG->upgraderunning < time()) { + $upgraderunning = get_config(null, 'upgraderunning'); + } else { + $upgraderunning = $CFG->upgraderunning; + } + + if (!$upgraderunning) { + // upgrade not running or aborted + print_error('upgradetimedout', 'admin', "$CFG->wwwroot/$CFG->admin/"); + die; + } + + if ($max_execution_time < 60) { + // protection against 0 here + $max_execution_time = 60; + } + + $expected_end = time() + $max_execution_time; + + if ($expected_end < $upgraderunning + 10 and $expected_end > $upgraderunning - 10) { + // no need to store new end, it is nearly the same ;-) + return; + } + + set_time_limit($max_execution_time); + set_config('upgraderunning', $expected_end); // keep upgrade locked until this time +} + /** * Upgrade savepoint, marks end of each upgrade block. * It stores new main version, resets upgrade timeout