Completed
Push — 6.7 ( 730fb7...a124d5 )
by André
39:46 queued 26:19
created

Indexer::createSearchIndex()   C

Complexity

Conditions 8
Paths 9

Size

Total Lines 50
Code Lines 32

Duplication

Lines 27
Ratio 54 %

Importance

Changes 0
Metric Value
cc 8
eloc 32
nc 9
nop 3
dl 27
loc 50
rs 6.3636
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Indexer::updateSearchIndex() 0 18 4
A Indexer::purge() 0 4 1
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\Persistence\Database\DatabaseHandler;
13
use eZ\Publish\Core\Search\Common\IncrementalIndexer;
14
use eZ\Publish\Core\Search\Legacy\Content\Handler as LegacySearchHandler;
15
use eZ\Publish\SPI\Persistence\Handler as PersistenceHandler;
16
use Psr\Log\LoggerInterface;
17
18
class Indexer extends IncrementalIndexer
19
{
20
    public function __construct(
21
        LoggerInterface $logger,
22
        PersistenceHandler $persistenceHandler,
23
        DatabaseHandler $databaseHandler,
24
        LegacySearchHandler $searchHandler
25
    ) {
26
        parent::__construct($logger, $persistenceHandler, $databaseHandler, $searchHandler);
27
    }
28
29
    public function getName()
30
    {
31
        return 'eZ Platform Legacy (SQL) Search Engine';
32
    }
33
34
    public function updateSearchIndex(array $contentIds, $commit)
35
    {
36
        $contentHandler = $this->persistenceHandler->contentHandler();
37
        foreach ($contentIds as $contentId) {
38
            try {
39
                $info = $contentHandler->loadContentInfo($contentId);
40
                if ($info->isPublished) {
41
                    $this->searchHandler->indexContent(
42
                        $contentHandler->load($info->id, $info->currentVersionNo)
43
                    );
44
                } else {
45
                    $this->searchHandler->deleteContent($contentId);
46
                }
47
            } catch (NotFoundException $e) {
48
                $this->searchHandler->deleteContent($contentId);
49
            }
50
        }
51
    }
52
53
    public function purge()
54
    {
55
        $this->searchHandler->purgeIndex();
56
    }
57
}
58