Completed
Push — ezp-30646 ( a44352...64df2d )
by
unknown
15:12
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
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\Search\Common\EventSubscriber;
8
9
use eZ\Publish\SPI\Persistence\Handler as PersistenceHandler;
10
use eZ\Publish\SPI\Search\Handler as SearchHandler;
11
12
/**
13
 * @internal
14
 */
15
abstract class AbstractSearchEventSubscriber
16
{
17
    /** @var \eZ\Publish\SPI\Search\Handler */
18
    protected $searchHandler;
19
20
    /** @var \eZ\Publish\SPI\Persistence\Handler */
21
    protected $persistenceHandler;
22
23
    public function __construct(
24
        SearchHandler $searchHandler,
25
        PersistenceHandler $persistenceHandler
26
    ) {
27
        $this->searchHandler = $searchHandler;
28
        $this->persistenceHandler = $persistenceHandler;
29
    }
30
31
    public function indexSubtree(int $locationId): void
32
    {
33
        $contentHandler = $this->persistenceHandler->contentHandler();
34
        $locationHandler = $this->persistenceHandler->locationHandler();
35
36
        $processedContentIdSet = [];
37
        $subtreeIds = $locationHandler->loadSubtreeIds($locationId);
38
        $contentInfoList = $contentHandler->loadContentInfoList(array_values($subtreeIds));
39
40
        foreach ($subtreeIds as $locationId => $contentId) {
41
            $this->searchHandler->indexLocation(
42
                $locationHandler->load($locationId)
43
            );
44
45
            if (isset($processedContentIdSet[$contentId])) {
46
                continue;
47
            }
48
49
            $this->searchHandler->indexContent(
50
                $contentHandler->load(
51
                    $contentId,
52
                    $contentInfoList[$contentId]->currentVersionNo
53
                )
54
            );
55
56
            // Content could be found in multiple Locations of the subtree,
57
            // but we need to (re)index it only once
58
            $processedContentIdSet[$contentId] = true;
59
        }
60
    }
61
}
62