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
|
|
|
namespace eZ\Publish\Core\Search\Legacy\Content; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Exceptions\NotFoundException; |
12
|
|
|
use eZ\Publish\Core\Search\Common\IncrementalIndexer; |
13
|
|
|
use eZ\Publish\Core\Search\Legacy\Content\Handler as LegacySearchHandler; |
14
|
|
|
use RuntimeException; |
15
|
|
|
|
16
|
|
|
class Indexer extends IncrementalIndexer |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
public function getName() |
20
|
|
|
{ |
21
|
|
|
return 'eZ Platform Legacy (SQL) Search Engine'; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function updateSearchIndex(array $contentIds, $commit) |
25
|
|
|
{ |
26
|
|
|
$this->checkSearchEngine(); |
27
|
|
|
$contentHandler = $this->persistenceHandler->contentHandler(); |
28
|
|
|
foreach ($contentIds as $contentId) { |
29
|
|
|
try { |
30
|
|
|
$info = $contentHandler->loadContentInfo($contentId); |
31
|
|
|
if ($info->isPublished) { |
32
|
|
|
$this->searchHandler->indexContent( |
33
|
|
|
$contentHandler->load($info->id, $info->currentVersionNo) |
34
|
|
|
); |
35
|
|
|
continue; |
36
|
|
|
} |
37
|
|
|
} catch (NotFoundException $e) {} |
|
|
|
|
38
|
|
|
|
39
|
|
|
$this->searchHandler->deleteContent($contentId); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function purge() |
44
|
|
|
{ |
45
|
|
|
$this->checkSearchEngine(); |
46
|
|
|
$this->searchHandler->purgeIndex(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
private function checkSearchEngine() |
50
|
|
|
{ |
51
|
|
|
if (!$this->searchHandler instanceof LegacySearchHandler) { |
52
|
|
|
throw new RuntimeException( |
53
|
|
|
sprintf( |
54
|
|
|
'Expected to find an instance of %s, but found %s', |
55
|
|
|
LegacySearchHandler::class, |
56
|
|
|
get_class($this->searchHandler) |
57
|
|
|
) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|