Merge "[BUGFIX] ConfigurationManager use FrontendSimulator only if neccessary"
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Storage / Typo3DbBackend.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
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 *
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 /**
29 * A Storage backend
30 *
31 * @package Extbase
32 * @subpackage Persistence\Storage
33 * @version $Id$
34 */
35 class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persistence_Storage_BackendInterface, t3lib_Singleton {
36
37 const OPERATOR_EQUAL_TO_NULL = 'operatorEqualToNull';
38 const OPERATOR_NOT_EQUAL_TO_NULL = 'operatorNotEqualToNull';
39
40 /**
41 * The TYPO3 database object
42 *
43 * @var t3lib_db
44 */
45 protected $databaseHandle;
46
47 /**
48 * @var Tx_Extbase_Persistence_Mapper_DataMapper
49 */
50 protected $dataMapper;
51
52 /**
53 * The TYPO3 page select object. Used for language and workspace overlay
54 *
55 * @var t3lib_pageSelect
56 */
57 protected $pageSelectObject;
58
59 /**
60 * A first-level TypoScript configuration cache
61 *
62 * @var array
63 */
64 protected $pageTSConfigCache = array();
65
66 /**
67 * Caches information about tables (esp. the existing column names)
68 *
69 * @var array
70 */
71 protected $tableInformationCache = array();
72
73 /**
74 * @var Tx_Extbase_Configuration_ConfigurationManagerInterface
75 */
76 protected $configurationManager;
77
78 /**
79 * @var Tx_Extbase_Service_CacheService
80 */
81 protected $cacheService;
82
83 /**
84 * Constructor. takes the database handle from $GLOBALS['TYPO3_DB']
85 */
86 public function __construct() {
87 $this->databaseHandle = $GLOBALS['TYPO3_DB'];
88 }
89
90 /**
91 * @param Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager
92 * @return void
93 */
94 public function injectConfigurationManager(Tx_Extbase_Configuration_ConfigurationManagerInterface $configurationManager) {
95 $this->configurationManager = $configurationManager;
96 }
97
98 /**
99 * Injects the DataMapper to map nodes to objects
100 *
101 * @param Tx_Extbase_Persistence_Mapper_DataMapper $dataMapper
102 * @return void
103 */
104 public function injectDataMapper(Tx_Extbase_Persistence_Mapper_DataMapper $dataMapper) {
105 $this->dataMapper = $dataMapper;
106 }
107
108 /**
109 * @param Tx_Extbase_Service_CacheService $cacheService
110 * @return void
111 */
112 public function injectCacheService(Tx_Extbase_Service_CacheService $cacheService) {
113 $this->cacheService = $cacheService;
114 }
115
116 /**
117 * Adds a row to the storage
118 *
119 * @param string $tableName The database table name
120 * @param array $row The row to be inserted
121 * @param boolean $isRelation TRUE if we are currently inserting into a relation table, FALSE by default
122 * @return int The uid of the inserted row
123 */
124 public function addRow($tableName, array $row, $isRelation = FALSE) {
125 $fields = array();
126 $values = array();
127 $parameters = array();
128 if (isset($row['uid'])) {
129 unset($row['uid']);
130 }
131 foreach ($row as $columnName => $value) {
132 $fields[] = $columnName;
133 $values[] = '?';
134 $parameters[] = $value;
135 }
136
137 $sqlString = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $fields) . ') VALUES (' . implode(', ', $values) . ')';
138 $this->replacePlaceholders($sqlString, $parameters);
139 // debug($sqlString,-2);
140 $this->databaseHandle->sql_query($sqlString);
141 $this->checkSqlErrors($sqlString);
142 $uid = $this->databaseHandle->sql_insert_id();
143 if (!$isRelation) {
144 $this->clearPageCache($tableName, $uid);
145 }
146 return (int)$uid;
147 }
148
149 /**
150 * Updates a row in the storage
151 *
152 * @param string $tableName The database table name
153 * @param array $row The row to be updated
154 * @param boolean $isRelation TRUE if we are currently inserting into a relation table, FALSE by default
155 * @return bool
156 */
157 public function updateRow($tableName, array $row, $isRelation = FALSE) {
158 if (!isset($row['uid'])) throw new InvalidArgumentException('The given row must contain a value for "uid".');
159 $uid = (int)$row['uid'];
160 unset($row['uid']);
161 $fields = array();
162 $parameters = array();
163 foreach ($row as $columnName => $value) {
164 $fields[] = $columnName . '=?';
165 $parameters[] = $value;
166 }
167 $parameters[] = $uid;
168
169 $sqlString = 'UPDATE ' . $tableName . ' SET ' . implode(', ', $fields) . ' WHERE uid=?';
170 $this->replacePlaceholders($sqlString, $parameters);
171 // debug($sqlString,-2);
172 $returnValue = $this->databaseHandle->sql_query($sqlString);
173 $this->checkSqlErrors($sqlString);
174 if (!$isRelation) {
175 $this->clearPageCache($tableName, $uid);
176 }
177 return $returnValue;
178 }
179
180 /**
181 * Deletes a row in the storage
182 *
183 * @param string $tableName The database table name
184 * @param array $identifier An array of identifier array('fieldname' => value). This array will be transformed to a WHERE clause
185 * @param boolean $isRelation TRUE if we are currently manipulating a relation table, FALSE by default
186 * @return bool
187 */
188 public function removeRow($tableName, array $identifier, $isRelation = FALSE) {
189 $statement = 'DELETE FROM ' . $tableName . ' WHERE ' . $this->parseIdentifier($identifier);
190 $this->replacePlaceholders($statement, $identifier);
191 if (!$isRelation && isset($identifier['uid'])) {
192 $this->clearPageCache($tableName, $identifier['uid'], $isRelation);
193 }
194 // debug($statement, -2);
195 $returnValue = $this->databaseHandle->sql_query($statement);
196 $this->checkSqlErrors($statement);
197 return $returnValue;
198 }
199
200 /**
201 * Fetches row data from the database
202 *
203 * @param string $identifier The Identifier of the row to fetch
204 * @param Tx_Extbase_Persistence_Mapper_DataMap $dataMap The Data Map
205 * @return array|FALSE
206 */
207 public function getRowByIdentifier($tableName, array $identifier) {
208 $statement = 'SELECT * FROM ' . $tableName . ' WHERE ' . $this->parseIdentifier($identifier);
209 $this->replacePlaceholders($statement, $identifier);
210 // debug($statement,-2);
211 $res = $this->databaseHandle->sql_query($statement);
212 $this->checkSqlErrors($statement);
213 $row = $this->databaseHandle->sql_fetch_assoc($res);
214 if ($row !== FALSE) {
215 return $row;
216 } else {
217 return FALSE;
218 }
219 }
220
221 protected function parseIdentifier(array $identifier) {
222 $fieldNames = array_keys($identifier);
223 $suffixedFieldNames = array();
224 foreach ($fieldNames as $fieldName) {
225 $suffixedFieldNames[] = $fieldName . '=?';
226 }
227 return implode(' AND ', $suffixedFieldNames);
228 }
229
230 /**
231 * Returns the object data matching the $query.
232 *
233 * @param Tx_Extbase_Persistence_QueryInterface $query
234 * @return array
235 * @author Karsten Dambekalns <karsten@typo3.org>
236 */
237 public function getObjectDataByQuery(Tx_Extbase_Persistence_QueryInterface $query) {
238 $parameters = array();
239
240 $statement = $query->getStatement();
241 if($statement instanceof Tx_Extbase_Persistence_QOM_Statement) {
242 $sql = $statement->getStatement();
243 $parameters = $statement->getBoundVariables();
244 } else {
245 $parameters = array();
246 $statementParts = $this->parseQuery($query, $parameters);
247 $sql = $this->buildQuery($statementParts, $parameters);
248 }
249 $this->replacePlaceholders($sql, $parameters);
250 // debug($sql,-2);
251 $result = $this->databaseHandle->sql_query($sql);
252 $this->checkSqlErrors($sql);
253 $rows = $this->getRowsFromResult($query->getSource(), $result);
254 $this->databaseHandle->sql_free_result($result);
255 $rows = $this->doLanguageAndWorkspaceOverlay($query->getSource(), $rows);
256 // TODO: implement $objectData = $this->processObjectRecords($statementHandle);
257 return $rows;
258 }
259
260 /**
261 * Returns the number of tuples matching the query.
262 *
263 * @param Tx_Extbase_Persistence_QOM_QueryObjectModelInterface $query
264 * @return integer The number of matching tuples
265 */
266 public function getObjectCountByQuery(Tx_Extbase_Persistence_QueryInterface $query) {
267 $constraint = $query->getConstraint();
268 if($constraint instanceof Tx_Extbase_Persistence_QOM_StatementInterface) {
269 throw new Tx_Extbase_Persistence_Storage_Exception_BadConstraint('Could not execute count on queries with a constraint of type Tx_Extbase_Persistence_QOM_StatementInterface', 1256661045);
270 }
271 $parameters = array();
272 $statementParts = $this->parseQuery($query, $parameters);
273 // if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints
274 if (!empty($statementParts['limit'])) {
275 $statement = $this->buildQuery($statementParts, $parameters);
276 $this->replacePlaceholders($statement, $parameters);
277 $result = $this->databaseHandle->sql_query($statement);
278 $this->checkSqlErrors($statement);
279 $count = $this->databaseHandle->sql_num_rows($result);
280 } else {
281 $statementParts['fields'] = array('COUNT(*)');
282 if (isset($statementParts['keywords']['distinct'])) {
283 unset($statementParts['keywords']['distinct']);
284 $statementParts['fields'] = array('COUNT(DISTINCT ' . reset($statementParts['tables']) . '.uid)');
285 }
286 $statement = $this->buildQuery($statementParts, $parameters);
287 $this->replacePlaceholders($statement, $parameters);
288 $result = $this->databaseHandle->sql_query($statement);
289 $this->checkSqlErrors($statement);
290 $rows = $this->getRowsFromResult($query->getSource(), $result);
291 $count = current(current($rows));
292 }
293 $this->databaseHandle->sql_free_result($result);
294 return (int)$count;
295 }
296
297 /**
298 * Parses the query and returns the SQL statement parts.
299 *
300 * @param Tx_Extbase_Persistence_QueryInterface $query The query
301 * @return array The SQL statement parts
302 */
303 public function parseQuery(Tx_Extbase_Persistence_QueryInterface $query, array &$parameters) {
304 $sql = array();
305 $sql['keywords'] = array();
306 $sql['tables'] = array();
307 $sql['unions'] = array();
308 $sql['fields'] = array();
309 $sql['where'] = array();
310 $sql['additionalWhereClause'] = array();
311 $sql['orderings'] = array();
312 $sql['limit'] = array();
313
314 $source = $query->getSource();
315
316 $this->parseSource($source, $sql, $parameters);
317 $this->parseConstraint($query->getConstraint(), $source, $sql, $parameters);
318 $this->parseOrderings($query->getOrderings(), $source, $sql);
319 $this->parseLimitAndOffset($query->getLimit(), $query->getOffset(), $sql);
320
321 $tableNames = array_unique(array_keys($sql['tables'] + $sql['unions']));
322 foreach ($tableNames as $tableName) {
323 if (is_string($tableName) && strlen($tableName) > 0) {
324 $this->addAdditionalWhereClause($query->getQuerySettings(), $tableName, $sql);
325 }
326 }
327
328 return $sql;
329 }
330
331 /**
332 * Returns the statement, ready to be executed.
333 *
334 * @param array $sql The SQL statement parts
335 * @return string The SQL statement
336 */
337 public function buildQuery(array $sql) {
338 $statement = 'SELECT ' . implode(' ', $sql['keywords']) . ' '. implode(',', $sql['fields']) . ' FROM ' . implode(' ', $sql['tables']) . ' '. implode(' ', $sql['unions']);
339 if (!empty($sql['where'])) {
340 $statement .= ' WHERE ' . implode('', $sql['where']);
341 if (!empty($sql['additionalWhereClause'])) {
342 $statement .= ' AND ' . implode(' AND ', $sql['additionalWhereClause']);
343 }
344 } elseif (!empty($sql['additionalWhereClause'])) {
345 $statement .= ' WHERE ' . implode(' AND ', $sql['additionalWhereClause']);
346 }
347 if (!empty($sql['orderings'])) {
348 $statement .= ' ORDER BY ' . implode(', ', $sql['orderings']);
349 }
350 if (!empty($sql['limit'])) {
351 $statement .= ' LIMIT ' . $sql['limit'];
352 }
353 return $statement;
354 }
355
356 /**
357 * Checks if a Value Object equal to the given Object exists in the data base
358 *
359 * @param Tx_Extbase_DomainObject_AbstractValueObject $object The Value Object
360 * @return mixed The matching uid if an object was found, else FALSE
361 */
362 public function getUidOfAlreadyPersistedValueObject(Tx_Extbase_DomainObject_AbstractValueObject $object) {
363 $fields = array();
364 $parameters = array();
365 $dataMap = $this->dataMapper->getDataMap(get_class($object));
366 $properties = $object->_getProperties();
367 foreach ($properties as $propertyName => $propertyValue) {
368 // FIXME We couple the Backend to the Entity implementation (uid, isClone); changes there breaks this method
369 if ($dataMap->isPersistableProperty($propertyName) && ($propertyName !== 'uid') && ($propertyName !== 'pid') && ($propertyName !== 'isClone')) {
370 if ($propertyValue === NULL) {
371 $fields[] = $dataMap->getColumnMap($propertyName)->getColumnName() . ' IS NULL';
372 } else {
373 $fields[] = $dataMap->getColumnMap($propertyName)->getColumnName() . '=?';
374 $parameters[] = $this->getPlainValue($propertyValue);
375 }
376 }
377 }
378 $sql = array();
379 $sql['additionalWhereClause'] = array();
380
381 $tableName = $dataMap->getTableName();
382 $this->addEnableFieldsStatement($tableName, $sql);
383
384 $statement = 'SELECT * FROM ' . $tableName;
385 $statement .= ' WHERE ' . implode(' AND ', $fields);
386 if (!empty($sql['additionalWhereClause'])) {
387 $statement .= ' AND ' . implode(' AND ', $sql['additionalWhereClause']);
388 }
389 $this->replacePlaceholders($statement, $parameters);
390 // debug($statement,-2);
391 $res = $this->databaseHandle->sql_query($statement);
392 $this->checkSqlErrors($statement);
393 $row = $this->databaseHandle->sql_fetch_assoc($res);
394 if ($row !== FALSE) {
395 return (int)$row['uid'];
396 } else {
397 return FALSE;
398 }
399 }
400
401 /**
402 * Transforms a Query Source into SQL and parameter arrays
403 *
404 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source
405 * @param array &$sql
406 * @param array &$parameters
407 * @return void
408 */
409 protected function parseSource(Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql) {
410 if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
411 $className = $source->getNodeTypeName();
412 $tableName = $this->dataMapper->getDataMap($className)->getTableName();
413 $this->addRecordTypeConstraint($className, $sql);
414 $sql['fields'][$tableName] = $tableName . '.*';
415 $sql['tables'][$tableName] = $tableName;
416 } elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
417 $this->parseJoin($source, $sql);
418 }
419 }
420
421 /**
422 * Adda a constrint to ensure that the record type of the returned tuples is matching the data type of the repository.
423 *
424 * @param string $className The class name
425 * @param array &$sql The query parts
426 * @return void
427 */
428 protected function addRecordTypeConstraint($className, &$sql) {
429 if ($className !== NULL) {
430 $dataMap = $this->dataMapper->getDataMap($className);
431 if ($dataMap->getRecordTypeColumnName() !== NULL) {
432 $recordTypes = array();
433 if ($dataMap->getRecordType() !== NULL) {
434 $recordTypes[] = $dataMap->getRecordType();
435 }
436 foreach ($dataMap->getSubclasses() as $subclassName) {
437 $subclassDataMap = $this->dataMapper->getDataMap($subclassName);
438 if ($subclassDataMap->getRecordType() !== NULL) {
439 $recordTypes[] = $subclassDataMap->getRecordType();
440 }
441 }
442 if (count($recordTypes) > 0) {
443 $recordTypeStatements = array();
444 foreach ($recordTypes as $recordType) {
445 $recordTypeStatements[] = $dataMap->getTableName() . '.' . $dataMap->getRecordTypeColumnName() . '=' . $this->databaseHandle->fullQuoteStr($recordType, 'foo');
446 }
447 $sql['additionalWhereClause'][] = '(' . implode(' OR ', $recordTypeStatements) . ')';
448 }
449 }
450 }
451 }
452
453 /**
454 * Transforms a Join into SQL and parameter arrays
455 *
456 * @param Tx_Extbase_Persistence_QOM_JoinInterface $join The join
457 * @param array &$sql The query parts
458 * @return void
459 */
460 protected function parseJoin(Tx_Extbase_Persistence_QOM_JoinInterface $join, array &$sql) {
461 $leftSource = $join->getLeft();
462 $leftClassName = $leftSource->getNodeTypeName();
463 $this->addRecordTypeConstraint($leftClassName, $sql);
464 $leftTableName = $leftSource->getSelectorName();
465 // $sql['fields'][$leftTableName] = $leftTableName . '.*';
466 $rightSource = $join->getRight();
467 if ($rightSource instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
468 $rightClassName = $rightSource->getLeft()->getNodeTypeName();
469 $rightTableName = $rightSource->getLeft()->getSelectorName();
470 } else {
471 $rightClassName = $rightSource->getNodeTypeName();
472 $rightTableName = $rightSource->getSelectorName();
473 $sql['fields'][$leftTableName] = $rightTableName . '.*';
474 }
475 $this->addRecordTypeConstraint($rightClassName, $sql);
476
477 $sql['tables'][$leftTableName] = $leftTableName;
478 $sql['unions'][$rightTableName] = 'LEFT JOIN ' . $rightTableName;
479
480 $joinCondition = $join->getJoinCondition();
481 if ($joinCondition instanceof Tx_Extbase_Persistence_QOM_EquiJoinCondition) {
482 $column1Name = $this->dataMapper->convertPropertyNameToColumnName($joinCondition->getProperty1Name(), $leftClassName);
483 $column2Name = $this->dataMapper->convertPropertyNameToColumnName($joinCondition->getProperty2Name(), $rightClassName);
484 $sql['unions'][$rightTableName] .= ' ON ' . $joinCondition->getSelector1Name() . '.' . $column1Name . ' = ' . $joinCondition->getSelector2Name() . '.' . $column2Name;
485 }
486 if ($rightSource instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
487 $this->parseJoin($rightSource, $sql);
488 }
489 }
490
491 /**
492 * Transforms a constraint into SQL and parameter arrays
493 *
494 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint The constraint
495 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source
496 * @param array &$sql The query parts
497 * @param array &$parameters The parameters that will replace the markers
498 * @param array $boundVariableValues The bound variables in the query (key) and their values (value)
499 * @return void
500 */
501 protected function parseConstraint(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint = NULL, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters) {
502 if ($constraint instanceof Tx_Extbase_Persistence_QOM_AndInterface) {
503 $sql['where'][] = '(';
504 $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters);
505 $sql['where'][] = ' AND ';
506 $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters);
507 $sql['where'][] = ')';
508 } elseif ($constraint instanceof Tx_Extbase_Persistence_QOM_OrInterface) {
509 $sql['where'][] = '(';
510 $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters);
511 $sql['where'][] = ' OR ';
512 $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters);
513 $sql['where'][] = ')';
514 } elseif ($constraint instanceof Tx_Extbase_Persistence_QOM_NotInterface) {
515 $sql['where'][] = 'NOT (';
516 $this->parseConstraint($constraint->getConstraint(), $source, $sql, $parameters);
517 $sql['where'][] = ')';
518 } elseif ($constraint instanceof Tx_Extbase_Persistence_QOM_ComparisonInterface) {
519 $this->parseComparison($constraint, $source, $sql, $parameters);
520 }
521 }
522
523 /**
524 * Parse a Comparison into SQL and parameter arrays.
525 *
526 * @param Tx_Extbase_Persistence_QOM_ComparisonInterface $comparison The comparison to parse
527 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source
528 * @param array &$sql SQL query parts to add to
529 * @param array &$parameters Parameters to bind to the SQL
530 * @param array $boundVariableValues The bound variables in the query and their values
531 * @return void
532 */
533 protected function parseComparison(Tx_Extbase_Persistence_QOM_ComparisonInterface $comparison, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters) {
534 $operand1 = $comparison->getOperand1();
535 $operator = $comparison->getOperator();
536 $operand2 = $comparison->getOperand2();
537
538 /**
539 * This if enables equals() to behave like in(). Use in() instead.
540 * @deprecated since Extbase 1.3; will be removed in Extbase 1.5
541 */
542 if (($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO) && (is_array($operand2) || ($operand2 instanceof ArrayAccess) || ($operand2 instanceof Traversable))) {
543 $operator = Tx_Extbase_Persistence_QueryInterface::OPERATOR_IN;
544 }
545
546 if ($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_IN) {
547 $items = array();
548 $hasValue = FALSE;
549 foreach ($operand2 as $value) {
550 $value = $this->getPlainValue($value);
551 if ($value !== NULL) {
552 $items[] = $value;
553 $hasValue = TRUE;
554 }
555 }
556 if ($hasValue === FALSE) {
557 $sql['where'][] = '1<>1';
558 } else {
559 $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters, NULL, $operand2);
560 $parameters[] = $items;
561 }
562 } elseif ($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_CONTAINS) {
563 if ($operand2 === NULL) {
564 $sql['where'][] = '1<>1';
565 } else {
566 $className = $source->getNodeTypeName();
567 $tableName = $this->dataMapper->convertClassNameToTableName($className);
568 $propertyName = $operand1->getPropertyName();
569 while (strpos($propertyName, '.') !== FALSE) {
570 $this->addUnionStatement($className, $tableName, $propertyName, $sql);
571 }
572 $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
573 $dataMap = $this->dataMapper->getDataMap($className);
574 $columnMap = $dataMap->getColumnMap($propertyName);
575 $typeOfRelation = $columnMap->getTypeOfRelation();
576 if ($typeOfRelation === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
577 $relationTableName = $columnMap->getRelationTableName();
578 $sql['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=' . $this->getPlainValue($operand2) . ')';
579 } elseif ($typeOfRelation === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
580 $parentKeyFieldName = $columnMap->getParentKeyFieldName();
581 if (isset($parentKeyFieldName)) {
582 $childTableName = $columnMap->getChildTableName();
583 $sql['where'][] = $tableName . '.uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=' . $this->getPlainValue($operand2) . ')';
584 } else {
585 $statement = 'FIND_IN_SET(' . $this->getPlainValue($operand2) . ',' . $tableName . '.' . $columnName . ')';
586 $sql['where'][] = $statement;
587 }
588 } else {
589 throw new Tx_Extbase_Persistence_Exception_RepositoryException('Unsupported relation for contains().', 1267832524);
590 }
591 }
592 } else {
593 if ($operand2 === NULL) {
594 if ($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO) {
595 $operator = self::OPERATOR_EQUAL_TO_NULL;
596 } elseif ($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_NOT_EQUAL_TO) {
597 $operator = self::OPERATOR_NOT_EQUAL_TO_NULL;
598 }
599 }
600 $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters);
601 $parameters[] = $this->getPlainValue($operand2);
602 }
603 }
604
605 /**
606 * Returns a plain value, i.e. objects are flattened out if possible.
607 *
608 * @param mixed $input
609 * @return mixed
610 */
611 protected function getPlainValue($input) {
612 if (is_array($input)) {
613 throw new Tx_Extbase_Persistence_Exception_UnexpectedTypeException('An array could not be converted to a plain value.', 1274799932);
614 }
615 if ($input instanceof DateTime) {
616 return $input->format('U');
617 } elseif (is_object($input)) {
618 if ($input instanceof Tx_Extbase_DomainObject_DomainObjectInterface) {
619 return $input->getUid();
620 } else {
621 throw new Tx_Extbase_Persistence_Exception_UnexpectedTypeException('An object of class "' . get_class($input) . '" could not be converted to a plain value.', 1274799934);
622 }
623 } elseif (is_bool($input)) {
624 return $input === TRUE ? 1 : 0;
625 } else {
626 return $input;
627 }
628 }
629
630 /**
631 * Parse a DynamicOperand into SQL and parameter arrays.
632 *
633 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand
634 * @param string $operator One of the JCR_OPERATOR_* constants
635 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source
636 * @param array &$sql The query parts
637 * @param array &$parameters The parameters that will replace the markers
638 * @param string $valueFunction an optional SQL function to apply to the operand value
639 * @return void
640 */
641 protected function parseDynamicOperand(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand, $operator, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters, $valueFunction = NULL, $operand2 = NULL) {
642 if ($operand instanceof Tx_Extbase_Persistence_QOM_LowerCaseInterface) {
643 $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'LOWER');
644 } elseif ($operand instanceof Tx_Extbase_Persistence_QOM_UpperCaseInterface) {
645 $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'UPPER');
646 } elseif ($operand instanceof Tx_Extbase_Persistence_QOM_PropertyValueInterface) {
647 $propertyName = $operand->getPropertyName();
648 if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) { // FIXME Only necessary to differ from Join
649 $className = $source->getNodeTypeName();
650 $tableName = $this->dataMapper->convertClassNameToTableName($className);
651 while (strpos($propertyName, '.') !== FALSE) {
652 $this->addUnionStatement($className, $tableName, $propertyName, $sql);
653 }
654 } elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
655 $tableName = $source->getJoinCondition()->getSelector1Name();
656 }
657 $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
658 $operator = $this->resolveOperator($operator);
659 if ($valueFunction === NULL) {
660 $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $operator . ' ?';
661 } else {
662 $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $operator . ' ?';
663 }
664
665 $sql['where'][] = $constraintSQL;
666 }
667 }
668
669 protected function addUnionStatement(&$className, &$tableName, &$propertyPath, array &$sql) {
670 $explodedPropertyPath = explode('.', $propertyPath, 2);
671 $propertyName = $explodedPropertyPath[0];
672 $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
673 $tableName = $this->dataMapper->convertClassNameToTableName($className);
674 $columnMap = $this->dataMapper->getDataMap($className)->getColumnMap($propertyName);
675 $parentKeyFieldName = $columnMap->getParentKeyFieldName();
676 $childTableName = $columnMap->getChildTableName();
677 if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_ONE) {
678 if (isset($parentKeyFieldName)) {
679 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
680 } else {
681 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $columnName . '=' . $childTableName . '.uid';
682 }
683 $className = $this->dataMapper->getType($className, $propertyName);
684 } elseif ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
685 if (isset($parentKeyFieldName)) {
686 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
687 } else {
688 $onStatement = '(FIND_IN_SET(' . $childTableName . '.uid, ' . $tableName . '.' . $columnName . '))';
689 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $onStatement;
690 }
691 $className = $this->dataMapper->getType($className, $propertyName);
692 } elseif ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
693 $relationTableName = $columnMap->getRelationTableName();
694 $sql['unions'][$relationTableName] = 'LEFT JOIN ' . $relationTableName . ' ON ' . $tableName . '.uid=' . $relationTableName . '.' . $columnMap->getParentKeyFieldName();
695 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $relationTableName . '.'. $columnMap->getChildKeyFieldName() . '=' . $childTableName . '.uid';
696 $className = $this->dataMapper->getType($className, $propertyName);
697 } else {
698 throw new Tx_Extbase_Persistence_Exception('Could not determine type of relation.', 1252502725);
699 }
700 // TODO check if there is another solution for this
701 $sql['keywords']['distinct'] = 'DISTINCT';
702 $propertyPath = $explodedPropertyPath[1];
703 $tableName = $childTableName;
704 }
705
706 /**
707 * Returns the SQL operator for the given JCR operator type.
708 *
709 * @param string $operator One of the JCR_OPERATOR_* constants
710 * @return string an SQL operator
711 */
712 protected function resolveOperator($operator) {
713 switch ($operator) {
714 case self::OPERATOR_EQUAL_TO_NULL:
715 $operator = 'IS';
716 break;
717 case self::OPERATOR_NOT_EQUAL_TO_NULL:
718 $operator = 'IS NOT';
719 break;
720 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_IN:
721 $operator = 'IN';
722 break;
723 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO:
724 $operator = '=';
725 break;
726 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_NOT_EQUAL_TO:
727 $operator = '!=';
728 break;
729 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN:
730 $operator = '<';
731 break;
732 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO:
733 $operator = '<=';
734 break;
735 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN:
736 $operator = '>';
737 break;
738 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO:
739 $operator = '>=';
740 break;
741 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_LIKE:
742 $operator = 'LIKE';
743 break;
744 default:
745 throw new Tx_Extbase_Persistence_Exception('Unsupported operator encountered.', 1242816073);
746 }
747
748 return $operator;
749 }
750
751 /**
752 * Replace query placeholders in a query part by the given
753 * parameters.
754 *
755 * @param string $sqlString The query part with placeholders
756 * @param array $parameters The parameters
757 * @return string The query part with replaced placeholders
758 */
759 protected function replacePlaceholders(&$sqlString, array $parameters) {
760 // TODO profile this method again
761 if (substr_count($sqlString, '?') !== count($parameters)) throw new Tx_Extbase_Persistence_Exception('The number of question marks to replace must be equal to the number of parameters.', 1242816074);
762 $offset = 0;
763 foreach ($parameters as $parameter) {
764 $markPosition = strpos($sqlString, '?', $offset);
765 if ($markPosition !== FALSE) {
766 if ($parameter === NULL) {
767 $parameter = 'NULL';
768 } elseif (is_array($parameter) || ($parameter instanceof ArrayAccess) || ($parameter instanceof Traversable)) {
769 $items = array();
770 foreach ($parameter as $item) {
771 $items[] = $this->databaseHandle->fullQuoteStr($item, 'foo');
772 }
773 $parameter = '(' . implode(',', $items) . ')';
774 } else {
775 $parameter = $this->databaseHandle->fullQuoteStr($parameter, 'foo'); // FIXME This may not work with DBAL; check this
776 }
777 $sqlString = substr($sqlString, 0, $markPosition) . $parameter . substr($sqlString, $markPosition + 1);
778 }
779 $offset = $markPosition + strlen($parameter);
780 }
781 }
782
783 /**
784 * Adds additional WHERE statements according to the query settings.
785 *
786 * @param Tx_Extbase_Persistence_QuerySettingsInterface $querySettings The TYPO3 4.x specific query settings
787 * @param string $tableName The table name to add the additional where clause for
788 * @param string $sql
789 * @return void
790 */
791 protected function addAdditionalWhereClause(Tx_Extbase_Persistence_QuerySettingsInterface $querySettings, $tableName, &$sql) {
792 if ($querySettings->getRespectEnableFields()) {
793 $this->addEnableFieldsStatement($tableName, $sql);
794 }
795 if ($querySettings->getRespectSysLanguage()) {
796 $this->addSysLanguageStatement($tableName, $sql);
797 }
798 if ($querySettings->getRespectStoragePage()) {
799 $this->addPageIdStatement($tableName, $sql, $querySettings->getStoragePageIds());
800 }
801 }
802
803 /**
804 * Builds the enable fields statement
805 *
806 * @param string $tableName The database table name
807 * @param array &$sql The query parts
808 * @return void
809 */
810 protected function addEnableFieldsStatement($tableName, array &$sql) {
811 if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
812 if (TYPO3_MODE === 'FE') {
813 $statement = $GLOBALS['TSFE']->sys_page->enableFields($tableName);
814 } else { // TYPO3_MODE === 'BE'
815 $statement = t3lib_BEfunc::deleteClause($tableName);
816 $statement .= t3lib_BEfunc::BEenableFields($tableName);
817 }
818 if(!empty($statement)) {
819 $statement = substr($statement, 5);
820 $sql['additionalWhereClause'][] = $statement;
821 }
822 }
823 }
824
825 /**
826 * Builds the language field statement
827 *
828 * @param string $tableName The database table name
829 * @param array &$sql The query parts
830 * @return void
831 */
832 protected function addSysLanguageStatement($tableName, array &$sql) {
833 if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
834 if(isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== NULL) {
835 $sql['additionalWhereClause'][] = $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (0,-1)';
836 }
837 }
838 }
839
840 /**
841 * Builds the page ID checking statement
842 *
843 * @param string $tableName The database table name
844 * @param array &$sql The query parts
845 * @param array $storagePageIds list of storage page ids
846 * @return void
847 */
848 protected function addPageIdStatement($tableName, array &$sql, array $storagePageIds) {
849 if (empty($this->tableInformationCache[$tableName]['columnNames'])) {
850 $this->tableInformationCache[$tableName]['columnNames'] = $this->databaseHandle->admin_get_fields($tableName);
851 }
852 if (is_array($GLOBALS['TCA'][$tableName]['ctrl']) && array_key_exists('pid', $this->tableInformationCache[$tableName]['columnNames'])) {
853 $sql['additionalWhereClause'][] = $tableName . '.pid IN (' . implode(', ', $storagePageIds) . ')';
854 }
855 }
856
857 /**
858 * Transforms orderings into SQL.
859 *
860 * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering)
861 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source
862 * @param array &$sql The query parts
863 * @return void
864 */
865 protected function parseOrderings(array $orderings, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql) {
866 foreach ($orderings as $propertyName => $order) {
867 switch ($order) {
868 case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING: // Deprecated since Extbase 1.1
869 case Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING:
870 $order = 'ASC';
871 break;
872 case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING: // Deprecated since Extbase 1.1
873 case Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING:
874 $order = 'DESC';
875 break;
876 default:
877 throw new Tx_Extbase_Persistence_Exception_UnsupportedOrder('Unsupported order encountered.', 1242816074);
878 }
879 if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
880 $className = $source->getNodeTypeName();
881 $tableName = $this->dataMapper->convertClassNameToTableName($className);
882 while (strpos($propertyName, '.') !== FALSE) {
883 $this->addUnionStatement($className, $tableName, $propertyName, $sql);
884 }
885 } elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
886 $tableName = $source->getLeft()->getSelectorName();
887 }
888 $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
889 if (strlen($tableName) > 0) {
890 $sql['orderings'][] = $tableName . '.' . $columnName . ' ' . $order;
891 } else {
892 $sql['orderings'][] = $columnName . ' ' . $order;
893 }
894 }
895 }
896
897 /**
898 * Transforms limit and offset into SQL
899 *
900 * @param int $limit
901 * @param int $offset
902 * @param array &$sql
903 * @return void
904 */
905 protected function parseLimitAndOffset($limit, $offset, array &$sql) {
906 if ($limit !== NULL && $offset !== NULL) {
907 $sql['limit'] = $offset . ', ' . $limit;
908 } elseif ($limit !== NULL) {
909 $sql['limit'] = $limit;
910 }
911 }
912
913 /**
914 * Transforms a Resource from a database query to an array of rows.
915 *
916 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source (selector od join)
917 * @param resource $result The result
918 * @return array The result as an array of rows (tuples)
919 */
920 protected function getRowsFromResult(Tx_Extbase_Persistence_QOM_SourceInterface $source, $result) {
921 $rows = array();
922 while ($row = $this->databaseHandle->sql_fetch_assoc($result)) {
923 if (is_array($row)) {
924 // TODO Check if this is necessary, maybe the last line is enough
925 $arrayKeys = range(0, count($row));
926 array_fill_keys($arrayKeys, $row);
927 $rows[] = $row;
928 }
929 }
930 return $rows;
931 }
932
933 /**
934 * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
935 * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
936 *
937 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source (selector od join)
938 * @param array $row The row array (as reference)
939 * @param string $languageUid The language id
940 * @param string $workspaceUidUid The workspace id
941 * @return void
942 */
943 protected function doLanguageAndWorkspaceOverlay(Tx_Extbase_Persistence_QOM_SourceInterface $source, array $rows, $languageUid = NULL, $workspaceUid = NULL) {
944 $overlayedRows = array();
945 foreach ($rows as $row) {
946 if (!($this->pageSelectObject instanceof t3lib_pageSelect)) {
947 if (TYPO3_MODE == 'FE') {
948 if (is_object($GLOBALS['TSFE'])) {
949 $this->pageSelectObject = $GLOBALS['TSFE']->sys_page;
950 } else {
951 $this->pageSelectObject = t3lib_div::makeInstance('t3lib_pageSelect');
952 }
953 } else {
954 $this->pageSelectObject = t3lib_div::makeInstance( 't3lib_pageSelect' );
955 }
956 }
957 if (is_object($GLOBALS['TSFE'])) {
958 if ($languageUid === NULL) {
959 // get the language UID of the content that should be output
960 $languageUid = $GLOBALS['TSFE']->sys_language_content;
961 $languageMode = $GLOBALS['TSFE']->sys_language_mode;
962 }
963 if ($workspaceUid !== NULL) {
964 $this->pageSelectObject->versioningWorkspaceId = $workspaceUid;
965 }
966 } else {
967 if ($languageUid === NULL) {
968 $languageUid = intval(t3lib_div::_GP('L'));
969 }
970 if ($workspaceUid === NULL) {
971 $workspaceUid = $GLOBALS['BE_USER']->workspace;
972 }
973 $this->pageSelectObject->versioningWorkspaceId = $workspaceUid;
974 }
975 if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
976 $tableName = $source->getSelectorName();
977 } elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
978 $tableName = $source->getRight()->getSelectorName();
979 }
980 $this->pageSelectObject->versionOL($tableName, $row, TRUE);
981 if($tableName == 'pages') {
982 $row = $this->pageSelectObject->getPageOverlay($row, $languageUid);
983 } elseif(isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '') {
984 if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1,0))) {
985 $overlayMode = ($languageMode === 'strict') ? 'hideNonTranslated' : '';
986 $row = $this->pageSelectObject->getRecordOverlay($tableName, $row, $languageUid, $overlayMode);
987 }
988 }
989 if ($row !== NULL && is_array($row)) {
990 $overlayedRows[] = $row;
991 }
992 }
993 return $overlayedRows;
994 }
995
996 /**
997 * Checks if there are SQL errors in the last query, and if yes, throw an exception.
998 *
999 * @return void
1000 * @param string $sql The SQL statement
1001 * @throws Tx_Extbase_Persistence_Storage_Exception_SqlError
1002 */
1003 protected function checkSqlErrors($sql='') {
1004 $error = $this->databaseHandle->sql_error();
1005 if ($error !== '') {
1006 $error .= $sql ? ': ' . $sql : '';
1007 throw new Tx_Extbase_Persistence_Storage_Exception_SqlError($error, 1247602160);
1008 }
1009 }
1010
1011 /**
1012 * Clear the TYPO3 page cache for the given record.
1013 * If the record lies on a page, then we clear the cache of this page.
1014 * If the record has no PID column, we clear the cache of the current page as best-effort.
1015 *
1016 * Much of this functionality is taken from t3lib_tcemain::clear_cache() which unfortunately only works with logged-in BE user.
1017 *
1018 * @param $tableName Table name of the record
1019 * @param $uid UID of the record
1020 * @return void
1021 */
1022 protected function clearPageCache($tableName, $uid) {
1023 $frameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
1024 if (isset($frameworkConfiguration['persistence']['enableAutomaticCacheClearing']) && $frameworkConfiguration['persistence']['enableAutomaticCacheClearing'] === '1') {
1025 } else {
1026 // if disabled, return
1027 return;
1028 }
1029
1030 $pageIdsToClear = array();
1031 $storagePage = NULL;
1032
1033 $columns = $this->databaseHandle->admin_get_fields($tableName);
1034 if (array_key_exists('pid', $columns)) {
1035 $result = $this->databaseHandle->exec_SELECTquery('pid', $tableName, 'uid='.intval($uid));
1036 if ($row = $this->databaseHandle->sql_fetch_assoc($result)) {
1037 $storagePage = $row['pid'];
1038 $pageIdsToClear[] = $storagePage;
1039 }
1040 } elseif (isset($GLOBALS['TSFE'])) {
1041 // No PID column - we can do a best-effort to clear the cache of the current page if in FE
1042 $storagePage = $GLOBALS['TSFE']->id;
1043 $pageIdsToClear[] = $storagePage;
1044 }
1045
1046 if ($storagePage === NULL) {
1047 return;
1048 }
1049 if (!isset($this->pageTSConfigCache[$storagePage])) {
1050 $this->pageTSConfigCache[$storagePage] = t3lib_BEfunc::getPagesTSconfig($storagePage);
1051 }
1052 if (isset($this->pageTSConfigCache[$storagePage]['TCEMAIN.']['clearCacheCmd'])) {
1053 $clearCacheCommands = t3lib_div::trimExplode(',',strtolower($this->pageTSConfigCache[$storagePage]['TCEMAIN.']['clearCacheCmd']),1);
1054 $clearCacheCommands = array_unique($clearCacheCommands);
1055 foreach ($clearCacheCommands as $clearCacheCommand) {
1056 if (t3lib_utility_Math::canBeInterpretedAsInteger($clearCacheCommand)) {
1057 $pageIdsToClear[] = $clearCacheCommand;
1058 }
1059 }
1060 }
1061
1062 // TODO check if we can hand this over to the Dispatcher to clear the page only once, this will save around 10% time while inserting and updating
1063 $this->cacheService->clearPageCache($pageIdsToClear);
1064 }
1065 }
1066
1067 ?>