[BUGFIX] Start nighly test run at 3am rather than 0:03am
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Generic / Typo3QuerySettings.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Persistence\Generic;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Context\Context;
18 use TYPO3\CMS\Core\Context\LanguageAspect;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
21 use TYPO3\CMS\Extbase\Object\ObjectManager;
22 use TYPO3\CMS\Extbase\Service\EnvironmentService;
23
24 /**
25 * Query settings, reflects the settings unique to TYPO3 CMS.
26 */
27 class Typo3QuerySettings implements QuerySettingsInterface
28 {
29 /**
30 * Flag if the storage page should be respected for the query.
31 *
32 * @var bool
33 */
34 protected $respectStoragePage = true;
35
36 /**
37 * the pid(s) of the storage page(s) that should be respected for the query.
38 *
39 * @var array
40 */
41 protected $storagePageIds = [];
42
43 /**
44 * A flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
45 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
46 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
47 *
48 * @var bool
49 */
50 protected $ignoreEnableFields = false;
51
52 /**
53 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
54 * to be ignored while building the query statement
55 *
56 * @var array
57 */
58 protected $enableFieldsToBeIgnored = [];
59
60 /**
61 * Flag whether deleted records should be included in the result set.
62 *
63 * @var bool
64 */
65 protected $includeDeleted = false;
66
67 /**
68 * Flag if the sys_language_uid should be respected (default is TRUE).
69 *
70 * @var bool
71 */
72 protected $respectSysLanguage = true;
73
74 /**
75 * Representing sys_language_overlay only valid for current context
76 *
77 * @var mixed
78 */
79 protected $languageOverlayMode = true;
80
81 /**
82 * Representing sys_language_uid only valid for current context
83 *
84 * @var int
85 */
86 protected $languageUid = 0;
87
88 /**
89 * @var EnvironmentService
90 */
91 protected $environmentService;
92
93 /**
94 * @param EnvironmentService $environmentService
95 */
96 public function injectEnvironmentService(EnvironmentService $environmentService)
97 {
98 $this->environmentService = $environmentService;
99 }
100
101 /**
102 * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
103 * initializeObject is responsible for handling that.
104 */
105 public function initializeObject()
106 {
107 /** @var ObjectManager $objectManager */
108 $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
109 /** @var ConfigurationManagerInterface $configurationManager */
110 $configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
111 if ($this->environmentService->isEnvironmentInBackendMode() && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
112 $this->setIgnoreEnableFields(true);
113 }
114 /** @var LanguageAspect $languageAspect */
115 $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
116 $this->setLanguageUid($languageAspect->getContentId());
117 $this->setLanguageOverlayMode(false);
118
119 if ($this->environmentService->isEnvironmentInFrontendMode()) {
120 $overlayMode = $languageAspect->getLegacyOverlayType() === 'hideNonTranslated' ? 'hideNonTranslated' : (bool)$languageAspect->getLegacyOverlayType();
121 $this->setLanguageOverlayMode($overlayMode);
122 } elseif ((int)GeneralUtility::_GP('L')) {
123 // Set language from 'L' parameter
124 $this->setLanguageUid((int)GeneralUtility::_GP('L'));
125 }
126 }
127
128 /**
129 * Sets the flag if the storage page should be respected for the query.
130 *
131 * @param bool $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
132 * @return QuerySettingsInterface
133 */
134 public function setRespectStoragePage($respectStoragePage)
135 {
136 $this->respectStoragePage = $respectStoragePage;
137 return $this;
138 }
139
140 /**
141 * Returns the state, if the storage page should be respected for the query.
142 *
143 * @return bool TRUE, if the storage page should be respected; otherwise FALSE.
144 */
145 public function getRespectStoragePage()
146 {
147 return $this->respectStoragePage;
148 }
149
150 /**
151 * Sets the pid(s) of the storage page(s) that should be respected for the query.
152 *
153 * @param array $storagePageIds If given the storage page IDs will be determined and the statement will be extended accordingly.
154 * @return QuerySettingsInterface
155 */
156 public function setStoragePageIds(array $storagePageIds)
157 {
158 $this->storagePageIds = $storagePageIds;
159 return $this;
160 }
161
162 /**
163 * Returns the pid(s) of the storage page(s) that should be respected for the query.
164 *
165 * @return array list of integers that each represent a storage page id
166 */
167 public function getStoragePageIds()
168 {
169 return $this->storagePageIds;
170 }
171
172 /**
173 * @param bool $respectSysLanguage TRUE if TYPO3 language settings are to be applied
174 * @return QuerySettingsInterface
175 */
176 public function setRespectSysLanguage($respectSysLanguage)
177 {
178 $this->respectSysLanguage = $respectSysLanguage;
179 return $this;
180 }
181
182 /**
183 * @return bool TRUE if TYPO3 language settings are to be applied
184 */
185 public function getRespectSysLanguage()
186 {
187 return $this->respectSysLanguage;
188 }
189
190 /**
191 * @param mixed $languageOverlayMode TRUE, FALSE or "hideNonTranslated"
192 * @return QuerySettingsInterface instance of $this to allow method chaining
193 */
194 public function setLanguageOverlayMode($languageOverlayMode = false)
195 {
196 $this->languageOverlayMode = $languageOverlayMode;
197 return $this;
198 }
199
200 /**
201 * @return mixed TRUE, FALSE or "hideNonTranslated"
202 */
203 public function getLanguageOverlayMode()
204 {
205 return $this->languageOverlayMode;
206 }
207
208 /**
209 * Language Mode is NOT used anymore, so just avoid using it. Will be deprecated in the future.
210 *
211 * @param string $languageMode
212 * @return QuerySettingsInterface instance of $this to allow method chaining
213 */
214 public function setLanguageMode($languageMode = '')
215 {
216 return $this;
217 }
218
219 /**
220 * Language Mode is NOT used anymore, so just avoid using it. Will be deprecated in the future.
221 *
222 * @return string NULL, "content_fallback", "strict" or "ignore"
223 */
224 public function getLanguageMode()
225 {
226 return null;
227 }
228
229 /**
230 * @param int $languageUid
231 * @return QuerySettingsInterface instance of $this to allow method chaining
232 */
233 public function setLanguageUid($languageUid)
234 {
235 $this->languageUid = $languageUid;
236 return $this;
237 }
238
239 /**
240 * @return int
241 */
242 public function getLanguageUid()
243 {
244 return $this->languageUid;
245 }
246
247 /**
248 * Sets a flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
249 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
250 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
251 *
252 * @param bool $ignoreEnableFields
253 * @return QuerySettingsInterface
254 * @see setEnableFieldsToBeIgnored()
255 */
256 public function setIgnoreEnableFields($ignoreEnableFields)
257 {
258 $this->ignoreEnableFields = $ignoreEnableFields;
259 return $this;
260 }
261
262 /**
263 * The returned value indicates whether all or some enable fields should be ignored.
264 *
265 * If TRUE, all enable fields are ignored. If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored.
266 * If FALSE, all enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
267 *
268 * @return bool
269 * @see getEnableFieldsToBeIgnored()
270 */
271 public function getIgnoreEnableFields()
272 {
273 return $this->ignoreEnableFields;
274 }
275
276 /**
277 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
278 * to be ignored while building the query statement. Adding a column name here effectively switches off filtering
279 * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
280 *
281 * @param array $enableFieldsToBeIgnored
282 * @return QuerySettingsInterface
283 * @see setIgnoreEnableFields()
284 */
285 public function setEnableFieldsToBeIgnored($enableFieldsToBeIgnored)
286 {
287 $this->enableFieldsToBeIgnored = $enableFieldsToBeIgnored;
288 return $this;
289 }
290
291 /**
292 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
293 * to be ignored while building the query statement.
294 *
295 * @return array
296 * @see getIgnoreEnableFields()
297 */
298 public function getEnableFieldsToBeIgnored()
299 {
300 return $this->enableFieldsToBeIgnored;
301 }
302
303 /**
304 * Sets the flag if the query should return objects that are deleted.
305 *
306 * @param bool $includeDeleted
307 * @return QuerySettingsInterface
308 */
309 public function setIncludeDeleted($includeDeleted)
310 {
311 $this->includeDeleted = $includeDeleted;
312 return $this;
313 }
314
315 /**
316 * Returns if the query should return objects that are deleted.
317 *
318 * @return bool
319 */
320 public function getIncludeDeleted()
321 {
322 return $this->includeDeleted;
323 }
324 }