BUG Dont try and load SearchVariants that dont apply to this env

This commit is contained in:
Hamish Friedlander 2012-07-19 12:52:37 +12:00
parent 9534eeff8a
commit b9c6ff44ec
3 changed files with 18 additions and 1 deletions

View File

@ -15,6 +15,12 @@ abstract class SearchVariant {
* with specific ones * 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 * Return true if this variant applies to the passed class & subclass
*/ */
@ -61,7 +67,10 @@ abstract class SearchVariant {
$concrete = array(); $concrete = array();
foreach ($classes as $variantclass) { foreach ($classes as $variantclass) {
$ref = new ReflectionClass($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; self::$variants = $concrete;

View File

@ -2,6 +2,10 @@
class SearchVariantSiteTreeSubsitesPolyhome extends SearchVariant { class SearchVariantSiteTreeSubsitesPolyhome extends SearchVariant {
function appliesToEnvironment() {
return class_exists('Subsite') && class_exists('SubsitePolyhome');
}
function appliesTo($class, $includeSubclasses) { function appliesTo($class, $includeSubclasses) {
return SearchIntrospection::has_extension($class, 'SiteTreeSubsitesPolyhome', $includeSubclasses); return SearchIntrospection::has_extension($class, 'SiteTreeSubsitesPolyhome', $includeSubclasses);
} }

View File

@ -2,6 +2,10 @@
class SearchVariantVersioned extends SearchVariant { class SearchVariantVersioned extends SearchVariant {
function appliesToEnvironment() {
return class_exists('Versioned');
}
function appliesTo($class, $includeSubclasses) { function appliesTo($class, $includeSubclasses) {
return SearchIntrospection::has_extension($class, 'Versioned', $includeSubclasses); return SearchIntrospection::has_extension($class, 'Versioned', $includeSubclasses);
} }