diff --git a/lang/en/plugin.php b/lang/en/plugin.php index 4d4dd8c222971..ae319422b05ef 100644 --- a/lang/en/plugin.php +++ b/lang/en/plugin.php @@ -29,6 +29,7 @@ $string['availability'] = 'Availability'; $string['checkforupdates'] = 'Check for available updates'; $string['checkforupdateslast'] = 'Last check done on {$a}'; +$string['detectedmisplacedplugin'] = 'Plugin "{$a->component}" is installed in incorrect location "{$a->current}", expected location is "{$a->expected}"'; $string['displayname'] = 'Plugin name'; $string['err_response_curl'] = 'Unable to fetch available updates data - unexpected cURL error.'; $string['err_response_format_version'] = 'Unexpected version of the response format. Please try to re-check for available updates.'; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 6890a8320028e..c3afd0926c355 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -9134,10 +9134,14 @@ function moodle_needs_upgrading() { continue; } $module = new stdClass(); + $plugin = new stdClass(); if (!is_readable($fullmod.'/version.php')) { continue; } include($fullmod.'/version.php'); // defines $module with version etc + if (!isset($module->version) and isset($plugin->version)) { + $module = $plugin; + } if (empty($installed[$mod])) { return true; } else if ($module->version > $installed[$mod]->version) { diff --git a/lib/pluginlib.php b/lib/pluginlib.php index 57e15fb5f77f1..a626ab4881c9d 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -2857,9 +2857,13 @@ protected function load_version_php() { $versionfile = $this->full_path('version.php'); $module = new stdClass(); + $plugin = new stdClass(); if (is_readable($versionfile)) { include($versionfile); } + if (!isset($module->version) and isset($plugin->version)) { + $module = $plugin; + } return $module; } diff --git a/lib/upgradelib.php b/lib/upgradelib.php index 938258334ac29..33a185cf3d2df 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -97,6 +97,23 @@ function __construct($plugin, $details) { } } +/** + * @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) { + global $CFG; + $a = new stdClass(); + $a->component = $component; + $a->expected = $expected; + $a->current = $current; + parent::__construct('detectedmisplacedplugin', 'core_plugin', "$CFG->wwwroot/$CFG->admin/index.php", $a); + } +} + /** * Sets maximum expected time needed for upgrade task. * Please always make sure that upgrade will not run longer! @@ -381,12 +398,19 @@ function upgrade_plugins($type, $startcallback, $endcallback, $verbose) { } $plugin = new stdClass(); + $module = new stdClass(); // Prevent some notices when plugin placed in wrong directory. require($fullplug.'/version.php'); // defines $plugin with version etc + if (!isset($plugin->version) and isset($module->version)) { + $plugin = $module; + } + // if plugin tells us it's full name we may check the location if (isset($plugin->component)) { if ($plugin->component !== $component) { - throw new plugin_defective_exception($component, 'Plugin installed in wrong folder.'); + $current = str_replace($CFG->dirroot, '$CFG->dirroot', $fullplug); + $expected = str_replace($CFG->dirroot, '$CFG->dirroot', get_component_directory($plugin->component)); + throw new plugin_misplaced_exception($component, $expected, $current); } } @@ -532,12 +556,19 @@ function upgrade_plugins_modules($startcallback, $endcallback, $verbose) { } $module = new stdClass(); + $plugin = new stdClass(); // Prevent some notices when plugin placed in wrong directory. require($fullmod .'/version.php'); // defines $module with version etc + if (!isset($module->version) and isset($plugin->version)) { + $module = $plugin; + } + // if plugin tells us it's full name we may check the location if (isset($module->component)) { if ($module->component !== $component) { - throw new plugin_defective_exception($component, 'Plugin installed in wrong folder.'); + $current = str_replace($CFG->dirroot, '$CFG->dirroot', $fullmod); + $expected = str_replace($CFG->dirroot, '$CFG->dirroot', get_component_directory($module->component)); + throw new plugin_misplaced_exception($component, $expected, $current); } } @@ -703,15 +734,21 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) { throw new plugin_defective_exception('block/'.$blockname, 'Missing version.php file.'); } $plugin = new stdClass(); + $module = new stdClass(); // Prevent some notices when module placed in wrong directory. $plugin->version = NULL; $plugin->cron = 0; include($fullblock.'/version.php'); + if (!isset($plugin->version) and isset($module->version)) { + $plugin = $module; + } $block = $plugin; // if plugin tells us it's full name we may check the location if (isset($block->component)) { if ($block->component !== $component) { - throw new plugin_defective_exception($component, 'Plugin installed in wrong folder.'); + $current = str_replace($CFG->dirroot, '$CFG->dirroot', $fullblock); + $expected = str_replace($CFG->dirroot, '$CFG->dirroot', get_component_directory($block->component)); + throw new plugin_misplaced_exception($component, $expected, $current); } }