1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aoe\FeatureFlag\Domain\Repository; |
4
|
|
|
|
5
|
|
|
/*************************************************************** |
6
|
|
|
* Copyright notice |
7
|
|
|
* |
8
|
|
|
* (c) 2021 AOE GmbH <[email protected]> |
9
|
|
|
* |
10
|
|
|
* All rights reserved |
11
|
|
|
* |
12
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
13
|
|
|
* free software; you can redistribute it and/or modify |
14
|
|
|
* it under the terms of the GNU General Public License as published by |
15
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
16
|
|
|
* (at your option) any later version. |
17
|
|
|
* |
18
|
|
|
* The GNU General Public License can be found at |
19
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
20
|
|
|
* |
21
|
|
|
* This script is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
27
|
|
|
***************************************************************/ |
28
|
|
|
|
29
|
|
|
use Aoe\FeatureFlag\Domain\Model\Mapping; |
30
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
31
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings; |
32
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface; |
33
|
|
|
use TYPO3\CMS\Extbase\Persistence\Repository; |
34
|
|
|
|
35
|
|
|
class MappingRepository extends Repository |
36
|
|
|
{ |
37
|
3 |
|
public function initializeObject() |
38
|
|
|
{ |
39
|
|
|
/** @var \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings $defaultQuerySettings */ |
40
|
3 |
|
$defaultQuerySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class); |
41
|
3 |
|
$defaultQuerySettings->setRespectStoragePage(false); |
42
|
3 |
|
$defaultQuerySettings->setRespectSysLanguage(false); |
43
|
3 |
|
$defaultQuerySettings->setIgnoreEnableFields(false) |
44
|
3 |
|
->setIncludeDeleted(false); |
45
|
3 |
|
$this->setDefaultQuerySettings($defaultQuerySettings); |
46
|
3 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param int $foreignTableUid |
50
|
|
|
* @param string $foreignTableName |
51
|
|
|
* @return Mapping |
52
|
|
|
*/ |
53
|
1 |
|
public function findOneByForeignTableNameAndUid($foreignTableUid, $foreignTableName) |
54
|
|
|
{ |
55
|
1 |
|
return $this->findAllByForeignTableNameAndUid($foreignTableUid, $foreignTableName) |
56
|
1 |
|
->getFirst(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param int $foreignTableUid |
61
|
|
|
* @param string $foreignTableName |
62
|
|
|
* @return QueryResultInterface |
63
|
|
|
*/ |
64
|
2 |
|
public function findAllByForeignTableNameAndUid($foreignTableUid, $foreignTableName) |
65
|
|
|
{ |
66
|
2 |
|
$query = $this->createQuery(); |
67
|
2 |
|
$query->matching( |
68
|
2 |
|
$query->logicalAnd( |
69
|
2 |
|
$query->equals('foreign_table_uid', $foreignTableUid), |
70
|
2 |
|
$query->equals('foreign_table_name', $foreignTableName) |
|
|
|
|
71
|
|
|
) |
72
|
|
|
); |
73
|
2 |
|
return $query->execute(); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param $featureFlagId |
78
|
|
|
* @return array|QueryResultInterface |
79
|
|
|
*/ |
80
|
|
|
public function findAllByFeatureFlag($featureFlagId) |
81
|
|
|
{ |
82
|
|
|
$query = $this->createQuery(); |
83
|
|
|
$query->getQuerySettings() |
84
|
|
|
->setRespectSysLanguage(false); |
85
|
|
|
$query->getQuerySettings() |
86
|
|
|
->setRespectStoragePage(false); |
87
|
|
|
$query->matching($query->equals('feature_flag', $featureFlagId)); |
88
|
|
|
return $query->execute(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
1 |
|
public function getHashedMappings() |
95
|
|
|
{ |
96
|
1 |
|
$mappings = $this->createQuery() |
97
|
1 |
|
->execute(true); |
98
|
1 |
|
$prepared = []; |
99
|
1 |
|
foreach ($mappings as $mapping) { |
100
|
1 |
|
$identifier = sha1($mapping['foreign_table_uid'] . '_' . $mapping['foreign_table_name']); |
101
|
1 |
|
$prepared[$identifier] = $identifier; |
102
|
|
|
} |
103
|
1 |
|
return $prepared; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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.