Merge branch 'MDL-56057_master' of git://github.com/dmonllao/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 17 Oct 2016 16:42:14 +0000 (18:42 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 17 Oct 2016 16:42:14 +0000 (18:42 +0200)
lib/adminlib.php
search/classes/manager.php

index e9fcd07..68e1b48 100644 (file)
@@ -9700,19 +9700,13 @@ class admin_setting_searchsetupinfo extends admin_setting {
         $return = '';
         $brtag = html_writer::empty_tag('br');
 
-        // Available search areas.
         $searchareas = \core_search\manager::get_search_areas_list();
-        $anyenabled = false;
+        $anyenabled = !empty(\core_search\manager::get_search_areas_list(true));
         $anyindexed = false;
         foreach ($searchareas as $areaid => $searcharea) {
             list($componentname, $varname) = $searcharea->get_config_var_name();
-            if (!$anyenabled) {
-                $anyenabled = get_config($componentname, $varname . '_enabled');
-            }
-            if (!$anyindexed) {
-                $anyindexed = get_config($componentname, $varname . '_indexingstart');
-            }
-            if ($anyenabled && $anyindexed) {
+            if (get_config($componentname, $varname . '_indexingstart')) {
+                $anyindexed = true;
                 break;
             }
         }
index cfbab0b..f6f7599 100644 (file)
@@ -198,13 +198,10 @@ class manager {
      */
     public static function get_search_area($areaid) {
 
-        // Try both caches, it does not matter where it comes from.
+        // We have them all here.
         if (!empty(static::$allsearchareas[$areaid])) {
             return static::$allsearchareas[$areaid];
         }
-        if (!empty(static::$enabledsearchareas[$areaid])) {
-            return static::$enabledsearchareas[$areaid];
-        }
 
         $classname = static::get_area_classname($areaid);
 
@@ -224,13 +221,16 @@ class manager {
     public static function get_search_areas_list($enabled = false) {
 
         // Two different arrays, we don't expect these arrays to be big.
-        if (!$enabled && static::$allsearchareas !== null) {
-            return static::$allsearchareas;
-        } else if ($enabled && static::$enabledsearchareas !== null) {
-            return static::$enabledsearchareas;
+        if (static::$allsearchareas !== null) {
+            if (!$enabled) {
+                return static::$allsearchareas;
+            } else {
+                return static::$enabledsearchareas;
+            }
         }
 
-        $searchareas = array();
+        static::$allsearchareas = array();
+        static::$enabledsearchareas = array();
 
         $plugintypes = \core_component::get_plugin_types();
         foreach ($plugintypes as $plugintype => $unused) {
@@ -248,8 +248,10 @@ class manager {
 
                     $areaid = static::generate_areaid($componentname, $areaname);
                     $searchclass = new $classname();
-                    if (!$enabled || ($enabled && $searchclass->is_enabled())) {
-                        $searchareas[$areaid] = $searchclass;
+
+                    static::$allsearchareas[$areaid] = $searchclass;
+                    if ($searchclass->is_enabled()) {
+                        static::$enabledsearchareas[$areaid] = $searchclass;
                     }
                 }
             }
@@ -269,20 +271,17 @@ class manager {
 
                 $areaid = static::generate_areaid($componentname, $areaname);
                 $searchclass = new $classname();
-                if (!$enabled || ($enabled && $searchclass->is_enabled())) {
-                    $searchareas[$areaid] = $searchclass;
+                static::$allsearchareas[$areaid] = $searchclass;
+                if ($searchclass->is_enabled()) {
+                    static::$enabledsearchareas[$areaid] = $searchclass;
                 }
             }
         }
 
-        // Cache results.
         if ($enabled) {
-            static::$enabledsearchareas = $searchareas;
-        } else {
-            static::$allsearchareas = $searchareas;
+            return static::$enabledsearchareas;
         }
-
-        return $searchareas;
+        return static::$allsearchareas;
     }
 
     /**