Completed
Pull Request — master (#1125)
by
unknown
05:37
created

Listener::persistScheduled()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
ccs 14
cts 14
cp 1
rs 9.2
cc 4
eloc 10
nc 8
nop 0
crap 4
1
<?php
2
3
namespace FOS\ElasticaBundle\Doctrine;
4
5
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
6
7
/**
8
 * Automatically update ElasticSearch based on changes to the Doctrine source
9
 * data. One listener is generated for each Doctrine entity / ElasticSearch type.
10
 */
11
class Listener extends AbstractListenerBase
12
{
13
    /**
14
     * Looks for new objects that should be indexed.
15
     *
16
     * @param LifecycleEventArgs $eventArgs
17
     */
18 2
    public function postPersist(LifecycleEventArgs $eventArgs)
19
    {
20 2
        $this->doPostPersist($eventArgs->getObject());
21 2
    }
22
23
    /**
24
     * Looks for objects being updated that should be indexed or removed from the index.
25
     *
26
     * @param LifecycleEventArgs $eventArgs
27
     */
28 2
    public function postUpdate(LifecycleEventArgs $eventArgs)
29
    {
30 2
        $this->doPostUpdate($eventArgs->getObject());
31 2
    }
32
33
    /**
34
     * Delete objects preRemove instead of postRemove so that we have access to the id.  Because this is called
35
     * preRemove, first check that the entity is managed by Doctrine.
36
     *
37
     * @param LifecycleEventArgs $eventArgs
38
     */
39 2
    public function preRemove(LifecycleEventArgs $eventArgs)
40
    {
41 2
        $this->doPreRemove($eventArgs->getObject());
42 2
    }
43
44
    /**
45
     * Iterate through scheduled actions before flushing to emulate 2.x behavior.
46
     * Note that the ElasticSearch index will fall out of sync with the source
47
     * data in the event of a crash during flush.
48
     *
49
     * This method is only called in legacy configurations of the listener.
50
     *
51
     * @deprecated This method should only be called in applications that depend
52
     *             on the behaviour that entities are indexed regardless of if a
53
     *             flush is successful.
54
     */
55
    public function preFlush()
56
    {
57
        $this->doPostFlush();
58
    }
59
60
    /**
61
     * Iterating through scheduled actions *after* flushing ensures that the
62
     * ElasticSearch index will be affected only if the query is successful.
63
     */
64 6
    public function postFlush()
65
    {
66 6
        $this->doPostFlush();
67 6
    }
68
}
69