1
|
|
|
<?php |
2
|
|
|
namespace Codappix\SearchCore\DataProcessing; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* Copyright (C) 2018 Daniel Siepmann <[email protected]> |
6
|
|
|
* |
7
|
|
|
* This program is free software; you can redistribute it and/or |
8
|
|
|
* modify it under the terms of the GNU General Public License |
9
|
|
|
* as published by the Free Software Foundation; either version 2 |
10
|
|
|
* of the License, or (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with this program; if not, write to the Free Software |
19
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
20
|
|
|
* 02110-1301, USA. |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
use Codappix\SearchCore\Domain\Index\TcaIndexer\RelationResolver; |
24
|
|
|
use Codappix\SearchCore\Domain\Index\TcaIndexer\TcaTableServiceInterface; |
25
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
26
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Resolves relations from TCA using RelationResolver. |
30
|
|
|
*/ |
31
|
|
|
class TcaRelationResolvingProcessor implements ProcessorInterface |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var ObjectManagerInterface |
35
|
|
|
*/ |
36
|
|
|
protected $objectManager; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var RelationResolver |
40
|
|
|
*/ |
41
|
|
|
protected $relationResolver; |
42
|
|
|
|
43
|
32 |
|
public function __construct( |
44
|
|
|
ObjectManagerInterface $objectManager, |
45
|
|
|
RelationResolver $relationResolver |
46
|
|
|
) { |
47
|
32 |
|
$this->objectManager = $objectManager; |
48
|
32 |
|
$this->relationResolver = $relationResolver; |
49
|
32 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @throws \InvalidArgumentException If _table is not configured. |
53
|
|
|
*/ |
54
|
32 |
|
public function processData(array $record, array $configuration) : array |
55
|
|
|
{ |
56
|
32 |
|
$this->initializeConfiguration($configuration); |
57
|
|
|
|
58
|
32 |
|
$tcaTableService = $this->objectManager->get( |
59
|
32 |
|
TcaTableServiceInterface::class, |
60
|
32 |
|
$configuration['_table'] |
|
|
|
|
61
|
|
|
); |
62
|
|
|
|
63
|
32 |
|
$processedRecord = $this->relationResolver->resolveRelationsForRecord( |
64
|
32 |
|
$tcaTableService, |
65
|
32 |
|
$this->getRecordToProcess($record, $configuration) |
66
|
|
|
); |
67
|
|
|
|
68
|
32 |
|
return array_merge($record, $processedRecord); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @throws \InvalidArgumentException If _table is not configured. |
73
|
|
|
*/ |
74
|
32 |
|
protected function initializeConfiguration(array &$configuration) |
75
|
|
|
{ |
76
|
32 |
|
if (!isset($configuration['_table'])) { |
77
|
|
|
throw new \InvalidArgumentException('The configuration "_table" is mandantory.', 1524552631); |
78
|
|
|
} |
79
|
|
|
|
80
|
32 |
|
if (!isset($configuration['excludeFields'])) { |
81
|
32 |
|
$configuration['excludeFields'] = ''; |
82
|
|
|
} |
83
|
|
|
|
84
|
32 |
|
$configuration['excludeFields'] = GeneralUtility::trimExplode(',', $configuration['excludeFields'], true); |
85
|
32 |
|
} |
86
|
|
|
|
87
|
32 |
|
protected function getRecordToProcess(array $record, array $configuration) : array |
88
|
|
|
{ |
89
|
32 |
|
if ($configuration['excludeFields'] === []) { |
90
|
32 |
|
return $record; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$newRecord = []; |
94
|
|
|
$keysToUse = array_diff(array_keys($record), $configuration['excludeFields']); |
95
|
|
|
foreach ($keysToUse as $keyToUse) { |
96
|
|
|
$newRecord[$keyToUse] = $record[$keyToUse]; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return $newRecord; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.