1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aoe\FeatureFlag\System\Db; |
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 TYPO3\CMS\Core\Database\Connection; |
30
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
31
|
|
|
use TYPO3\CMS\Core\Database\Query\QueryBuilder; |
32
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
33
|
|
|
|
34
|
|
|
class FeatureFlagData |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
public const TABLE_MAPPING = 'tx_featureflag_domain_model_mapping'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
public const TABLE_FLAGS = 'tx_featureflag_domain_model_featureflag'; |
45
|
|
|
|
46
|
|
|
public function getContentElements(string $table, int $behavior, int $enabled): array |
47
|
|
|
{ |
48
|
|
|
/** @var QueryBuilder $queryBuilder */ |
49
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
50
|
|
|
->getQueryBuilderForTable($table); |
51
|
|
|
|
52
|
|
|
$queryBuilder->getRestrictions() |
53
|
|
|
->removeAll(); |
54
|
|
|
|
55
|
|
|
$queryBuilder |
56
|
|
|
->select($table . '.uid') |
57
|
|
|
->from($table) |
58
|
|
|
->from(self::TABLE_MAPPING) |
59
|
|
|
->from(self::TABLE_FLAGS) |
60
|
|
|
->where( |
61
|
|
|
$queryBuilder->expr() |
62
|
|
|
->andX( |
63
|
|
|
$queryBuilder->expr() |
64
|
|
|
->eq( |
65
|
|
|
self::TABLE_MAPPING . '.feature_flag', |
66
|
|
|
self::TABLE_FLAGS . '.uid' |
67
|
|
|
), |
68
|
|
|
$queryBuilder->expr() |
69
|
|
|
->eq( |
70
|
|
|
$table . '.uid', |
71
|
|
|
self::TABLE_MAPPING . '.foreign_table_uid' |
72
|
|
|
), |
73
|
|
|
$queryBuilder->expr() |
74
|
|
|
->eq( |
75
|
|
|
self::TABLE_FLAGS . '.enabled', |
76
|
|
|
$queryBuilder->createNamedParameter($enabled, Connection::PARAM_INT) |
77
|
|
|
), |
78
|
|
|
$queryBuilder->expr() |
79
|
|
|
->eq( |
80
|
|
|
self::TABLE_MAPPING . '.foreign_table_name', |
81
|
|
|
$queryBuilder->createNamedParameter($table, Connection::PARAM_STR) |
82
|
|
|
), |
83
|
|
|
$queryBuilder->expr() |
84
|
|
|
->eq( |
85
|
|
|
self::TABLE_MAPPING . '.behavior', |
86
|
|
|
$queryBuilder->createNamedParameter($behavior, Connection::PARAM_INT) |
87
|
|
|
) |
88
|
|
|
) |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
return $queryBuilder->execute() |
92
|
|
|
->fetchAllAssociative(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function updateContentElements(string $table, array $uids, bool $isVisible): void |
96
|
|
|
{ |
97
|
|
|
/** @var QueryBuilder $queryBuilder */ |
98
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
99
|
|
|
->getQueryBuilderForTable($table); |
100
|
|
|
|
101
|
|
|
$queryBuilder->getRestrictions() |
102
|
|
|
->removeAll(); |
103
|
|
|
|
104
|
|
|
$query = $queryBuilder |
105
|
|
|
->update($table) |
106
|
|
|
->set('hidden', $isVisible ? 0 : 1) |
107
|
|
|
->add('where', $queryBuilder->expr()->in('uid', $uids)); |
108
|
|
|
|
109
|
|
|
$query->execute(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getContentElementsPIDs(string $table, int $uid): string |
113
|
|
|
{ |
114
|
|
|
/** @var QueryBuilder $queryBuilder */ |
115
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
116
|
|
|
->getQueryBuilderForTable($table); |
117
|
|
|
|
118
|
|
|
$queryBuilder->getRestrictions() |
119
|
|
|
->removeAll(); |
120
|
|
|
|
121
|
|
|
$query = $queryBuilder |
122
|
|
|
->select($table . '.pid') |
123
|
|
|
->from($table) |
124
|
|
|
->where( |
125
|
|
|
$queryBuilder->expr() |
|
|
|
|
126
|
|
|
->eq( |
127
|
|
|
$table . '.uid', |
128
|
|
|
$queryBuilder->createNamedParameter($uid, Connection::PARAM_INT) |
129
|
|
|
) |
130
|
|
|
); |
131
|
|
|
|
132
|
|
|
return $query->execute() |
|
|
|
|
133
|
|
|
->fetchOne(); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|