Code Duplication    Length = 32-37 lines in 2 locations

eZ/Publish/Core/Search/Common/Slot/CopyContent.php 1 location

@@ 21-57 (lines=37) @@
18
/**
19
 * A Search Engine slot handling CopyContentSignal.
20
 */
21
class CopyContent extends Slot
22
{
23
    /**
24
     * Receive the given $signal and react on it.
25
     *
26
     * @param \eZ\Publish\Core\SignalSlot\Signal $signal
27
     */
28
    public function receive(Signal $signal)
29
    {
30
        if (!$signal instanceof Signal\ContentService\CopyContentSignal || !$this->canIndex()) {
31
            return;
32
        }
33
34
        if ($this->canIndexContent()) {
35
            $this->searchHandler->indexContent(
36
                $this->persistenceHandler->contentHandler()->load(
37
                    $signal->dstContentId,
38
                    $signal->dstVersionNo
39
                )
40
            );
41
        }
42
43
        if ($this->canIndexLocation()) {
44
            $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent(
45
                $signal->dstContentId
46
            );
47
            foreach ($locations as $location) {
48
                $this->searchHandler->indexLocation($location);
49
            }
50
        }
51
    }
52
53
    protected function canIndexContent()
54
    {
55
        return $this->searchHandler instanceof ContentIndexing || $this->searchHandler instanceof FullTextIndexing;
56
    }
57
}
58

eZ/Publish/Core/Search/Common/Slot/PublishVersion.php 1 location

@@ 21-52 (lines=32) @@
18
/**
19
 * A Search Engine slot handling PublishVersionSignal.
20
 */
21
class PublishVersion extends Slot
22
{
23
    /**
24
     * Receive the given $signal and react on it.
25
     *
26
     * @param \eZ\Publish\Core\SignalSlot\Signal $signal
27
     */
28
    public function receive(Signal $signal)
29
    {
30
        if (!$signal instanceof Signal\ContentService\PublishVersionSignal || !$this->canIndex()) {
31
            return;
32
        }
33
34
        if ($this->canIndexContent()) {
35
            $this->searchHandler->indexContent(
36
                $this->persistenceHandler->contentHandler()->load($signal->contentId, $signal->versionNo)
37
            );
38
        }
39
40
        if ($this->canIndexLocation()) {
41
            $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($signal->contentId);
42
            foreach ($locations as $location) {
43
                $this->searchHandler->indexLocation($location);
44
            }
45
        }
46
    }
47
48
    protected function canIndexContent()
49
    {
50
        return $this->searchHandler instanceof ContentIndexing || $this->searchHandler instanceof FullTextIndexing;
51
    }
52
}
53