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
|
|
|
*/ |
43
|
54 |
|
public function __construct( |
44
|
|
|
TcaTableServiceInterface $tcaTableService, |
45
|
|
|
ConnectionInterface $connection, |
46
|
|
|
ConfigurationContainerInterface $configuration |
47
|
|
|
) { |
48
|
54 |
|
parent::__construct($connection, $configuration); |
49
|
54 |
|
$this->tcaTableService = $tcaTableService; |
50
|
54 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return array|null Nullable when no items are found and execution should be stopped |
54
|
|
|
*/ |
55
|
26 |
|
protected function getRecords(int $offset, int $limit) |
56
|
|
|
{ |
57
|
26 |
|
$records = $this->tcaTableService->getRecords($offset, $limit); |
58
|
26 |
|
if ($records === []) { |
59
|
26 |
|
return null; |
60
|
|
|
} |
61
|
|
|
|
62
|
26 |
|
$this->tcaTableService->filterRecordsByRootLineBlacklist($records); |
63
|
26 |
|
foreach ($records as &$record) { |
64
|
26 |
|
$this->tcaTableService->prepareRecord($record); |
65
|
|
|
} |
66
|
|
|
|
67
|
26 |
|
return $records; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @throws NoRecordFoundException If record could not be found. |
72
|
|
|
*/ |
73
|
4 |
|
protected function getRecord(int $identifier): array |
74
|
|
|
{ |
75
|
4 |
|
$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
|
30 |
|
protected function getDocumentName(): string |
88
|
|
|
{ |
89
|
30 |
|
return $this->tcaTableService->getTableName(); |
90
|
|
|
} |
91
|
|
|
|
92
|
28 |
|
protected function getDocumentIdentifier($identifier): string |
93
|
|
|
{ |
94
|
28 |
|
return $this->getDocumentName() . '-' . $identifier; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|