diff --git a/admin/cli/install.php b/admin/cli/install.php index 4b373820943..b37161c6ad4 100644 --- a/admin/cli/install.php +++ b/admin/cli/install.php @@ -636,6 +636,23 @@ if (!file_exists($configfile)) { 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 diff --git a/admin/cli/upgrade.php b/admin/cli/upgrade.php index 6f49cc1a1a9..31a23c27805 100644 --- a/admin/cli/upgrade.php +++ b/admin/cli/upgrade.php @@ -93,7 +93,7 @@ if ($version < $CFG->version) { $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); @@ -105,6 +105,11 @@ if (!$envstatus) { 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; diff --git a/admin/index.php b/admin/index.php index 631f7890162..10220d24e41 100644 --- a/admin/index.php +++ b/admin/index.php @@ -212,8 +212,8 @@ if ($version > $CFG->version) { // upgrade $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'); @@ -224,7 +224,7 @@ if ($version > $CFG->version) { // upgrade $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(); @@ -257,7 +257,7 @@ if (moodle_needs_upgrading()) { $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(); diff --git a/admin/renderer.php b/admin/renderer.php index c90c4130ce0..e74c0951ac8 100644 --- a/admin/renderer.php +++ b/admin/renderer.php @@ -119,7 +119,7 @@ class core_admin_renderer extends plugin_renderer_base { $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'); @@ -137,19 +137,23 @@ class core_admin_renderer extends plugin_renderer_base { * 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(); @@ -388,11 +392,11 @@ class core_admin_renderer extends plugin_renderer_base { * (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)) { @@ -475,7 +479,7 @@ class core_admin_renderer extends plugin_renderer_base { $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)); @@ -537,12 +541,11 @@ class core_admin_renderer extends plugin_renderer_base { * @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'; diff --git a/lang/en/admin.php b/lang/en/admin.php index 0f626f871c6..19d1da0cd4e 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -745,6 +745,7 @@ $string['pleaserefreshregistration'] = 'Your site has been registered with moodl $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)'; diff --git a/lib/pluginlib.php b/lib/pluginlib.php index cbbc062f419..6f2c8bb0d99 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -235,8 +235,6 @@ class plugin_manager { * @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)) { @@ -251,6 +249,28 @@ class plugin_manager { 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 *