Skip to content

Commit

Permalink
MDL-29474 prevent install/upgrade if plugin dependancies not met.
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Oct 20, 2011
1 parent cc35956 commit faadd32
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 19 deletions.
17 changes: 17 additions & 0 deletions admin/cli/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,23 @@
cli_error('Can not create config file.');
}

// Test environment first.
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
if (!$envstatus) {
$errors = environment_get_errors($environment_results);
cli_heading(get_string('environment', 'admin'));
foreach ($errors as $error) {
list($info, $report) = $error;
echo "!! $info !!\n$report\n\n";
}
exit(1);
}

// Test plugin dependancies.
if (!plugin_manager::instance()->all_plugins_ok($version)) {
cli_error(get_string('pluginschecktodo', 'admin'));
}

// remember selected language
$installlang = $CFG->lang;
// return back to original dir before executing setup.php which changes the dir again
Expand Down
7 changes: 6 additions & 1 deletion admin/cli/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
$oldversion = "$CFG->release ($CFG->version)";
$newversion = "$release ($version)";

// test environment first
// Test environment first.
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
if (!$envstatus) {
$errors = environment_get_errors($environment_results);
Expand All @@ -105,6 +105,11 @@
exit(1);
}

// Test plugin dependancies.
if (!plugin_manager::instance()->all_plugins_ok($version)) {
cli_error(get_string('pluginschecktodo', 'admin'));
}

if ($interactive) {
$a = new stdClass();
$a->oldversion = $oldversion;
Expand Down
8 changes: 4 additions & 4 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@
$PAGE->set_cacheable(false);

$output = $PAGE->get_renderer('core', 'admin');
echo $this->upgrade_environment_page($release, $envstatus, $environment_results);
die;
echo $output->upgrade_environment_page($release, $envstatus, $environment_results);
die();

} else if (empty($confirmplugins)) {
$strplugincheck = get_string('plugincheck');
Expand All @@ -224,7 +224,7 @@
$PAGE->set_cacheable(false);

$output = $PAGE->get_renderer('core', 'admin');
echo $output->upgrade_plugin_check_page(plugin_manager::instance(), $showallplugins,
echo $output->upgrade_plugin_check_page(plugin_manager::instance(), $version, $showallplugins,
new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)),
new moodle_url('/admin/index.php', array('confirmupgrade'=>1, 'confirmrelease'=>1, 'confirmplugincheck'=>1)));
die();
Expand Down Expand Up @@ -257,7 +257,7 @@
$PAGE->set_cacheable(false);

$output = $PAGE->get_renderer('core', 'admin');
echo $output->upgrade_plugin_check_page(plugin_manager::instance(), $showallplugins,
echo $output->upgrade_plugin_check_page(plugin_manager::instance(), $version, $showallplugins,
new moodle_url('/admin/index.php'),
new moodle_url('/admin/index.php', array('confirmplugincheck'=>1)));
die();
Expand Down
27 changes: 15 additions & 12 deletions admin/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function upgrade_environment_page($release, $envstatus, $environment_resu
$output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1));

} else {
echo $output->notification(get_string('environmentok', 'admin'), 'notifysuccess');
$output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');

if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
$output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
Expand All @@ -137,19 +137,23 @@ public function upgrade_environment_page($release, $envstatus, $environment_resu
* Display the upgrade page that lists all the plugins that require attention.
* @return string HTML to output.
*/
public function upgrade_plugin_check_page($pluginman, $showallplugins, $reloadurl, $continueurl) {
public function upgrade_plugin_check_page($pluginman, $version, $showallplugins, $reloadurl, $continueurl) {
$output = '';

$output .= $this->header();
$output .= $this->box_start('generalbox');
$output .= $this->container(get_string('pluginchecknotice', 'core_plugin'), 'generalbox', 'notice');
$output .= $this->plugins_check_table($pluginman, array('full' => $showallplugins));
$output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
$output .= $this->box_end();
$output .= $this->upgrade_reload($reloadurl);

$button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
$button->class = 'continuebutton';
$output .= $this->render($button);
if ($pluginman->all_plugins_ok($version)) {
$button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
$button->class = 'continuebutton';
$output .= $this->render($button);
} else {
$output .= $this->box(get_string('pluginschecktodo', 'admin'), 'environmentbox errorbox');
}

$output .= $this->footer();

Expand Down Expand Up @@ -388,11 +392,11 @@ function upgrade_reload($url) {
* (bool)full = false: whether to display up-to-date plugins, too
*
* @param plugin_manager $pluginman provides information about the plugins.
* @param int $version the version of the Moodle code from version.php.
* @param array $options rendering options
* @return string HTML code
*/
public function plugins_check_table(plugin_manager $pluginman, array $options = null) {
global $CFG;
public function plugins_check_table(plugin_manager $pluginman, $version, array $options = null) {
$plugininfo = $pluginman->get_plugins();

if (empty($plugininfo)) {
Expand Down Expand Up @@ -475,7 +479,7 @@ public function plugins_check_table(plugin_manager $pluginman, array $options =

$status = new html_table_cell(get_string('status_' . $statuscode, 'core_plugin'));

$requires = new html_table_cell($this->required_column($plugin, $pluginman));
$requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));

$statusisboring = in_array($statuscode, array(
plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE));
Expand Down Expand Up @@ -537,12 +541,11 @@ public function plugins_check_table(plugin_manager $pluginman, array $options =
* @param plugin_information $plugin the plugin we are rendering the row for.
* @param plugin_manager $pluginman provides data on all the plugins.
*/
protected function required_column($plugin, $pluginman) {
global $CFG;
protected function required_column($plugin, $pluginman, $version) {
$requires = array();

if (!empty($plugin->versionrequires)) {
if ($plugin->versionrequires <= $CFG->version) {
if ($plugin->versionrequires <= $version) {
$class = 'requires-ok';
} else {
$class = 'requires-failed';
Expand Down
1 change: 1 addition & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@
$string['pleaseregister'] = 'Please register your site to remove this button';
$string['plugin'] = 'Plugin';
$string['plugins'] = 'Plugins';
$string['pluginschecktodo'] = 'You must solve all the plugin requirements before proceeding to install this Moodle version!';
$string['pluginsoverview'] = 'Plugins overview';
$string['profilecategory'] = 'Category';
$string['profilecategoryname'] = 'Category name (must be unique)';
Expand Down
24 changes: 22 additions & 2 deletions lib/pluginlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ public function get_plugin_info($component) {
* @return bool true if all the dependancies are satisfied.
*/
public function are_dependancies_satisfied($dependancies) {
$installedplugins = $this->get_plugins();

foreach ($dependancies as $component => $requiredversion) {
$otherplugin = $this->get_plugin_info($component);
if (is_null($otherplugin)) {
Expand All @@ -251,6 +249,28 @@ public function are_dependancies_satisfied($dependancies) {
return true;
}

/**
* Checks all dependancies for all installed plugins. Used by install and upgrade.
* @param int $moodleversion the version from version.php.
* @return bool true if all the dependancies are satisfied for all plugins.
*/
public function all_plugins_ok($moodleversion) {
foreach ($this->get_plugins() as $type => $plugins) {
foreach ($plugins as $plugin) {

if (!empty($plugin->versionrequires) && $plugin->versionrequires > $moodleversion) {
return false;
}

if (!$this->are_dependancies_satisfied($plugin->get_other_required_plugins())) {
return false;
}
}
}

return true;
}

/**
* Defines a white list of all plugins shipped in the standard Moodle distribution
*
Expand Down

0 comments on commit faadd32

Please sign in to comment.