From 4c44d1c29e6b50da420b6fe592fdc18838babfeb Mon Sep 17 00:00:00 2001 From: Brett Tasker Date: Mon, 1 May 2017 20:18:59 +1200 Subject: [PATCH] FIX: Broken merge as files have been moved + Fixed additional tests --- ...hUpdater_BindManipulationCaptureFilter.php | 15 ---- code/search/SearchUpdater_ObjectHandler.php | 71 ------------------- .../updaters/SearchUpdater_ObjectHandler.php | 24 +++++-- tests/SearchVariantVersionedTest.php | 6 +- 4 files changed, 23 insertions(+), 93 deletions(-) delete mode 100644 code/search/SearchUpdater_BindManipulationCaptureFilter.php delete mode 100644 code/search/SearchUpdater_ObjectHandler.php diff --git a/code/search/SearchUpdater_BindManipulationCaptureFilter.php b/code/search/SearchUpdater_BindManipulationCaptureFilter.php deleted file mode 100644 index 24cef93..0000000 --- a/code/search/SearchUpdater_BindManipulationCaptureFilter.php +++ /dev/null @@ -1,15 +0,0 @@ -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); - } -} diff --git a/code/search/updaters/SearchUpdater_ObjectHandler.php b/code/search/updaters/SearchUpdater_ObjectHandler.php index f469584..c75b8df 100644 --- a/code/search/updaters/SearchUpdater_ObjectHandler.php +++ b/code/search/updaters/SearchUpdater_ObjectHandler.php @@ -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); } diff --git a/tests/SearchVariantVersionedTest.php b/tests/SearchVariantVersionedTest.php index bd6a97e..f0a7695 100644 --- a/tests/SearchVariantVersionedTest.php +++ b/tests/SearchVariantVersionedTest.php @@ -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] ); }