SearchIndex_Recording   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 68
rs 10
c 0
b 0
f 0
wmc 12

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getService() 0 4 1
A getIsCommitted() 0 3 1
A getIndexName() 0 3 1
A delete() 0 3 1
A commit() 0 3 1
A reset() 0 5 1
A add() 0 12 2
A getAdded() 0 15 4
1
<?php
2
3
namespace SilverStripe\FullTextSearch\Search\Indexes;
4
5
use SilverStripe\FullTextSearch\Search\Indexes\SearchIndex;
6
7
/**
8
 * A search index that just records actions. Useful for testing
9
 */
10
abstract class SearchIndex_Recording extends SearchIndex
11
{
12
    public $added = array();
13
    public $deleted = array();
14
    public $committed = false;
15
16
    public function reset()
17
    {
18
        $this->added = array();
19
        $this->deleted = array();
20
        $this->committed = false;
21
    }
22
23
    public function add($object)
24
    {
25
        $res = array();
26
27
        $res['ID'] = $object->ID;
28
29
        foreach ($this->getFieldsIterator() as $name => $field) {
30
            $val = $this->_getFieldValue($object, $field);
31
            $res[$name] = $val;
32
        }
33
34
        $this->added[] = $res;
35
    }
36
37
    public function getAdded($fields = array())
38
    {
39
        $res = array();
40
41
        foreach ($this->added as $added) {
42
            $filtered = array();
43
            foreach ($fields as $field) {
44
                if (isset($added[$field])) {
45
                    $filtered[$field] = $added[$field];
46
                }
47
            }
48
            $res[] = $filtered;
49
        }
50
51
        return $res;
52
    }
53
54
    public function delete($base, $id, $state)
55
    {
56
        $this->deleted[] = array('base' => $base, 'id' => $id, 'state' => $state);
57
    }
58
59
    public function commit()
60
    {
61
        $this->committed = true;
62
    }
63
64
    public function getIndexName()
65
    {
66
        return get_class($this);
67
    }
68
69
    public function getIsCommitted()
70
    {
71
        return $this->committed;
72
    }
73
74
    public function getService()
75
    {
76
        // Causes commits to the service to be redirected back to the same object
77
        return $this;
78
    }
79
}
80