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
|
|
|
} |