mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 14:05:29 +02:00
FIX: Broken merge as files have been moved + Fixed additional tests
This commit is contained in:
parent
c29e8ec6bf
commit
4c44d1c29e
@ -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 */
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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]
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user