From 5f8aaf220f6ea567706489f206550a4382125180 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 22 May 2024 20:52:11 +0100 Subject: [PATCH] MDL-81870 core: validate component during upgrade task savepoint. --- lang/en/error.php | 1 + lib/upgradelib.php | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lang/en/error.php b/lang/en/error.php index b57d693aa76..60c0daf77a9 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 f0ca4bb42ce..598395e21d7 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -459,17 +459,16 @@ function upgrade_block_savepoint($result, $version, $blockname, $allowabort=true } /** - * 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 +479,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) {