diff --git a/admin/index.php b/admin/index.php index 7ea72af6a92..d41b06845dc 100644 --- a/admin/index.php +++ b/admin/index.php @@ -593,10 +593,14 @@ $availableupdatesfetch = $updateschecker->get_last_timefetched(); $buggyiconvnomb = (!function_exists('mb_convert_encoding') and @iconv('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€'); //check if the site is registered on Moodle.org $registered = $DB->count_records('registration_hubs', array('huburl' => HUB_MOODLEORGHUBURL, 'confirmed' => 1)); +// Check if there are any cache warnings. +$cachewarnings = cache_helper::warnings(); admin_externalpage_setup('adminnotifications'); +/* @var core_admin_renderer $output */ $output = $PAGE->get_renderer('core', 'admin'); -echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, - $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb, - $registered); + +echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, $cronoverdue, $dbproblems, + $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb, + $registered, $cachewarnings); diff --git a/admin/renderer.php b/admin/renderer.php index 81d2ac5fda2..2803e05a27f 100644 --- a/admin/renderer.php +++ b/admin/renderer.php @@ -303,12 +303,13 @@ class core_admin_renderer extends plugin_renderer_base { * @param bool $buggyiconvnomb warn iconv problems * @param array|null $availableupdates array of \core\update\info objects or null * @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown) + * @param string[] $cachewarnings An array containing warnings from the Cache API. * * @return string HTML to output. */ public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch, - $buggyiconvnomb, $registered) { + $buggyiconvnomb, $registered, array $cachewarnings = array()) { global $CFG; $output = ''; @@ -321,6 +322,7 @@ class core_admin_renderer extends plugin_renderer_base { $output .= $this->cron_overdue_warning($cronoverdue); $output .= $this->db_problems($dbproblems); $output .= $this->maintenance_mode_warning($maintenancemode); + $output .= $this->cache_warnings($cachewarnings); $output .= $this->registration_warning($registered); ////////////////////////////////////////////////////////////////////////////////////////////////// @@ -583,6 +585,19 @@ class core_admin_renderer extends plugin_renderer_base { return $this->warning($dbproblems); } + /** + * Renders cache warnings if there are any. + * + * @param string[] $cachewarnings + * @return string + */ + public function cache_warnings(array $cachewarnings) { + if (!count($cachewarnings)) { + return ''; + } + return join("\n", array_map(array($this, 'warning'), $cachewarnings)); + } + /** * Render an appropriate message if the site in in maintenance mode. * @param bool $maintenancemode diff --git a/cache/admin.php b/cache/admin.php index ba49777a54c..827b13719e3 100644 --- a/cache/admin.php +++ b/cache/admin.php @@ -280,15 +280,7 @@ if (!empty($action) && confirm_sesskey()) { } } -// Stores can add notices to the cache configuration screen for things like conflicting configurations etc. -// Here we check each cache to see if it has warnings. -foreach ($stores as $store) { - if (!empty($store['warnings']) && is_array($store['warnings'])) { - foreach ($store['warnings'] as $warning) { - $notifications[] = array($warning, false); - } - } -} +$notifications = array_merge($notifications, cache_helper::warnings($stores)); $PAGE->set_title($title); $PAGE->set_heading($SITE->fullname); @@ -297,7 +289,7 @@ $renderer = $PAGE->get_renderer('core_cache'); echo $renderer->header(); echo $renderer->heading($title); -echo $renderer->notififications($notifications); +echo $renderer->notifications($notifications); if ($mform instanceof moodleform) { $mform->display(); diff --git a/cache/classes/helper.php b/cache/classes/helper.php index 015ed8a184b..f4d5022ab90 100644 --- a/cache/classes/helper.php +++ b/cache/classes/helper.php @@ -735,4 +735,28 @@ class cache_helper { } return $stores; } + + /** + * Returns an array of warnings from the cache API. + * + * The warning returned here are for things like conflicting store instance configurations etc. + * These get shown on the admin notifications page for example. + * + * @param array|null $stores An array of stores to get warnings for, or null for all. + * @return string[] + */ + public static function warnings(array $stores = null) { + global $CFG; + if ($stores === null) { + require_once($CFG->dirroot.'/cache/locallib.php'); + $stores = cache_administration_helper::get_store_instance_summaries(); + } + $warnings = array(); + foreach ($stores as $store) { + if (!empty($store['warnings'])) { + $warnings = array_merge($warnings, $store['warnings']); + } + } + return $warnings; + } } diff --git a/cache/classes/store.php b/cache/classes/store.php index c5081f920a1..e40fed57716 100644 --- a/cache/classes/store.php +++ b/cache/classes/store.php @@ -345,7 +345,11 @@ abstract class cache_store implements cache_store_interface { * This should be used to notify things like configuration conflicts etc. * The warnings returned here will be displayed on the cache configuration screen. * - * @return string[] Returns an array of warnings (strings) + * @return array[] Returns an array of arrays with the format: + * $notifications = array( + * array('This is a success message', true), + * array('This is a failure message', false), + * ); */ public function get_warnings() { return array(); diff --git a/cache/renderer.php b/cache/renderer.php index dbf7e88a80e..2b18d6b3fe5 100644 --- a/cache/renderer.php +++ b/cache/renderer.php @@ -376,10 +376,16 @@ class core_cache_renderer extends plugin_renderer_base { /** * Renders an array of notifications for the cache configuration screen. * + * Takes an array of notifications with the form: + * $notifications = array( + * array('This is a success message', true), + * array('This is a failure message', false), + * ); + * * @param array $notifications * @return string */ - public function notififications(array $notifications = array()) { + public function notifications(array $notifications = array()) { if (count($notifications) === 0) { // There are no notifications to render. return '';