Completed
Push — non_purge_indexer ( c5ca78...13d609 )
by André
12:02
created

Indexer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A updateSearchIndex() 0 18 4
A purge() 0 5 1
A checkSearchEngine() 0 12 2
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) {}
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
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