2013-02-12 22:16:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class SearchVariantSubsites extends SearchVariant {
|
|
|
|
|
|
|
|
function appliesToEnvironment() {
|
|
|
|
return class_exists('Subsite');
|
|
|
|
}
|
|
|
|
|
|
|
|
function appliesTo($class, $includeSubclasses) {
|
|
|
|
// Include all DataExtensions that contain a SubsiteID.
|
|
|
|
// TODO: refactor subsites to inherit a common interface, so we can run introspection once only.
|
|
|
|
return SearchIntrospection::has_extension($class, 'SiteTreeSubsites', $includeSubclasses) ||
|
|
|
|
SearchIntrospection::has_extension($class, 'GroupSubsites', $includeSubclasses) ||
|
|
|
|
SearchIntrospection::has_extension($class, 'FileSubsites', $includeSubclasses) ||
|
|
|
|
SearchIntrospection::has_extension($class, 'SiteConfigSubsites', $includeSubclasses);
|
|
|
|
}
|
|
|
|
|
|
|
|
function currentState() {
|
2014-05-22 06:31:19 +02:00
|
|
|
return (string)Subsite::currentSubsiteID();
|
2013-02-12 22:16:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function reindexStates() {
|
|
|
|
static $ids = null;
|
|
|
|
|
|
|
|
if ($ids === null) {
|
2014-05-22 06:31:19 +02:00
|
|
|
$ids = array('0');
|
|
|
|
foreach (DataObject::get('Subsite') as $subsite) $ids[] = (string)$subsite->ID;
|
2013-02-12 22:16:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $ids;
|
|
|
|
}
|
|
|
|
|
|
|
|
function activateState($state) {
|
2013-09-17 04:33:39 +02:00
|
|
|
// We always just set the $_GET variable rather than store in Session - this always works, has highest priority
|
|
|
|
// in Subsite::currentSubsiteID() and doesn't persist unlike Subsite::changeSubsite
|
|
|
|
$_GET['SubsiteID'] = $state;
|
|
|
|
Permission::flush_permission_cache();
|
2013-02-12 22:16:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function alterDefinition($base, $index) {
|
|
|
|
$self = get_class($this);
|
|
|
|
|
|
|
|
$index->filterFields['_subsite'] = array(
|
|
|
|
'name' => '_subsite',
|
|
|
|
'field' => '_subsite',
|
|
|
|
'fullfield' => '_subsite',
|
|
|
|
'base' => $base,
|
|
|
|
'origin' => $base,
|
|
|
|
'type' => 'Int',
|
|
|
|
'lookup_chain' => array(array('call' => 'variant', 'variant' => $self, 'method' => 'currentState'))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function alterQuery($query, $index) {
|
|
|
|
$subsite = Subsite::currentSubsiteID();
|
|
|
|
$query->filter('_subsite', array($subsite, SearchQuery::$missing));
|
|
|
|
}
|
|
|
|
|
|
|
|
static $subsites = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We need _really_ complicated logic to find just the changed subsites (because we use versions there's no explicit
|
|
|
|
* deletes, just new versions with different members) so just always use all of them
|
|
|
|
*/
|
|
|
|
function extractManipulationWriteState(&$writes) {
|
|
|
|
$self = get_class($this);
|
|
|
|
|
|
|
|
foreach ($writes as $key => $write) {
|
|
|
|
if (!$this->appliesTo($write['class'], true)) continue;
|
|
|
|
|
|
|
|
if (self::$subsites === null) {
|
2014-08-19 00:29:01 +02:00
|
|
|
$query = new SQLQuery('"ID"', '"Subsite"');
|
2013-02-12 22:16:39 +01:00
|
|
|
self::$subsites = array_merge(array('0'), $query->execute()->column());
|
|
|
|
}
|
|
|
|
|
|
|
|
$next = array();
|
|
|
|
|
|
|
|
foreach ($write['statefulids'] as $i => $statefulid) {
|
|
|
|
foreach (self::$subsites as $subsiteID) {
|
2014-05-22 06:31:19 +02:00
|
|
|
$next[] = array('id' => $statefulid['id'], 'state' => array_merge($statefulid['state'], array($self => (string)$subsiteID)));
|
2013-02-12 22:16:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$writes[$key]['statefulids'] = $next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|