diff --git a/admin/index.php b/admin/index.php index 7b1cd06502b..e78d218a349 100644 --- a/admin/index.php +++ b/admin/index.php @@ -47,7 +47,9 @@ if (!function_exists('iconv')) { define('NO_OUTPUT_BUFFERING', true); -if (empty($_GET['cache']) and empty($_POST['cache']) and empty($_GET['sesskey']) and empty($_POST['sesskey'])) { +if ((isset($_GET['cache']) and $_GET['cache'] === '0') + or (isset($_POST['cache']) and $_POST['cache'] === '0') + or (!isset($_POST['cache']) and !isset($_GET['cache']) and empty($_GET['sesskey']) and empty($_POST['sesskey']))) { // Prevent caching at all cost when visiting this page directly, // we redirect to self once we known no upgrades are necessary. // Note: $_GET and $_POST are used here intentionally because our param cleaning is not loaded yet. @@ -72,9 +74,7 @@ $cache = optional_param('cache', 0, PARAM_BOOL); // Set up PAGE. $url = new moodle_url('/admin/index.php'); -if ($cache) { - $url->param('cache', $cache); -} +$url->param('cache', $cache); $PAGE->set_url($url); unset($url); @@ -249,11 +249,13 @@ if ($version > $CFG->version) { // upgrade $PAGE->set_pagelayout('maintenance'); $PAGE->set_popup_notification_allowed(false); + /** @var core_admin_renderer $output */ + $output = $PAGE->get_renderer('core', 'admin'); + if (upgrade_stale_php_files_present()) { $PAGE->set_title($stradministration); $PAGE->set_cacheable(false); - $output = $PAGE->get_renderer('core', 'admin'); echo $output->upgrade_stale_php_files_page(); die(); } @@ -268,7 +270,6 @@ if ($version > $CFG->version) { // upgrade $PAGE->set_heading($strdatabasechecking); $PAGE->set_cacheable(false); - $output = $PAGE->get_renderer('core', 'admin'); echo $output->upgrade_confirm_page($a->newversion, $maturity, $testsite); die(); @@ -282,7 +283,6 @@ if ($version > $CFG->version) { // upgrade $PAGE->set_heading($strcurrentrelease); $PAGE->set_cacheable(false); - $output = $PAGE->get_renderer('core', 'admin'); echo $output->upgrade_environment_page($release, $envstatus, $environment_results); die(); @@ -296,31 +296,22 @@ if ($version > $CFG->version) { // upgrade $reloadurl = new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)); - // check plugin dependencies first - $failed = array(); - if (!plugin_manager::instance()->all_plugins_ok($version, $failed)) { - $output = $PAGE->get_renderer('core', 'admin'); - echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl); - die(); - } - unset($failed); - if ($fetchupdates) { - // no sesskey support guaranteed here - if (empty($CFG->disableupdatenotifications)) { - available_update_checker::instance()->fetch(); + $updateschecker = available_update_checker::instance(); + if ($updateschecker->enabled()) { + // No sesskey support guaranteed here, because sessions might not work yet. + $updateschecker->fetch(); } redirect($reloadurl); } - $output = $PAGE->get_renderer('core', 'admin'); - $deployer = available_update_deployer::instance(); if ($deployer->enabled()) { $deployer->initialize($reloadurl, $reloadurl); $deploydata = $deployer->submitted_data(); if (!empty($deploydata)) { + // No sesskey support guaranteed here, because sessions might not work yet. echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata); die(); } @@ -332,7 +323,18 @@ if ($version > $CFG->version) { // upgrade die(); } else { - // Launch main upgrade + // Always verify plugin dependencies! + $failed = array(); + if (!plugin_manager::instance()->all_plugins_ok($version, $failed)) { + $PAGE->set_pagelayout('maintenance'); + $PAGE->set_popup_notification_allowed(false); + $reloadurl = new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)); + echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl); + die(); + } + unset($failed); + + // Launch main upgrade. upgrade_core($version, true); } } else if ($version < $CFG->version) { @@ -352,6 +354,10 @@ if ($branch <> $CFG->branch) { // Update the branch if (moodle_needs_upgrading()) { if (!$PAGE->headerprinted) { // means core upgrade or installation was not already done + + /** @var core_admin_renderer $output */ + $output = $PAGE->get_renderer('core', 'admin'); + if (!$confirmplugins) { $strplugincheck = get_string('plugincheck'); @@ -363,39 +369,44 @@ if (moodle_needs_upgrading()) { $PAGE->set_cacheable(false); if ($fetchupdates) { - // no sesskey support guaranteed here - available_update_checker::instance()->fetch(); - redirect($PAGE->url); + $updateschecker = available_update_checker::instance(); + if ($updateschecker->enabled()) { + require_sesskey(); + $updateschecker->fetch(); + } + redirect($reloadurl); } - $output = $PAGE->get_renderer('core', 'admin'); - $deployer = available_update_deployer::instance(); if ($deployer->enabled()) { $deployer->initialize($PAGE->url, $PAGE->url); $deploydata = $deployer->submitted_data(); if (!empty($deploydata)) { + require_sesskey(); echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata); die(); } } - // check plugin dependencies first - $failed = array(); - if (!plugin_manager::instance()->all_plugins_ok($version, $failed)) { - echo $output->unsatisfied_dependencies_page($version, $failed, $PAGE->url); - die(); - } - unset($failed); - - // dependencies check passed, let's rock! + // Show plugins info. echo $output->upgrade_plugin_check_page(plugin_manager::instance(), available_update_checker::instance(), $version, $showallplugins, new moodle_url($PAGE->url), new moodle_url('/admin/index.php', array('confirmplugincheck'=>1))); die(); } + + // Always verify plugin dependencies! + $failed = array(); + if (!plugin_manager::instance()->all_plugins_ok($version, $failed)) { + $PAGE->set_pagelayout('maintenance'); + $PAGE->set_popup_notification_allowed(false); + $reloadurl = new moodle_url('/admin/index.php', array('cache' => 0)); + echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl); + die(); + } + unset($failed); } // install/upgrade all plugins and other parts upgrade_noncore(true); @@ -456,6 +467,17 @@ if (during_initial_install()) { upgrade_finished('upgradesettings.php'); } +if (has_capability('moodle/site:config', context_system::instance())) { + if ($fetchupdates) { + $updateschecker = available_update_checker::instance(); + if ($updateschecker->enabled()) { + require_sesskey(); + $updateschecker->fetch(); + } + redirect(new moodle_url('/admin/index.php', array('cache' => 0))); + } +} + // Now we can be sure everything was upgraded and caches work fine, // redirect if necessary to make sure caching is enabled. if (!$cache and !optional_param('sesskey', '', PARAM_RAW)) { @@ -534,12 +556,6 @@ $registered = $DB->count_records('registration_hubs', array('huburl' => HUB_MOOD admin_externalpage_setup('adminnotifications'); -if ($fetchupdates) { - require_sesskey(); - $updateschecker->fetch(); - redirect(new moodle_url('/admin/index.php')); -} - $output = $PAGE->get_renderer('core', 'admin'); echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb, diff --git a/admin/renderer.php b/admin/renderer.php index ad36d346314..6171a69ad59 100644 --- a/admin/renderer.php +++ b/admin/renderer.php @@ -170,7 +170,7 @@ class core_admin_renderer extends plugin_renderer_base { $output .= $this->environment_check_table($envstatus, $environment_results); if (!$envstatus) { - $output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1)); + $output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1, 'cache' => 0)); } else { $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess'); @@ -179,7 +179,7 @@ class core_admin_renderer extends plugin_renderer_base { $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice'); } - $output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1))); + $output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0))); } $output .= $this->footer(); @@ -701,7 +701,7 @@ class core_admin_renderer extends plugin_renderer_base { } $updateinfo .= $this->container_start('checkforupdates'); - $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 1)); + $fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0)); $updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin')); if ($fetch) { $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin', @@ -952,7 +952,7 @@ class core_admin_renderer extends plugin_renderer_base { $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin')); if (empty($options['full'])) { $out .= html_writer::link(new moodle_url('/admin/index.php', - array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)), + array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1, 'cache' => 0)), get_string('nonehighlightedinfo', 'core_plugin')); } $out .= $this->output->container_end(); @@ -962,11 +962,11 @@ class core_admin_renderer extends plugin_renderer_base { $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted)); if (empty($options['full'])) { $out .= html_writer::link(new moodle_url('/admin/index.php', - array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)), + array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1, 'cache' => 0)), get_string('somehighlightedinfo', 'core_plugin')); } else { $out .= html_writer::link(new moodle_url('/admin/index.php', - array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 0)), + array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 0, 'cache' => 0)), get_string('somehighlightedonly', 'core_plugin')); } $out .= $this->output->container_end(); diff --git a/lib/pluginlib.php b/lib/pluginlib.php index f2a8e780c4d..9ca87ec9c3b 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -1035,6 +1035,18 @@ class available_update_checker { } } + /** + * Is automatic deployment enabled? + * + * @return bool + */ + public function enabled() { + global $CFG; + + // The feature can be prohibited via config.php. + return empty($CFG->disableupdateautodeploy); + } + /** * Returns the timestamp of the last execution of {@link fetch()} * @@ -1810,9 +1822,6 @@ class available_update_info { */ class available_update_deployer { - const HTTP_PARAM_PREFIX = 'updteautodpldata_'; // Hey, even Google has not heard of such a prefix! So it MUST be safe :-p - const HTTP_PARAM_CHECKER = 'datapackagesize'; // Name of the parameter that holds the number of items in the received data items - /** @var available_update_deployer holds the singleton instance */ protected static $singletoninstance; /** @var moodle_url URL of a page that includes the deployer UI */ @@ -1985,9 +1994,19 @@ class available_update_deployer { throw new coding_exception('Illegal method call - deployer not initialized.'); } - $params = $this->data_to_params(array( - 'updateinfo' => (array)$info, // see http://www.php.net/manual/en/language.types.array.php#language.types.array.casting - )); + $params = array( + 'updateaddon' => $info->component, + 'version' =>$info->version, + 'sesskey' => sesskey(), + ); + + // Append some our own data. + if (!empty($this->callerurl)) { + $params['callerurl'] = $this->callerurl->out(false); + } + if (!empty($this->returnurl)) { + $params['returnurl'] = $this->returnurl->out(false); + } $widget = new single_button( new moodle_url($this->callerurl, $params), @@ -2079,25 +2098,46 @@ class available_update_deployer { * @return array */ public function submitted_data() { - - $data = $this->params_to_data($_POST); - - if (empty($data) or empty($data[self::HTTP_PARAM_CHECKER])) { + $component = optional_param('updateaddon', '', PARAM_COMPONENT); + $version = optional_param('version', '', PARAM_RAW); + if (!$component or !$version) { return false; } - if (!empty($data['updateinfo']) and is_object($data['updateinfo'])) { - $updateinfo = $data['updateinfo']; - if (!empty($updateinfo->component) and !empty($updateinfo->version)) { - $data['updateinfo'] = new available_update_info($updateinfo->component, (array)$updateinfo); + $plugininfo = plugin_manager::instance()->get_plugin_info($component); + if (!$plugininfo) { + return false; + } + + if ($plugininfo->is_standard()) { + return false; + } + + if (!$updates = $plugininfo->available_updates()) { + return false; + } + + $info = null; + foreach ($updates as $update) { + if ($update->version == $version) { + $info = $update; + break; } } - - if (!empty($data['callerurl'])) { - $data['callerurl'] = new moodle_url($data['callerurl']); + if (!$info) { + return false; } - if (!empty($data['returnurl'])) { + $data = array( + 'updateaddon' => $component, + 'updateinfo' => $info, + 'callerurl' => optional_param('callerurl', null, PARAM_URL), + 'returnurl' => optional_param('returnurl', null, PARAM_URL), + ); + if ($data['callerurl']) { + $data['callerurl'] = new moodle_url($data['callerurl']); + } + if ($data['callerurl']) { $data['returnurl'] = new moodle_url($data['returnurl']); } @@ -2196,62 +2236,6 @@ class available_update_deployer { } } - // End of external API - - /** - * Prepares an array of HTTP parameters that can be passed to another page. - * - * @param array|object $data associative array or an object holding the data, data JSON-able - * @return array suitable as a param for moodle_url - */ - protected function data_to_params($data) { - - // Append some our own data - if (!empty($this->callerurl)) { - $data['callerurl'] = $this->callerurl->out(false); - } - if (!empty($this->returnurl)) { - $data['returnurl'] = $this->returnurl->out(false); - } - - // Finally append the count of items in the package. - $data[self::HTTP_PARAM_CHECKER] = count($data); - - // Generate params - $params = array(); - foreach ($data as $name => $value) { - $transname = self::HTTP_PARAM_PREFIX.$name; - $transvalue = json_encode($value); - $params[$transname] = $transvalue; - } - - return $params; - } - - /** - * Converts HTTP parameters passed to the script into native PHP data - * - * @param array $params such as $_REQUEST or $_POST - * @return array data passed for this class - */ - protected function params_to_data(array $params) { - - if (empty($params)) { - return array(); - } - - $data = array(); - foreach ($params as $name => $value) { - if (strpos($name, self::HTTP_PARAM_PREFIX) === 0) { - $realname = substr($name, strlen(self::HTTP_PARAM_PREFIX)); - $realvalue = json_decode($value); - $data[$realname] = $realvalue; - } - } - - return $data; - } - /** * Returns a random string to be used as a filename of the password storage. *