[!!!][TASK] Drop extbase query cache
[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\Utility\GeneralUtility;
18
19 /**
20 * Query settings. This class is NOT part of the TYPO3.Flow API.
21 * It reflects the settings unique to TYPO3 CMS.
22 *
23 * @api
24 */
25 class Typo3QuerySettings implements QuerySettingsInterface
26 {
27 /**
28 * Flag if the storage page should be respected for the query.
29 *
30 * @var bool
31 */
32 protected $respectStoragePage = true;
33
34 /**
35 * the pid(s) of the storage page(s) that should be respected for the query.
36 *
37 * @var array
38 */
39 protected $storagePageIds = array();
40
41 /**
42 * A flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
43 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
44 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
45 *
46 * @var bool
47 */
48 protected $ignoreEnableFields = false;
49
50 /**
51 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
52 * to be ignored while building the query statement
53 *
54 * @var array
55 */
56 protected $enableFieldsToBeIgnored = array();
57
58 /**
59 * Flag whether deleted records should be included in the result set.
60 *
61 * @var bool
62 */
63 protected $includeDeleted = false;
64
65 /**
66 * Flag if the sys_language_uid should be respected (default is TRUE).
67 *
68 * @var bool
69 */
70 protected $respectSysLanguage = true;
71
72 /**
73 * Representing sys_language_overlay only valid for current context
74 *
75 * @var mixed
76 */
77 protected $languageOverlayMode = true;
78
79 /**
80 * Representing sys_language_mode only valid for current context
81 *
82 * @var string
83 */
84 protected $languageMode = null;
85
86 /**
87 * Represensting sys_language_uid only valid for current context
88 *
89 * @var int
90 */
91 protected $languageUid = 0;
92
93 /**
94 * Flag whether the query should use a prepared statement
95 *
96 * @var bool
97 * @deprecated since TYPO3 v8, will be removed in TYPO3 9, this option is handled automatically now in the database abstraction
98 */
99 protected $usePreparedStatement = false;
100
101 /**
102 * Flag whether the query should be cached using the caching framework
103 *
104 * @var bool
105 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, as the database is taking care of query caching
106 */
107 protected $useQueryCache = true;
108
109 /**
110 * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
111 * initializeObject is responsible for handling that.
112 */
113 public function initializeObject()
114 {
115 /** @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManager */
116 $objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
117 /** @var $configurationManager \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface */
118 $configurationManager = $objectManager->get(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class);
119 if (TYPO3_MODE === 'BE' && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
120 $this->setIgnoreEnableFields(true);
121 }
122
123 // TYPO3 CMS language defaults
124 $this->setLanguageUid(0);
125 $this->setLanguageMode(null);
126 $this->setLanguageOverlayMode(false);
127
128 // Set correct language uid for frontend handling
129 if (isset($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE'])) {
130 $this->setLanguageUid((int)$GLOBALS['TSFE']->sys_language_content);
131 $this->setLanguageOverlayMode($GLOBALS['TSFE']->sys_language_contentOL ?: false);
132 $this->setLanguageMode($GLOBALS['TSFE']->sys_language_mode ?: null);
133 } elseif ((int)GeneralUtility::_GP('L')) {
134 // Set language from 'L' parameter
135 $this->setLanguageUid((int)GeneralUtility::_GP('L'));
136 }
137 }
138
139 /**
140 * Sets the flag if the storage page should be respected for the query.
141 *
142 * @param bool $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
143 * @return QuerySettingsInterface
144 * @api
145 */
146 public function setRespectStoragePage($respectStoragePage)
147 {
148 $this->respectStoragePage = $respectStoragePage;
149 return $this;
150 }
151
152 /**
153 * Returns the state, if the storage page should be respected for the query.
154 *
155 * @return bool TRUE, if the storage page should be respected; otherwise FALSE.
156 */
157 public function getRespectStoragePage()
158 {
159 return $this->respectStoragePage;
160 }
161
162 /**
163 * Sets the pid(s) of the storage page(s) that should be respected for the query.
164 *
165 * @param array $storagePageIds If given the storage page IDs will be determined and the statement will be extended accordingly.
166 * @return QuerySettingsInterface
167 * @api
168 */
169 public function setStoragePageIds(array $storagePageIds)
170 {
171 $this->storagePageIds = $storagePageIds;
172 return $this;
173 }
174
175 /**
176 * Returns the pid(s) of the storage page(s) that should be respected for the query.
177 *
178 * @return array list of integers that each represent a storage page id
179 */
180 public function getStoragePageIds()
181 {
182 return $this->storagePageIds;
183 }
184
185 /**
186 * @param bool $respectSysLanguage TRUE if TYPO3 language settings are to be applied
187 * @return QuerySettingsInterface
188 * @api
189 */
190 public function setRespectSysLanguage($respectSysLanguage)
191 {
192 $this->respectSysLanguage = $respectSysLanguage;
193 return $this;
194 }
195
196 /**
197 * @return bool TRUE if TYPO3 language settings are to be applied
198 */
199 public function getRespectSysLanguage()
200 {
201 return $this->respectSysLanguage;
202 }
203
204 /**
205 * @param mixed $languageOverlayMode TRUE, FALSE or "hideNonTranslated"
206 * @return QuerySettingsInterface instance of $this to allow method chaining
207 * @api
208 */
209 public function setLanguageOverlayMode($languageOverlayMode = false)
210 {
211 $this->languageOverlayMode = $languageOverlayMode;
212 return $this;
213 }
214
215 /**
216 * @return mixed TRUE, FALSE or "hideNonTranslated"
217 */
218 public function getLanguageOverlayMode()
219 {
220 return $this->languageOverlayMode;
221 }
222
223 /**
224 * @param string $languageMode NULL, "content_fallback", "strict" or "ignore"
225 * @return QuerySettingsInterface instance of $this to allow method chaining
226 * @api
227 */
228 public function setLanguageMode($languageMode = '')
229 {
230 $this->languageMode = $languageMode;
231 return $this;
232 }
233
234 /**
235 * @return string NULL, "content_fallback", "strict" or "ignore"
236 */
237 public function getLanguageMode()
238 {
239 return $this->languageMode;
240 }
241
242 /**
243 * @param int $languageUid
244 * @return QuerySettingsInterface instance of $this to allow method chaining
245 * @api
246 */
247 public function setLanguageUid($languageUid)
248 {
249 $this->languageUid = $languageUid;
250 return $this;
251 }
252
253 /**
254 * @return int
255 */
256 public function getLanguageUid()
257 {
258 return $this->languageUid;
259 }
260
261 /**
262 * Sets a flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
263 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
264 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
265 *
266 * @param bool $ignoreEnableFields
267 * @return QuerySettingsInterface
268 * @see setEnableFieldsToBeIgnored()
269 * @api
270 */
271 public function setIgnoreEnableFields($ignoreEnableFields)
272 {
273 $this->ignoreEnableFields = $ignoreEnableFields;
274 return $this;
275 }
276
277 /**
278 * The returned value indicates whether all or some enable fields should be ignored.
279 *
280 * If TRUE, all enable fields are ignored. If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored.
281 * If FALSE, all enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
282 *
283 * @return bool
284 * @see getEnableFieldsToBeIgnored()
285 */
286 public function getIgnoreEnableFields()
287 {
288 return $this->ignoreEnableFields;
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. Adding a column name here effectively switches off filtering
294 * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
295 *
296 * @param array $enableFieldsToBeIgnored
297 * @return QuerySettingsInterface
298 * @see setIgnoreEnableFields()
299 * @api
300 */
301 public function setEnableFieldsToBeIgnored($enableFieldsToBeIgnored)
302 {
303 $this->enableFieldsToBeIgnored = $enableFieldsToBeIgnored;
304 return $this;
305 }
306
307 /**
308 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
309 * to be ignored while building the query statement.
310 *
311 * @return array
312 * @see getIgnoreEnableFields()
313 */
314 public function getEnableFieldsToBeIgnored()
315 {
316 return $this->enableFieldsToBeIgnored;
317 }
318
319 /**
320 * Sets the flag if the query should return objects that are deleted.
321 *
322 * @param bool $includeDeleted
323 * @return QuerySettingsInterface
324 * @api
325 */
326 public function setIncludeDeleted($includeDeleted)
327 {
328 $this->includeDeleted = $includeDeleted;
329 return $this;
330 }
331
332 /**
333 * Returns if the query should return objects that are deleted.
334 *
335 * @return bool
336 */
337 public function getIncludeDeleted()
338 {
339 return $this->includeDeleted;
340 }
341
342 /**
343 * @param bool $usePreparedStatement
344 * @return QuerySettingsInterface
345 * @deprecated since TYPO3 v8, will be removed in TYPO3 9, this option is handled automatically now in the database abstraction
346 */
347 public function usePreparedStatement($usePreparedStatement)
348 {
349 GeneralUtility::logDeprecatedFunction();
350 $this->usePreparedStatement = $usePreparedStatement;
351 return $this;
352 }
353
354 /**
355 * @return bool
356 * @deprecated since TYPO3 v8, will be removed in TYPO3 9, this option is handled automatically now in the database abstraction
357 */
358 public function getUsePreparedStatement()
359 {
360 GeneralUtility::logDeprecatedFunction();
361 return (bool)$this->usePreparedStatement;
362 }
363
364 /**
365 * @param bool $useQueryCache
366 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, as the database is taking care of query caching
367 * @return QuerySettingsInterface
368 */
369 public function useQueryCache($useQueryCache)
370 {
371 GeneralUtility::logDeprecatedFunction();
372 $this->useQueryCache = (bool)$useQueryCache;
373 return $this;
374 }
375
376 /**
377 * @return bool
378 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, as the database is taking care of query caching
379 */
380 public function getUseQueryCache()
381 {
382 GeneralUtility::logDeprecatedFunction();
383 return $this->useQueryCache;
384 }
385 }