FIX: Broken merge as files have been moved + Fixed additional tests

This commit is contained in:
Brett Tasker 2017-05-01 20:18:59 +12:00
parent c29e8ec6bf
commit 4c44d1c29e
4 changed files with 23 additions and 93 deletions

View File

@ -1,15 +0,0 @@
<?php
class SearchUpdater_BindManipulationCaptureFilter implements RequestFilter
{
public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model)
{
SearchUpdater::bind_manipulation_capture();
}
public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model)
{
/* NOP */
}
}

View File

@ -1,71 +0,0 @@
<?php
/**
* Delete operations do not use database manipulations.
*
* If a delete has been requested, force a write on objects that should be
* indexed. This causes the object to be marked for deletion from the index.
*/
class SearchUpdater_ObjectHandler extends DataExtension
{
public function onAfterDelete()
{
// Calling delete() on empty objects does nothing
if (!$this->owner->ID) {
return;
}
// Force SearchUpdater to mark this record as dirty
// Note: Some extensions require entire hierarchy passed to augmentWrite()
$manipulation = array();
foreach (ClassInfo::ancestry($this->owner) as $class) {
if (!is_subclass_of($class, 'DataObject')) {
continue;
}
$manipulation[$class] = array(
'fields' => array(),
'id' => $this->owner->ID,
// Note: 'delete' command not actually handled by manipulations,
// but added so that SearchUpdater can detect the deletion
'command' => 'delete'
);
}
$this->owner->extend('augmentWrite', $manipulation);
SearchUpdater::handle_manipulation($manipulation);
}
/**
* Forces this object to trigger a re-index in the current state
*/
public function triggerReindex()
{
if (!$this->owner->ID) {
return;
}
$id = $this->owner->ID;
$class = $this->owner->ClassName;
$state = SearchVariant::current_state($class);
$base = ClassInfo::baseDataClass($class);
$key = "$id:$base:" . serialize($state);
$statefulids = array(
array(
'id' => $id,
'state' => $state
)
);
$writes = array(
$key => array(
'base' => $base,
'class' => $class,
'id' => $id,
'statefulids' => $statefulids,
'fields' => array()
)
);
SearchUpdater::process_writes($writes);
}
}

View File

@ -4,7 +4,9 @@ namespace SilverStripe\FullTextSearch\Search\Updaters;
use SilverStripe\ORM\DataExtension;
use SilverStripe\FullTextSearch\Search\Variants\SearchVariant;
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
use SilverStripe\ORM\DataObject;
use SilverStripe\Core\ClassInfo;
/**
* Delete operations do not use database manipulations.
@ -23,14 +25,26 @@ class SearchUpdater_ObjectHandler extends DataExtension
}
// Force SearchUpdater to mark this record as dirty
$manipulation = array(
$this->owner->ClassName => array(
// Note: Some extensions require entire hierarchy passed to augmentWrite()
$manipulation = array();
foreach (ClassInfo::ancestry($this->owner) as $class) {
if (!is_subclass_of($class, DataObject::class)) {
continue;
}
$tableName = DataObject::getSchema()->tableName($class);
$manipulation[$tableName] = array(
'fields' => array(),
'id' => $this->owner->ID,
'command' => 'update'
)
);
'class' => $class,
// Note: 'delete' command not actually handled by manipulations,
// but added so that SearchUpdater can detect the deletion
'command' => 'delete'
);
}
$this->owner->extend('augmentWrite', $manipulation);
SearchUpdater::handle_manipulation($manipulation);
}

View File

@ -2,8 +2,10 @@
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Core\Config\Config;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\FullTextSearch\Search\FullTextSearch;
use SilverStripe\FullTextSearch\Search\Indexes\SearchIndex_Recording;
use SilverStripe\FullTextSearch\Search\Variants\SearchVariantVersioned;
use SilverStripe\FullTextSearch\Tests\SearchVariantVersionedTest\SearchVariantVersionedTest_Index;
use SilverStripe\FullTextSearch\Tests\SearchVariantVersionedTest\SearchVariantVersionedTest_Item;
use SilverStripe\FullTextSearch\Tests\SearchVariantVersionedTest\SearchVariantVersionedTest_IndexNoStage;
@ -90,7 +92,7 @@ class SearchVariantVersionedTest extends SapphireTest
$this->assertCount(1, self::$index->deleted);
$this->assertEquals(
'SiteTree',
SiteTree::class,
self::$index->deleted[0]['base']
);
$this->assertEquals(
@ -99,7 +101,7 @@ class SearchVariantVersionedTest extends SapphireTest
);
$this->assertEquals(
'Live',
self::$index->deleted[0]['state']['SearchVariantVersioned']
self::$index->deleted[0]['state'][SearchVariantVersioned::class]
);
}