Completed
Push — ezp-30646 ( 6400c7...ee4911 )
by
unknown
21:35
created

AbstractSearchEventSubscriber::indexSubtree()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 30
rs 9.44
c 0
b 0
f 0
1
<?php
2
3
namespace eZ\Publish\Core\Search\Common\EventSubscriber;
4
5
use eZ\Publish\SPI\Search\Handler as SearchHandler;
6
use eZ\Publish\SPI\Persistence\Handler as PersistenceHandler;
7
8
abstract class AbstractSearchEventSubscriber
9
{
10
    /**
11
     * @var \eZ\Publish\SPI\Search\Handler
12
     */
13
    protected $searchHandler;
14
15
    /**
16
     * @var \eZ\Publish\SPI\Persistence\Handler
17
     */
18
    protected $persistenceHandler;
19
20
    public function __construct(
21
        SearchHandler $searchHandler,
22
        PersistenceHandler $persistenceHandler
23
    ) {
24
        $this->searchHandler = $searchHandler;
25
        $this->persistenceHandler = $persistenceHandler;
26
    }
27
28
    public function indexSubtree(int $locationId): void
29
    {
30
        $contentHandler = $this->persistenceHandler->contentHandler();
31
        $locationHandler = $this->persistenceHandler->locationHandler();
32
33
        $processedContentIdSet = [];
34
        $subtreeIds = $locationHandler->loadSubtreeIds($locationId);
35
        $contentInfoList = $contentHandler->loadContentInfoList(array_values($subtreeIds));
36
37
        foreach ($subtreeIds as $locationId => $contentId) {
38
            $this->searchHandler->indexLocation(
39
                $locationHandler->load($locationId)
40
            );
41
42
            if (isset($processedContentIdSet[$contentId])) {
43
                continue;
44
            }
45
46
            $this->searchHandler->indexContent(
47
                $contentHandler->load(
48
                    $contentId,
49
                    $contentInfoList[$contentId]->currentVersionNo
50
                )
51
            );
52
53
            // Content could be found in multiple Locations of the subtree,
54
            // but we need to (re)index it only once
55
            $processedContentIdSet[$contentId] = true;
56
        }
57
    }
58
}