silverstripe-fulltextsearch/code/search/indexes/SearchIndex_Recording.php
Elliot Sawyer 1728a62af5 WIP: Silverstripe 4 compatibility
Thanks to Marco Hermo and Brett Tasker for helping with this
* Bump framework/cms to ^4.0@dev
* WIP Silverstripe 4 compatibility fixes
* more replacements and patches to migrate this module to 4.0
* Update composer.json
* remove php <5.5 from travis.yml
* WIP more SS4 compatibility fixes
* WIP fix solr path to use DIR, avoid hardcoded module name
* WIP respect current include path
* WIP Namespacing and use on SearchIndex class
* Namespacing for tests
* WIP add namespaces to all classes
* Second push of Test changes + namespacing
* WIP split Solr files with multiple classes into single file / single class. Adjust namespaces
* Fix PHP errors in test
* break out search components with multiple classes into individual files and change namespaces
* Update namespacing for Search indexes and variants in tests
* Batch fixes for tests #2
* Update _config.php to use namespace
* Use root namespace in referencing Apache_Solr_Document
* Migrate task names so that the name is not fully qualified
2017-04-25 20:46:35 +12:00

80 lines
1.7 KiB
PHP

<?php
namespace SilverStripe\FullTextSearch\Search\Indexes;
use SilverStripe\FullTextSearch\Search\Indexes\SearchIndex;
/**
* A search index that just records actions. Useful for testing
*/
abstract class SearchIndex_Recording extends SearchIndex
{
public $added = array();
public $deleted = array();
public $committed = false;
public function reset()
{
$this->added = array();
$this->deleted = array();
$this->committed = false;
}
public function add($object)
{
$res = array();
$res['ID'] = $object->ID;
foreach ($this->getFieldsIterator() as $name => $field) {
$val = $this->_getFieldValue($object, $field);
$res[$name] = $val;
}
$this->added[] = $res;
}
public function getAdded($fields = array())
{
$res = array();
foreach ($this->added as $added) {
$filtered = array();
foreach ($fields as $field) {
if (isset($added[$field])) {
$filtered[$field] = $added[$field];
}
}
$res[] = $filtered;
}
return $res;
}
public function delete($base, $id, $state)
{
$this->deleted[] = array('base' => $base, 'id' => $id, 'state' => $state);
}
public function commit()
{
$this->committed = true;
}
public function getIndexName()
{
return get_class($this);
}
public function getIsCommitted()
{
return $this->committed;
}
public function getService()
{
// Causes commits to the service to be redirected back to the same object
return $this;
}
}