Skip to content
Permalink
Browse files

Merge branch 'w08_MDL-38121_m25_plugincheck' of git://github.com/skod…

…ak/moodle
  • Loading branch information...
danpoltawski committed Feb 25, 2013
2 parents f4e34c5 + bdbcb6d commit bbd045b9e6be42c4507ae09b3a75878840942f05
Showing with 49 additions and 3 deletions.
  1. +1 −0 lang/en/plugin.php
  2. +4 −0 lib/moodlelib.php
  3. +4 −0 lib/pluginlib.php
  4. +40 −3 lib/upgradelib.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.';
@@ -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) {
@@ -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;
}
@@ -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);
}
}

0 comments on commit bbd045b

Please sign in to comment.
You can’t perform that action at this time.