diff --git a/lang/en/error.php b/lang/en/error.php index f167239c64f..d62d8f2aae5 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -504,6 +504,7 @@ $string['pagenotexist'] = '
An unusual error occurred trying to view a page th $string['passwordexceeded'] = 'The password can\'t be more than {$a} characters.'; $string['pathdoesnotstartslash'] = 'No valid arguments supplied, path does not start with slash!'; $string['pleasereport'] = 'If you have time, please let us know what you were trying to do when the error occurred:'; +$string['pluginnotexist'] = '{$a} plugin doesn\'t exist'; $string['pluginrequirementsnotmet'] = 'Plugin "{$a->pluginname}" ({$a->pluginversion}) could not be installed. It requires a newer version of Moodle (currently you are using {$a->currentmoodle}, you need {$a->requiremoodle}).'; $string['pluginunsupported'] = 'Plugin "{$a->pluginname}" {$a->pluginversion} does not support this version of Moodle {$a->moodleversion}. Seek plugin information to find supported versions.'; $string['prefixcannotbeempty'] = '
Error: database table prefix cannot be empty ({$a})
diff --git a/lib/upgradelib.php b/lib/upgradelib.php index e0df4a55587..d4cbfcd16fd 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -373,43 +373,12 @@ function upgrade_main_savepoint($result, $version, $allowabort=true) { * * @category upgrade * @param bool $result false if upgrade step failed, true if completed - * @param string or float $version main version + * @param string|float $version main version * @param string $modname name of module * @param bool $allowabort allow user to abort script execution here - * @return void */ function upgrade_mod_savepoint($result, $version, $modname, $allowabort=true) { - global $DB; - - $component = 'mod_'.$modname; - - if (!$result) { - throw new upgrade_exception($component, $version); - } - - $dbversion = $DB->get_field('config_plugins', 'value', array('plugin'=>$component, 'name'=>'version')); - - if (!$module = $DB->get_record('modules', array('name'=>$modname))) { - throw new \moodle_exception('modulenotexist', 'debug', '', $modname); - } - - if ($dbversion >= $version) { - // something really wrong is going on in upgrade script - throw new downgrade_exception($component, $dbversion, $version); - } - set_config('version', $version, $component); - - upgrade_log(UPGRADE_LOG_NORMAL, $component, 'Upgrade savepoint reached'); - - // reset upgrade timeout to default - upgrade_set_timeout(); - - core_upgrade_time::record_savepoint($version); - - // this is a safe place to stop upgrades if user aborts page loading - if ($allowabort and connection_aborted()) { - die; - } + upgrade_plugin_savepoint($result, $version, 'mod', $modname, $allowabort); } /** @@ -419,57 +388,25 @@ function upgrade_mod_savepoint($result, $version, $modname, $allowabort=true) { * * @category upgrade * @param bool $result false if upgrade step failed, true if completed - * @param string or float $version main version + * @param string|float $version main version * @param string $blockname name of block * @param bool $allowabort allow user to abort script execution here - * @return void */ function upgrade_block_savepoint($result, $version, $blockname, $allowabort=true) { - global $DB; - - $component = 'block_'.$blockname; - - if (!$result) { - throw new upgrade_exception($component, $version); - } - - $dbversion = $DB->get_field('config_plugins', 'value', array('plugin'=>$component, 'name'=>'version')); - - if (!$block = $DB->get_record('block', array('name'=>$blockname))) { - throw new \moodle_exception('blocknotexist', 'debug', '', $blockname); - } - - if ($dbversion >= $version) { - // something really wrong is going on in upgrade script - throw new downgrade_exception($component, $dbversion, $version); - } - set_config('version', $version, $component); - - upgrade_log(UPGRADE_LOG_NORMAL, $component, 'Upgrade savepoint reached'); - - // reset upgrade timeout to default - upgrade_set_timeout(); - - core_upgrade_time::record_savepoint($version); - - // this is a safe place to stop upgrades if user aborts page loading - if ($allowabort and connection_aborted()) { - die; - } + upgrade_plugin_savepoint($result, $version, 'block', $blockname, $allowabort); } /** - * Plugins upgrade savepoint, marks end of blocks upgrade blocks + * Plugins upgrade savepoint, marks end of plugin upgrade blocks * It stores plugin version, resets upgrade timeout * and abort upgrade if user cancels page loading. * * @category upgrade * @param bool $result false if upgrade step failed, true if completed - * @param string or float $version main version + * @param string|float $version main version * @param string $type The type of the plugin. * @param string $plugin The name of the plugin. * @param bool $allowabort allow user to abort script execution here - * @return void */ function upgrade_plugin_savepoint($result, $version, $type, $plugin, $allowabort=true) { global $DB; @@ -480,6 +417,11 @@ function upgrade_plugin_savepoint($result, $version, $type, $plugin, $allowabort throw new upgrade_exception($component, $version); } + // Ensure we're dealing with a real component. + if (core_component::get_component_directory($component) === null) { + throw new moodle_exception('pluginnotexist', 'error', '', $component); + } + $dbversion = $DB->get_field('config_plugins', 'value', array('plugin'=>$component, 'name'=>'version')); if ($dbversion >= $version) {