findAllByForeignTableNameAndUid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 10
ccs 0
cts 7
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Aoe\FeatureFlag\Domain\Repository;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2024 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 TYPO3\CMS\Core\Utility\GeneralUtility;
30
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
31
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
32
use TYPO3\CMS\Extbase\Persistence\Repository;
33
34
class MappingRepository extends Repository
35
{
36
    public function initializeObject(): void
37
    {
38
        /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings $defaultQuerySettings */
39
        $defaultQuerySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
40
        $defaultQuerySettings->setRespectStoragePage(false);
41
        $defaultQuerySettings->setRespectSysLanguage(false);
42
        $defaultQuerySettings->setIgnoreEnableFields(false)
43
            ->setIncludeDeleted(false);
44
        $this->setDefaultQuerySettings($defaultQuerySettings);
45
    }
46
47
    public function findOneByForeignTableNameAndUid(string $foreignTableUid, string $foreignTableName): ?object
48
    {
49
        return $this->findAllByForeignTableNameAndUid($foreignTableUid, $foreignTableName)
50
            ->getFirst();
51
    }
52
53
    /**
54
     * @return QueryResultInterface
55
     */
56
    public function findAllByForeignTableNameAndUid(string $foreignTableUid, string $foreignTableName)
57
    {
58
        $query = $this->createQuery();
59
        $query->matching(
60
            $query->logicalAnd(
61
                $query->equals('foreign_table_uid', $foreignTableUid),
62
                $query->equals('foreign_table_name', $foreignTableName)
63
            )
64
        );
65
        return $query->execute();
66
    }
67
68
    /**
69
     * @return array|QueryResultInterface
70
     */
71
    public function findAllByFeatureFlag(string $featureFlagId)
72
    {
73
        $query = $this->createQuery();
74
        $query->getQuerySettings()
75
            ->setRespectSysLanguage(false);
76
        $query->getQuerySettings()
77
            ->setRespectStoragePage(false);
78
        $query->matching($query->equals('feature_flag', $featureFlagId));
79
        return $query->execute();
80
    }
81
82
    public function getHashedMappings(): array
83
    {
84
        $mappings = $this->createQuery()
85
            ->execute(true);
86
        $prepared = [];
87
        foreach ($mappings as $mapping) {
88
            $identifier = sha1($mapping['foreign_table_uid'] . '_' . $mapping['foreign_table_name']);
89
            $prepared[$identifier] = $identifier;
90
        }
91
92
        return $prepared;
93
    }
94
}
95