From b3d5bd33f88f4ff0dbc8cc8631c896244d7079c9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20=C5=A0koda?= Date: Wed, 5 Mar 2014 16:33:41 +0800 Subject: [PATCH] MDL-44451 fix plugin_misplaced_exception exception --- lib/upgradelib.php | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/upgradelib.php b/lib/upgradelib.php index c87f9482db9..611f44c6690 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -98,14 +98,37 @@ class plugin_defective_exception extends moodle_exception { } /** + * Misplaced plugin exception. + * + * Note: this should be used only from the upgrade/admin code. + * * @package core * @subpackage upgrade * @copyright 2009 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class plugin_misplaced_exception extends moodle_exception { - function __construct($component, $expected, $current) { + /** + * Constructor. + * @param string $component the component from version.php + * @param string $expected expected directory, null means calculate + * @param string $current plugin directory path + */ + public function __construct($component, $expected, $current) { global $CFG; + if (empty($expected)) { + list($type, $plugin) = core_component::normalize_component($component); + $plugintypes = core_component::get_plugin_types(); + if (isset($plugintypes[$type])) { + $expected = $plugintypes[$type] . '/' . $plugin; + } + } + if (strpos($expected, '$CFG->dirroot') !== 0) { + $expected = str_replace($CFG->dirroot, '$CFG->dirroot', $expected); + } + if (strpos($current, '$CFG->dirroot') !== 0) { + $current = str_replace($CFG->dirroot, '$CFG->dirroot', $current); + } $a = new stdClass(); $a->component = $component; $a->expected = $expected; @@ -424,9 +447,7 @@ function upgrade_plugins($type, $startcallback, $endcallback, $verbose) { // if plugin tells us it's full name we may check the location if (isset($plugin->component)) { if ($plugin->component !== $component) { - $current = str_replace($CFG->dirroot, '$CFG->dirroot', $fullplug); - $expected = str_replace($CFG->dirroot, '$CFG->dirroot', core_component::get_component_directory($plugin->component)); - throw new plugin_misplaced_exception($component, $expected, $current); + throw new plugin_misplaced_exception($plugin->component, null, $fullplug); } } @@ -584,9 +605,7 @@ function upgrade_plugins_modules($startcallback, $endcallback, $verbose) { // if plugin tells us it's full name we may check the location if (isset($plugin->component)) { if ($plugin->component !== $component) { - $current = str_replace($CFG->dirroot, '$CFG->dirroot', $fullmod); - $expected = str_replace($CFG->dirroot, '$CFG->dirroot', core_component::get_component_directory($plugin->component)); - throw new plugin_misplaced_exception($component, $expected, $current); + throw new plugin_misplaced_exception($plugin->component, null, $fullmod); } } @@ -764,9 +783,7 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) { // if plugin tells us it's full name we may check the location if (isset($plugin->component)) { if ($plugin->component !== $component) { - $current = str_replace($CFG->dirroot, '$CFG->dirroot', $fullblock); - $expected = str_replace($CFG->dirroot, '$CFG->dirroot', core_component::get_component_directory($plugin->component)); - throw new plugin_misplaced_exception($component, $expected, $current); + throw new plugin_misplaced_exception($plugin->component, null, $fullblock); } } -- 2.11.4.GIT