MDL-44451 fix plugin_misplaced_exception exception

This commit is contained in:
Petr Škoda 2014-03-05 16:33:41 +08:00
parent 00dabc896b
commit b3d5bd33f8

View File

@ -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);
}
}