[TASK] Add default TypoScript setting for 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 * Copyright notice
6 *
7 * (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
8 * Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
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 2 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 * A copy is found in the text file GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32 /**
33 * Query settings. This class is NOT part of the FLOW3 API.
34 * It reflects the settings unique to TYPO3 CMS.
35 *
36 * @api
37 */
38 class Typo3QuerySettings implements QuerySettingsInterface {
39
40 /**
41 * Flag if the storage page should be respected for the query.
42 *
43 * @var bool
44 */
45 protected $respectStoragePage = TRUE;
46
47 /**
48 * the pid(s) of the storage page(s) that should be respected for the query.
49 *
50 * @var array
51 */
52 protected $storagePageIds = array();
53
54 /**
55 * A flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
56 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
57 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
58 *
59 * @var bool
60 */
61 protected $ignoreEnableFields = FALSE;
62
63 /**
64 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
65 * to be ignored while building the query statement
66 *
67 * @var array
68 */
69 protected $enableFieldsToBeIgnored = array();
70
71 /**
72 * Flag whether deleted records should be included in the result set.
73 *
74 * @var bool
75 */
76 protected $includeDeleted = FALSE;
77
78 /**
79 * Flag if the sys_language_uid should be respected (default is TRUE).
80 *
81 * @var bool
82 */
83 protected $respectSysLanguage = TRUE;
84
85 /**
86 * Representing sys_language_overlay only valid for current context
87 *
88 * @var mixed
89 */
90 protected $languageOverlayMode = TRUE;
91
92 /**
93 * Representing sys_language_mode only valid for current context
94 *
95 * @var string
96 */
97 protected $languageMode = NULL;
98
99 /**
100 * Represensting sys_language_uid only valid for current context
101 *
102 * @var int
103 */
104 protected $languageUid = 0;
105
106 /**
107 * Flag if the the query result should be returned as raw QueryResult.
108 *
109 * @var bool
110 * @deprecated since Extbase 6.2, will be removed two versions later
111 */
112 protected $returnRawQueryResult = FALSE;
113
114 /**
115 * Flag whether the query should use a prepared statement
116 *
117 * @var bool
118 */
119 protected $usePreparedStatement = FALSE;
120
121 /**
122 * Flag whether the query should be cached using the caching framework
123 *
124 * @var bool
125 */
126 protected $useQueryCache = TRUE;
127
128 /**
129 * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
130 * initializeObject is responsible for handling that.
131 */
132 public function initializeObject() {
133 /** @var $objectManager \TYPO3\CMS\Extbase\Object\ObjectManager */
134 $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
135 /** @var $configurationManager \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface */
136 $configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
137 if (TYPO3_MODE === 'BE' && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
138 $this->setIgnoreEnableFields(TRUE);
139 }
140
141 // TYPO3 CMS language defaults
142 $this->setLanguageUid(0);
143 $this->setLanguageMode(NULL);
144 $this->setLanguageOverlayMode(FALSE);
145
146 // Set correct language uid for frontend handling
147 if (isset($GLOBALS['TSFE']) && is_object($GLOBALS['TSFE'])) {
148 $this->setLanguageUid((int)$GLOBALS['TSFE']->sys_language_content);
149 $this->setLanguageOverlayMode($GLOBALS['TSFE']->sys_language_contentOL ?: FALSE);
150 $this->setLanguageMode($GLOBALS['TSFE']->sys_language_mode ?: NULL);
151 } elseif ((int)GeneralUtility::_GP('L')) {
152 // Set language from 'L' parameter
153 $this->setLanguageUid((int)GeneralUtility::_GP('L'));
154 }
155 }
156
157 /**
158 * Sets the flag if the storage page should be respected for the query.
159 *
160 * @param bool $respectStoragePage If TRUE the storage page ID will be determined and the statement will be extended accordingly.
161 * @return QuerySettingsInterface
162 * @api
163 */
164 public function setRespectStoragePage($respectStoragePage) {
165 $this->respectStoragePage = $respectStoragePage;
166 return $this;
167 }
168
169 /**
170 * Returns the state, if the storage page should be respected for the query.
171 *
172 * @return bool TRUE, if the storage page should be respected; otherwise FALSE.
173 */
174 public function getRespectStoragePage() {
175 return $this->respectStoragePage;
176 }
177
178 /**
179 * Sets the pid(s) of the storage page(s) that should be respected for the query.
180 *
181 * @param array $storagePageIds If given the storage page IDs will be determined and the statement will be extended accordingly.
182 * @return QuerySettingsInterface
183 * @api
184 */
185 public function setStoragePageIds(array $storagePageIds) {
186 $this->storagePageIds = $storagePageIds;
187 return $this;
188 }
189
190 /**
191 * Returns the pid(s) of the storage page(s) that should be respected for the query.
192 *
193 * @return array list of integers that each represent a storage page id
194 */
195 public function getStoragePageIds() {
196 return $this->storagePageIds;
197 }
198
199 /**
200 * @param bool $respectSysLanguage TRUE if TYPO3 language settings are to be applied
201 * @return QuerySettingsInterface
202 * @api
203 */
204 public function setRespectSysLanguage($respectSysLanguage) {
205 $this->respectSysLanguage = $respectSysLanguage;
206 return $this;
207 }
208
209 /**
210 * @return bool TRUE if TYPO3 language settings are to be applied
211 */
212 public function getRespectSysLanguage() {
213 return $this->respectSysLanguage;
214 }
215
216 /**
217 * @param mixed $languageOverlayMode TRUE, FALSE or "hideNonTranslated"
218 * @return QuerySettingsInterface instance of $this to allow method chaining
219 * @api
220 */
221 public function setLanguageOverlayMode($languageOverlayMode = FALSE) {
222 $this->languageOverlayMode = $languageOverlayMode;
223 return $this;
224 }
225
226 /**
227 * @return mixed TRUE, FALSE or "hideNonTranslated"
228 */
229 public function getLanguageOverlayMode() {
230 return $this->languageOverlayMode;
231 }
232
233 /**
234 * @param string $languageMode NULL, "content_fallback", "strict" or "ignore"
235 * @return QuerySettingsInterface instance of $this to allow method chaining
236 * @api
237 */
238 public function setLanguageMode($languageMode = '') {
239 $this->languageMode = $languageMode;
240 return $this;
241 }
242
243 /**
244 * @return string NULL, "content_fallback", "strict" or "ignore"
245 */
246 public function getLanguageMode() {
247 return $this->languageMode;
248 }
249
250 /**
251 * @param int $languageUid
252 * @return QuerySettingsInterface instance of $this to allow method chaining
253 * @api
254 */
255 public function setLanguageUid($languageUid) {
256 $this->languageUid = $languageUid;
257 return $this;
258 }
259
260 /**
261 * @return int
262 */
263 public function getLanguageUid() {
264 return $this->languageUid;
265 }
266
267 /**
268 * Sets the language uid for the language overlay.
269 *
270 * @param int $sysLanguageUid language uid for the language overlay
271 * @return QuerySettingsInterface instance of $this to allow method chaining
272 * @deprecated since Extbase 6.2, will be removed two versions later. Use setLanguageUid() instead.
273 */
274 public function setSysLanguageUid($sysLanguageUid) {
275 GeneralUtility::logDeprecatedFunction();
276 return $this->setLanguageUid($sysLanguageUid);
277 }
278
279 /**
280 * Returns the language uid for the language overlay
281 *
282 * @return int language uid for the language overlay
283 * @deprecated since Extbase 6.2, will be removed two versions later. Use getLanguageUid() instead.
284 */
285 public function getSysLanguageUid() {
286 GeneralUtility::logDeprecatedFunction();
287 return $this->getLanguageUid();
288 }
289
290 /**
291 * Sets a flag indicating whether all or some enable fields should be ignored. If TRUE, all enable fields are ignored.
292 * If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored. If FALSE, all
293 * enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
294 *
295 * @param bool $ignoreEnableFields
296 * @return QuerySettingsInterface
297 * @see setEnableFieldsToBeIgnored()
298 * @api
299 */
300 public function setIgnoreEnableFields($ignoreEnableFields) {
301 $this->ignoreEnableFields = $ignoreEnableFields;
302 return $this;
303 }
304
305 /**
306 * The returned value indicates whether all or some enable fields should be ignored.
307 *
308 * If TRUE, all enable fields are ignored. If--in addition to this--enableFieldsToBeIgnored is set, only fields specified there are ignored.
309 * If FALSE, all enable fields are taken into account, regardless of the enableFieldsToBeIgnored setting.
310 *
311 * @return bool
312 * @see getEnableFieldsToBeIgnored()
313 */
314 public function getIgnoreEnableFields() {
315 return $this->ignoreEnableFields;
316 }
317
318 /**
319 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
320 * to be ignored while building the query statement. Adding a column name here effectively switches off filtering
321 * by this column. This setting is only taken into account if $this->ignoreEnableFields = TRUE.
322 *
323 * @param array $enableFieldsToBeIgnored
324 * @return QuerySettingsInterface
325 * @see setIgnoreEnableFields()
326 * @api
327 */
328 public function setEnableFieldsToBeIgnored($enableFieldsToBeIgnored) {
329 $this->enableFieldsToBeIgnored = $enableFieldsToBeIgnored;
330 return $this;
331 }
332
333 /**
334 * An array of column names in the enable columns array (array keys in $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']),
335 * to be ignored while building the query statement.
336 *
337 * @return array
338 * @see getIgnoreEnableFields()
339 */
340 public function getEnableFieldsToBeIgnored() {
341 return $this->enableFieldsToBeIgnored;
342 }
343
344 /**
345 * Sets the flag if the query should return objects that are deleted.
346 *
347 * @param bool $includeDeleted
348 * @return QuerySettingsInterface
349 * @api
350 */
351 public function setIncludeDeleted($includeDeleted) {
352 $this->includeDeleted = $includeDeleted;
353 return $this;
354 }
355
356 /**
357 * Returns if the query should return objects that are deleted.
358 *
359 * @return bool
360 */
361 public function getIncludeDeleted() {
362 return $this->includeDeleted;
363 }
364
365 /**
366 * Sets the state, if the QueryResult should be returned unmapped.
367 *
368 * @param bool $returnRawQueryResult TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
369 * @return QuerySettingsInterface
370 * @deprecated since Extbase 6.2, will be removed two versions later. Please use argument in query->execute() instead.
371 */
372 public function setReturnRawQueryResult($returnRawQueryResult) {
373 GeneralUtility::logDeprecatedFunction();
374 $this->returnRawQueryResult = $returnRawQueryResult;
375 return $this;
376 }
377
378 /**
379 * Returns the state, if the QueryResult should be returned unmapped.
380 *
381 * @return bool TRUE, if the QueryResult should be returned unmapped; otherwise FALSE.
382 * @deprecated since Extbase 6.2, will be removed two versions later. Please use argument in query->execute() instead.
383 */
384 public function getReturnRawQueryResult() {
385 // We do not log this call intentionally, otherwise the deprecation log would be filled up
386 return $this->returnRawQueryResult;
387 }
388
389 /**
390 * @param bool $usePreparedStatement
391 * @return QuerySettingsInterface
392 */
393 public function usePreparedStatement($usePreparedStatement) {
394 $this->usePreparedStatement = $usePreparedStatement;
395 return $this;
396 }
397
398 /**
399 * @return bool
400 */
401 public function getUsePreparedStatement() {
402 return (bool)$this->usePreparedStatement;
403 }
404
405 /**
406 * @param bool $useQueryCache
407 * @return QuerySettingsInterface
408 */
409 public function useQueryCache($useQueryCache) {
410 $this->useQueryCache = (bool)$useQueryCache;
411 return $this;
412 }
413
414 /**
415 * @return bool
416 */
417 public function getUseQueryCache() {
418 return $this->useQueryCache;
419 }
420 }