MDL-34099 Report available updates for plugins at admin/index.php
authorDavid Mudrák <david@moodle.com>
Thu, 13 Sep 2012 14:34:47 +0000 (16:34 +0200)
committerDavid Mudrák <david@moodle.com>
Thu, 8 Nov 2012 21:33:05 +0000 (22:33 +0100)
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
admin/renderer.php
lang/en/admin.php

index 410cbf6..d3ec395 100644 (file)
@@ -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€');
index 293bf52..bf45639 100644 (file)
@@ -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);
index c2ae229..a0c3226 100644 (file)
@@ -774,6 +774,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 <a href="{$a->url}">plugins overview</a> page for more details.';
 $string['profilecategory'] = 'Category';
 $string['profilecategoryname'] = 'Category name (must be unique)';
 $string['profilecategorynamenotunique'] = 'This category name is already in use';