diff --git a/lib/upgradelib.php b/lib/upgradelib.php index a0113235f42..4b3bb1ec91c 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; @@ -422,9 +445,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); } } @@ -578,9 +599,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); } } @@ -755,9 +774,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); } }