Completed
Push — EZP-25088-search-handler-inter... ( f8bc81 )
by
unknown
26:40
created

CopySubtree::receive()   C

Complexity

Conditions 7
Paths 9

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 7
eloc 16
c 2
b 0
f 0
nc 9
nop 1
dl 0
loc 30
rs 6.7272
1
<?php
2
3
/**
4
 * This file is part of the eZ Publish Kernel package.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 *
9
 * @version //autogentag//
10
 */
11
namespace eZ\Publish\Core\Search\Common\Slot;
12
13
use eZ\Publish\Core\SignalSlot\Signal;
14
use eZ\Publish\Core\Search\Common\Slot;
15
use eZ\Publish\SPI\Search\Indexer;
16
use eZ\Publish\SPI\Search\Indexer\ContentIndexer;
17
use eZ\Publish\SPI\Search\Indexer\LocationIndexer;
18
19
/**
20
 * A Search Engine slot handling CopySubtreeSignal.
21
 */
22
class CopySubtree extends Slot
23
{
24
    /**
25
     * Receive the given $signal and react on it.
26
     *
27
     * @param \eZ\Publish\Core\SignalSlot\Signal $signal
28
     */
29
    public function receive(Signal $signal)
30
    {
31
        if (!$signal instanceof Signal\LocationService\CopySubtreeSignal) {
32
            return;
33
        }
34
35
        if (!$this->searchHandler instanceof Indexer) {
36
            return;
37
        }
38
39
        $contentHandler = $this->persistenceHandler->contentHandler();
40
        $subtreeIds = $this->persistenceHandler->locationHandler()->loadSubtreeIds($signal->targetNewSubtreeId);
41
42
        foreach ($subtreeIds as $contentId) {
43
            $contentInfo = $contentHandler->loadContentInfo($contentId);
44
45
            if ($this->searchHandler instanceof ContentIndexer) {
46
                $this->searchHandler->indexContent(
47
                    $contentHandler->load($contentInfo->id, $contentInfo->currentVersionNo)
48
                );
49
            }
50
51
            if ($this->searchHandler instanceof LocationIndexer) {
52
                $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentInfo->id);
53
                foreach ($locations as $location) {
54
                    $this->searchHandler->indexLocation($location);
55
                }
56
            }
57
        }
58
    }
59
}
60