1
|
|
|
<?php |
2
|
|
|
namespace Aoe\FeatureFlag\System\Db; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2021 AOE GmbH <[email protected]> |
8
|
|
|
* |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
|
28
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
29
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
30
|
|
|
use TYPO3\CMS\Core\Database\Query\QueryBuilder; |
31
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
32
|
|
|
|
33
|
|
|
class FeatureFlagData |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
const TABLE_MAPPING = 'tx_featureflag_domain_model_mapping'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
const TABLE_FLAGS = 'tx_featureflag_domain_model_featureflag'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $table |
47
|
|
|
* @param integer $behavior |
48
|
|
|
* @param integer $enabled |
49
|
|
|
* |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
public function getContentElements($table, $behavior, $enabled) |
53
|
|
|
{ |
54
|
|
|
/** @var QueryBuilder $queryBuilder */ |
55
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
56
|
|
|
->getQueryBuilderForTable($table); |
57
|
|
|
|
58
|
|
|
$queryBuilder->getRestrictions()->removeAll(); |
59
|
|
|
|
60
|
|
|
$queryBuilder |
61
|
|
|
->select($table . '.uid') |
62
|
|
|
->from($table) |
63
|
|
|
->from(self::TABLE_MAPPING) |
64
|
|
|
->from(self::TABLE_FLAGS) |
65
|
|
|
->where( |
66
|
|
|
$queryBuilder->expr()->andX( |
67
|
|
|
$queryBuilder->expr()->eq( |
68
|
|
|
self::TABLE_MAPPING . '.feature_flag', |
69
|
|
|
self::TABLE_FLAGS . '.uid' |
70
|
|
|
), |
71
|
|
|
$queryBuilder->expr()->eq( |
72
|
|
|
$table . '.uid', |
73
|
|
|
self::TABLE_MAPPING . '.foreign_table_uid' |
74
|
|
|
), |
75
|
|
|
$queryBuilder->expr()->eq( |
76
|
|
|
self::TABLE_FLAGS . '.enabled', |
77
|
|
|
$queryBuilder->createNamedParameter($enabled, Connection::PARAM_INT) |
78
|
|
|
), |
79
|
|
|
$queryBuilder->expr()->eq( |
80
|
|
|
self::TABLE_MAPPING . '.foreign_table_name', |
81
|
|
|
$queryBuilder->createNamedParameter($table, Connection::PARAM_STR) |
82
|
|
|
), |
83
|
|
|
$queryBuilder->expr()->eq( |
84
|
|
|
self::TABLE_MAPPING . '.behavior', |
85
|
|
|
$queryBuilder->createNamedParameter($behavior, Connection::PARAM_INT) |
86
|
|
|
) |
87
|
|
|
) |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
return $queryBuilder->execute()->fetchAllAssociative(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $table |
95
|
|
|
* @param array $uids |
96
|
|
|
* @param bool $isVisible |
97
|
|
|
*/ |
98
|
|
|
public function updateContentElements($table, array $uids, $isVisible) |
99
|
|
|
{ |
100
|
|
|
/** @var QueryBuilder $queryBuilder */ |
101
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
102
|
|
|
->getQueryBuilderForTable($table); |
103
|
|
|
|
104
|
|
|
$queryBuilder->getRestrictions()->removeAll(); |
105
|
|
|
|
106
|
|
|
$query = $queryBuilder |
107
|
|
|
->update($table) |
108
|
|
|
->set('hidden', $isVisible === true ? 0 : 1) |
109
|
|
|
->add('where', $queryBuilder->expr()->in('uid', $uids)); |
110
|
|
|
|
111
|
|
|
$query->execute(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param string $table |
116
|
|
|
* @param integer $uid |
117
|
|
|
* |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
public function getContentElementsPIDs($table, $uid) |
121
|
|
|
{ |
122
|
|
|
/** @var QueryBuilder $queryBuilder */ |
123
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
124
|
|
|
->getQueryBuilderForTable($table); |
125
|
|
|
|
126
|
|
|
$queryBuilder->getRestrictions()->removeAll(); |
127
|
|
|
|
128
|
|
|
$query = $queryBuilder |
129
|
|
|
->select($table . '.pid') |
130
|
|
|
->from($table) |
131
|
|
|
->where( |
132
|
|
|
$queryBuilder->expr()->eq( |
133
|
|
|
$table . '.uid', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT) |
134
|
|
|
) |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
return $query->execute()->fetchColumn(0); |
|
|
|
|
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.