Completed
Pull Request — develop (#167)
by Daniel
24:51
created

TcaIndexer::getDocumentIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Codappix\SearchCore\Domain\Index;
4
5
/*
6
 * Copyright (C) 2016  Daniel Siepmann <[email protected]>
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
 * 02110-1301, USA.
22
 */
23
24
use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
25
use Codappix\SearchCore\Connection\ConnectionInterface;
26
use Codappix\SearchCore\Domain\Index\TcaIndexer\TcaTableServiceInterface;
27
28
/**
29
 * Will index the given table using configuration from TCA.
30
 */
31
class TcaIndexer extends AbstractIndexer
32
{
33
    /**
34
     * @var TcaTableServiceInterface
35
     */
36
    protected $tcaTableService;
37
38
    /**
39
     * @param TcaTableServiceInterface $tcaTableService
40
     * @param ConnectionInterface $connection
41
     * @param ConfigurationContainerInterface $configuration
42 52
     */
43
    public function __construct(
44
        TcaTableServiceInterface $tcaTableService,
45
        ConnectionInterface $connection,
46
        ConfigurationContainerInterface $configuration
47 52
    ) {
48 52
        parent::__construct($connection, $configuration);
49 52
        $this->tcaTableService = $tcaTableService;
50
    }
51
52
    /**
53
     * @return array|null Nullable when no items are found and execution should be stopped
54 24
     */
55
    protected function getRecords(int $offset, int $limit)
56 24
    {
57 24
        $records = $this->tcaTableService->getRecords($offset, $limit);
58 24
        if ($records === []) {
59
            return null;
60
        }
61 24
62 24
        $this->tcaTableService->filterRecordsByRootLineBlacklist($records);
63 24
        foreach ($records as &$record) {
64
            $this->tcaTableService->prepareRecord($record);
65
        }
66 24
67
        return $records;
68
    }
69
70
    /**
71
     * @throws NoRecordFoundException If record could not be found.
72 4
     */
73
    protected function getRecord(int $identifier): array
74 4
    {
75
        $record = $this->tcaTableService->getRecord($identifier);
76 4
        if ($record === []) {
77 2
            throw new NoRecordFoundException(
78 2
                'Record could not be fetched from database: "' . $identifier . '". Perhaps record is not active.',
79 2
                1484225364
80
            );
81
        }
82 2
        $this->tcaTableService->prepareRecord($record);
83
84 2
        return $record;
85
    }
86
87 28
    protected function getDocumentName(): string
88
    {
89 28
        return $this->tcaTableService->getTableName();
90
    }
91
92
    public function getDocumentIdentifier($identifier): string
93
    {
94
        return $this->getDocumentName() . '-' . $identifier;
95
    }
96
}
97