2011-05-02 06:33:05 +02:00
|
|
|
<?php
|
2017-04-21 02:27:01 +02:00
|
|
|
namespace SilverStripe\FullTextSearch\Search;
|
2015-11-21 07:19:20 +01:00
|
|
|
class SearchVariantVersioned extends SearchVariant
|
|
|
|
{
|
|
|
|
public function appliesToEnvironment()
|
|
|
|
{
|
|
|
|
return class_exists('Versioned');
|
|
|
|
}
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
public function appliesTo($class, $includeSubclasses)
|
|
|
|
{
|
|
|
|
return SearchIntrospection::has_extension($class, 'Versioned', $includeSubclasses);
|
|
|
|
}
|
2012-07-19 02:52:37 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
public function currentState()
|
|
|
|
{
|
|
|
|
return Versioned::current_stage();
|
|
|
|
}
|
|
|
|
public function reindexStates()
|
|
|
|
{
|
|
|
|
return array('Stage', 'Live');
|
|
|
|
}
|
|
|
|
public function activateState($state)
|
|
|
|
{
|
|
|
|
Versioned::reading_stage($state);
|
|
|
|
}
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2016-04-15 07:59:10 +02:00
|
|
|
public function alterDefinition($class, $index)
|
2015-11-21 07:19:20 +01:00
|
|
|
{
|
|
|
|
$self = get_class($this);
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2016-04-15 07:59:10 +02:00
|
|
|
$this->addFilterField($index, '_versionedstage', array(
|
2015-11-21 07:19:20 +01:00
|
|
|
'name' => '_versionedstage',
|
|
|
|
'field' => '_versionedstage',
|
|
|
|
'fullfield' => '_versionedstage',
|
2016-04-15 07:59:10 +02:00
|
|
|
'base' => ClassInfo::baseDataClass($class),
|
|
|
|
'origin' => $class,
|
2015-11-21 07:19:20 +01:00
|
|
|
'type' => 'String',
|
|
|
|
'lookup_chain' => array(array('call' => 'variant', 'variant' => $self, 'method' => 'currentState'))
|
2016-04-15 07:59:10 +02:00
|
|
|
));
|
2015-11-21 07:19:20 +01:00
|
|
|
}
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
public function alterQuery($query, $index)
|
|
|
|
{
|
|
|
|
$stage = Versioned::current_stage();
|
|
|
|
$query->filter('_versionedstage', array($stage, SearchQuery::$missing));
|
|
|
|
}
|
2016-04-15 07:59:10 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
public function extractManipulationState(&$manipulation)
|
|
|
|
{
|
|
|
|
$self = get_class($this);
|
2016-04-15 07:59:10 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
foreach ($manipulation as $table => $details) {
|
|
|
|
$class = $details['class'];
|
|
|
|
$stage = 'Stage';
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
if (preg_match('/^(.*)_Live$/', $table, $matches)) {
|
|
|
|
$class = $matches[1];
|
|
|
|
$stage = 'Live';
|
|
|
|
}
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
if (ClassInfo::exists($class) && $this->appliesTo($class, false)) {
|
|
|
|
$manipulation[$table]['class'] = $class;
|
|
|
|
$manipulation[$table]['state'][$self] = $stage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
public function extractStates(&$table, &$ids, &$fields)
|
|
|
|
{
|
|
|
|
$class = $table;
|
|
|
|
$suffix = null;
|
2011-05-02 06:33:05 +02:00
|
|
|
|
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
if (ClassInfo::exists($class) && $this->appliesTo($class, false)) {
|
|
|
|
$table = $class;
|
|
|
|
$self = get_class($this);
|
2011-05-02 06:33:05 +02:00
|
|
|
|
2015-11-21 07:19:20 +01:00
|
|
|
foreach ($ids as $i => $statefulid) {
|
|
|
|
$ids[$i]['state'][$self] = $suffix ? $suffix : 'Stage';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-02 06:33:05 +02:00
|
|
|
}
|