From b9c6ff44ec65e910ce841efc2cbe08b013e7b251 Mon Sep 17 00:00:00 2001 From: Hamish Friedlander Date: Thu, 19 Jul 2012 12:52:37 +1200 Subject: [PATCH] BUG Dont try and load SearchVariants that dont apply to this env --- code/search/SearchVariant.php | 11 ++++++++++- code/search/SearchVariantSiteTreeSubsitesPolyhome.php | 4 ++++ code/search/SearchVariantVersioned.php | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/code/search/SearchVariant.php b/code/search/SearchVariant.php index 4c18778..425cf82 100644 --- a/code/search/SearchVariant.php +++ b/code/search/SearchVariant.php @@ -15,6 +15,12 @@ abstract class SearchVariant { * with specific ones */ + /** + * Return false if there is something missing from the environment (probably a + * not installed module) that means this variant can't apply to any class + */ + abstract function appliesToEnvironment(); + /** * Return true if this variant applies to the passed class & subclass */ @@ -61,7 +67,10 @@ abstract class SearchVariant { $concrete = array(); foreach ($classes as $variantclass) { $ref = new ReflectionClass($variantclass); - if ($ref->isInstantiable()) $concrete[$variantclass] = singleton($variantclass); + if ($ref->isInstantiable()) { + $variant = singleton($variantclass); + if ($variant->appliesToEnvironment()) $concrete[$variantclass] = $variant; + } } self::$variants = $concrete; diff --git a/code/search/SearchVariantSiteTreeSubsitesPolyhome.php b/code/search/SearchVariantSiteTreeSubsitesPolyhome.php index be03d79..1171221 100644 --- a/code/search/SearchVariantSiteTreeSubsitesPolyhome.php +++ b/code/search/SearchVariantSiteTreeSubsitesPolyhome.php @@ -2,6 +2,10 @@ class SearchVariantSiteTreeSubsitesPolyhome extends SearchVariant { + function appliesToEnvironment() { + return class_exists('Subsite') && class_exists('SubsitePolyhome'); + } + function appliesTo($class, $includeSubclasses) { return SearchIntrospection::has_extension($class, 'SiteTreeSubsitesPolyhome', $includeSubclasses); } diff --git a/code/search/SearchVariantVersioned.php b/code/search/SearchVariantVersioned.php index 81a1af3..d197f33 100644 --- a/code/search/SearchVariantVersioned.php +++ b/code/search/SearchVariantVersioned.php @@ -2,6 +2,10 @@ class SearchVariantVersioned extends SearchVariant { + function appliesToEnvironment() { + return class_exists('Versioned'); + } + function appliesTo($class, $includeSubclasses) { return SearchIntrospection::has_extension($class, 'Versioned', $includeSubclasses); }