MDL-55390 core_search: check if a search area is real
authorDevang Gaur <devang.only@gmail.com>
Thu, 4 Aug 2016 19:42:21 +0000 (01:12 +0530)
committerDevang Gaur <devang.only@gmail.com>
Thu, 4 Aug 2016 19:42:21 +0000 (01:12 +0530)
search/classes/manager.php

index 7aa5b46..87d1cad 100644 (file)
@@ -240,6 +240,11 @@ class manager {
                 $searchclasses = \core_component::get_component_classes_in_namespace($componentname, 'search');
                 foreach ($searchclasses as $classname => $classpath) {
                     $areaname = substr(strrchr($classname, '\\'), 1);
+
+                    if (!static::is_search_area($classname)) {
+                        continue;
+                    }
+
                     $areaid = static::generate_areaid($componentname, $areaname);
                     $searchclass = new $classname();
                     if (!$enabled || ($enabled && $searchclass->is_enabled())) {
@@ -256,6 +261,11 @@ class manager {
 
             foreach ($searchclasses as $classname => $classpath) {
                 $areaname = substr(strrchr($classname, '\\'), 1);
+
+                if (!static::is_search_area($classname)) {
+                    continue;
+                }
+
                 $areaid = static::generate_areaid($componentname, $areaname);
                 $searchclass = new $classname();
                 if (!$enabled || ($enabled && $searchclass->is_enabled())) {
@@ -716,4 +726,19 @@ class manager {
         }
         return $configsettings;
     }
+
+    /**
+     * Checks whether a classname is of an actual search area.
+     *
+     * @param string $searchareaname
+     * @return bool
+     */
+    protected static function is_search_area($searchareaname) {
+        if (is_subclass_of($searchareaname, 'core_search\base')) {
+            $$searchareaname = new \ReflectionClass($searchareaname);
+            return $$searchareaname->IsInstantiable();
+        }
+
+        return false;
+    }
 }