From c56e55e4765063b3986d99e18c3beb4e0696daf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Thu, 13 Sep 2012 16:34:47 +0200 Subject: [PATCH] MDL-34099 Report available updates for plugins at admin/index.php The Notifications (admin/index.php) page has now information about available updates for core and eventually plugins, too. Note that the structure of the available updates array changed. This breaks backward compatibility for eventual 3rd renderers out there (not expected though). --- admin/index.php | 23 ++++++++++++++++++++++- admin/renderer.php | 30 ++++++++++++++++++++++++------ lang/en/admin.php | 1 + 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/admin/index.php b/admin/index.php index 410cbf6..d3ec395 100644 --- a/admin/index.php +++ b/admin/index.php @@ -416,9 +416,30 @@ $cronoverdue = ($lastcron < time() - 3600 * 24); $dbproblems = $DB->diagnose(); $maintenancemode = !empty($CFG->maintenance_enabled); +// Available updates for Moodle core $updateschecker = available_update_checker::instance(); -$availableupdates = $updateschecker->get_update_info('core', +$availableupdates = array(); +$availableupdates['core'] = $updateschecker->get_update_info('core', array('minmaturity' => $CFG->updateminmaturity, 'notifybuilds' => $CFG->updatenotifybuilds)); + +// Available updates for contributed plugins +$pluginman = plugin_manager::instance(); +foreach ($pluginman->get_plugins() as $plugintype => $plugintypeinstances) { + foreach ($plugintypeinstances as $pluginname => $plugininfo) { + if (!empty($plugininfo->availableupdates)) { + foreach ($plugininfo->availableupdates as $pluginavailableupdate) { + if ($pluginavailableupdate->version > $plugininfo->versiondisk) { + if (!isset($availableupdates[$plugintype.'_'.$pluginname])) { + $availableupdates[$plugintype.'_'.$pluginname] = array(); + } + $availableupdates[$plugintype.'_'.$pluginname][] = $pluginavailableupdate; + } + } + } + } +} + +// The timestamp of the most recent check for available updates $availableupdatesfetch = $updateschecker->get_last_timefetched(); $buggyiconvnomb = (!function_exists('mb_convert_encoding') and @iconv('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€'); diff --git a/admin/renderer.php b/admin/renderer.php index 3a3c2bd..84912a6 100644 --- a/admin/renderer.php +++ b/admin/renderer.php @@ -495,21 +495,39 @@ class core_admin_renderer extends plugin_renderer_base { } /** - * Displays the info about available Moodle updates + * Displays the info about available Moodle core and plugin updates * - * @param array|null $updates array of available_update_info objects or null + * The structure of the $updates param has changed since 2.4. It contains not only updates + * for the core itself, but also for all other installed plugins. + * + * @param array|null $updates array of (string)component => array of available_update_info objects or null * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown) * @return string */ protected function available_updates($updates, $fetch) { $updateinfo = $this->box_start('generalbox adminwarning availableupdatesinfo'); + $someupdateavailable = false; if (is_array($updates)) { - $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3); - foreach ($updates as $update) { - $updateinfo .= $this->moodle_available_update_info($update); + if (is_array($updates['core'])) { + $someupdateavailable = true; + $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3); + foreach ($updates['core'] as $update) { + $updateinfo .= $this->moodle_available_update_info($update); + } } - } else { + unset($updates['core']); + // If something has left in the $updates array now, it is updates for plugins. + if (!empty($updates)) { + $someupdateavailable = true; + $updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3); + $pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1)); + $updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin', + array('url' => $pluginsoverviewurl->out()))); + } + } + + if (!$someupdateavailable) { $now = time(); if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) { $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3); diff --git a/lang/en/admin.php b/lang/en/admin.php index cf38bf9..d9cf011 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -762,6 +762,7 @@ $string['pluginscheck'] = 'Plugin dependencies check'; $string['pluginscheckfailed'] = 'Dependencies check failed for {$a->pluginslist}'; $string['pluginschecktodo'] = 'You must solve all the plugin requirements before proceeding to install this Moodle version!'; $string['pluginsoverview'] = 'Plugins overview'; +$string['pluginsoverviewsee'] = 'See plugins overview page for more details.'; $string['profilecategory'] = 'Category'; $string['profilecategoryname'] = 'Category name (must be unique)'; $string['profilecategorynamenotunique'] = 'This category name is already in use'; -- 1.7.3.4