[BUGFIX] parseDynamicOperand appends to uninitialized variable
[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);
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 * @return void
407 */
408 protected function parseSource(Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql) {
409 if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
410 $className = $source->getNodeTypeName();
411 $tableName = $this->dataMapper->getDataMap($className)->getTableName();
412 $this->addRecordTypeConstraint($className, $sql);
413 $sql['fields'][$tableName] = $tableName . '.*';
414 $sql['tables'][$tableName] = $tableName;
415 } elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
416 $this->parseJoin($source, $sql);
417 }
418 }
419
420 /**
421 * Adda a constrint to ensure that the record type of the returned tuples is matching the data type of the repository.
422 *
423 * @param string $className The class name
424 * @param array &$sql The query parts
425 * @return void
426 */
427 protected function addRecordTypeConstraint($className, &$sql) {
428 if ($className !== NULL) {
429 $dataMap = $this->dataMapper->getDataMap($className);
430 if ($dataMap->getRecordTypeColumnName() !== NULL) {
431 $recordTypes = array();
432 if ($dataMap->getRecordType() !== NULL) {
433 $recordTypes[] = $dataMap->getRecordType();
434 }
435 foreach ($dataMap->getSubclasses() as $subclassName) {
436 $subclassDataMap = $this->dataMapper->getDataMap($subclassName);
437 if ($subclassDataMap->getRecordType() !== NULL) {
438 $recordTypes[] = $subclassDataMap->getRecordType();
439 }
440 }
441 if (count($recordTypes) > 0) {
442 $recordTypeStatements = array();
443 foreach ($recordTypes as $recordType) {
444 $recordTypeStatements[] = $dataMap->getTableName() . '.' . $dataMap->getRecordTypeColumnName() . '=' . $this->databaseHandle->fullQuoteStr($recordType, 'foo');
445 }
446 $sql['additionalWhereClause'][] = '(' . implode(' OR ', $recordTypeStatements) . ')';
447 }
448 }
449 }
450 }
451
452 /**
453 * Transforms a Join into SQL and parameter arrays
454 *
455 * @param Tx_Extbase_Persistence_QOM_JoinInterface $join The join
456 * @param array &$sql The query parts
457 * @return void
458 */
459 protected function parseJoin(Tx_Extbase_Persistence_QOM_JoinInterface $join, array &$sql) {
460 $leftSource = $join->getLeft();
461 $leftClassName = $leftSource->getNodeTypeName();
462 $this->addRecordTypeConstraint($leftClassName, $sql);
463 $leftTableName = $leftSource->getSelectorName();
464 // $sql['fields'][$leftTableName] = $leftTableName . '.*';
465 $rightSource = $join->getRight();
466 if ($rightSource instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
467 $rightClassName = $rightSource->getLeft()->getNodeTypeName();
468 $rightTableName = $rightSource->getLeft()->getSelectorName();
469 } else {
470 $rightClassName = $rightSource->getNodeTypeName();
471 $rightTableName = $rightSource->getSelectorName();
472 $sql['fields'][$leftTableName] = $rightTableName . '.*';
473 }
474 $this->addRecordTypeConstraint($rightClassName, $sql);
475
476 $sql['tables'][$leftTableName] = $leftTableName;
477 $sql['unions'][$rightTableName] = 'LEFT JOIN ' . $rightTableName;
478
479 $joinCondition = $join->getJoinCondition();
480 if ($joinCondition instanceof Tx_Extbase_Persistence_QOM_EquiJoinCondition) {
481 $column1Name = $this->dataMapper->convertPropertyNameToColumnName($joinCondition->getProperty1Name(), $leftClassName);
482 $column2Name = $this->dataMapper->convertPropertyNameToColumnName($joinCondition->getProperty2Name(), $rightClassName);
483 $sql['unions'][$rightTableName] .= ' ON ' . $joinCondition->getSelector1Name() . '.' . $column1Name . ' = ' . $joinCondition->getSelector2Name() . '.' . $column2Name;
484 }
485 if ($rightSource instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
486 $this->parseJoin($rightSource, $sql);
487 }
488 }
489
490 /**
491 * Transforms a constraint into SQL and parameter arrays
492 *
493 * @param Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint The constraint
494 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source
495 * @param array &$sql The query parts
496 * @param array &$parameters The parameters that will replace the markers
497 * @param array $boundVariableValues The bound variables in the query (key) and their values (value)
498 * @return void
499 */
500 protected function parseConstraint(Tx_Extbase_Persistence_QOM_ConstraintInterface $constraint = NULL, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters) {
501 if ($constraint instanceof Tx_Extbase_Persistence_QOM_AndInterface) {
502 $sql['where'][] = '(';
503 $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters);
504 $sql['where'][] = ' AND ';
505 $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters);
506 $sql['where'][] = ')';
507 } elseif ($constraint instanceof Tx_Extbase_Persistence_QOM_OrInterface) {
508 $sql['where'][] = '(';
509 $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters);
510 $sql['where'][] = ' OR ';
511 $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters);
512 $sql['where'][] = ')';
513 } elseif ($constraint instanceof Tx_Extbase_Persistence_QOM_NotInterface) {
514 $sql['where'][] = 'NOT (';
515 $this->parseConstraint($constraint->getConstraint(), $source, $sql, $parameters);
516 $sql['where'][] = ')';
517 } elseif ($constraint instanceof Tx_Extbase_Persistence_QOM_ComparisonInterface) {
518 $this->parseComparison($constraint, $source, $sql, $parameters);
519 }
520 }
521
522 /**
523 * Parse a Comparison into SQL and parameter arrays.
524 *
525 * @param Tx_Extbase_Persistence_QOM_ComparisonInterface $comparison The comparison to parse
526 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source
527 * @param array &$sql SQL query parts to add to
528 * @param array &$parameters Parameters to bind to the SQL
529 * @param array $boundVariableValues The bound variables in the query and their values
530 * @return void
531 */
532 protected function parseComparison(Tx_Extbase_Persistence_QOM_ComparisonInterface $comparison, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters) {
533 $operand1 = $comparison->getOperand1();
534 $operator = $comparison->getOperator();
535 $operand2 = $comparison->getOperand2();
536
537 /**
538 * This if enables equals() to behave like in(). Use in() instead.
539 * @deprecated since Extbase 1.3; will be removed in Extbase 1.5
540 */
541 if (($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO) && (is_array($operand2) || ($operand2 instanceof ArrayAccess) || ($operand2 instanceof Traversable))) {
542 $operator = Tx_Extbase_Persistence_QueryInterface::OPERATOR_IN;
543 }
544
545 if ($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_IN) {
546 $items = array();
547 $hasValue = FALSE;
548 foreach ($operand2 as $value) {
549 $value = $this->getPlainValue($value);
550 if ($value !== NULL) {
551 $items[] = $value;
552 $hasValue = TRUE;
553 }
554 }
555 if ($hasValue === FALSE) {
556 $sql['where'][] = '1<>1';
557 } else {
558 $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters, NULL, $operand2);
559 $parameters[] = $items;
560 }
561 } elseif ($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_CONTAINS) {
562 if ($operand2 === NULL) {
563 $sql['where'][] = '1<>1';
564 } else {
565 $className = $source->getNodeTypeName();
566 $tableName = $this->dataMapper->convertClassNameToTableName($className);
567 $propertyName = $operand1->getPropertyName();
568 while (strpos($propertyName, '.') !== FALSE) {
569 $this->addUnionStatement($className, $tableName, $propertyName, $sql);
570 }
571 $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
572 $dataMap = $this->dataMapper->getDataMap($className);
573 $columnMap = $dataMap->getColumnMap($propertyName);
574 $typeOfRelation = ($columnMap instanceof Tx_Extbase_Persistence_Mapper_ColumnMap ? $columnMap->getTypeOfRelation() : NULL);
575 if ($typeOfRelation === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
576 $relationTableName = $columnMap->getRelationTableName();
577 $sql['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=' . $this->getPlainValue($operand2) . ')';
578 } elseif ($typeOfRelation === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
579 $parentKeyFieldName = $columnMap->getParentKeyFieldName();
580 if (isset($parentKeyFieldName)) {
581 $childTableName = $columnMap->getChildTableName();
582 $sql['where'][] = $tableName . '.uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=' . $this->getPlainValue($operand2) . ')';
583 } else {
584 $statement = 'FIND_IN_SET(' . $this->getPlainValue($operand2) . ',' . $tableName . '.' . $columnName . ')';
585 $sql['where'][] = $statement;
586 }
587 } else {
588 throw new Tx_Extbase_Persistence_Exception_RepositoryException(
589 'Unsupported or non-existing property name "' . $propertyName . '" used in relation matching.',
590 1327065745
591 );
592 }
593 }
594 } else {
595 if ($operand2 === NULL) {
596 if ($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO) {
597 $operator = self::OPERATOR_EQUAL_TO_NULL;
598 } elseif ($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_NOT_EQUAL_TO) {
599 $operator = self::OPERATOR_NOT_EQUAL_TO_NULL;
600 }
601 }
602 $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters);
603 $parameters[] = $this->getPlainValue($operand2);
604 }
605 }
606
607 /**
608 * Returns a plain value, i.e. objects are flattened out if possible.
609 *
610 * @param mixed $input
611 * @return mixed
612 */
613 protected function getPlainValue($input) {
614 if (is_array($input)) {
615 throw new Tx_Extbase_Persistence_Exception_UnexpectedTypeException('An array could not be converted to a plain value.', 1274799932);
616 }
617 if ($input instanceof DateTime) {
618 return $input->format('U');
619 } elseif (is_object($input)) {
620 if ($input instanceof Tx_Extbase_DomainObject_DomainObjectInterface) {
621 return $input->getUid();
622 } else {
623 throw new Tx_Extbase_Persistence_Exception_UnexpectedTypeException('An object of class "' . get_class($input) . '" could not be converted to a plain value.', 1274799934);
624 }
625 } elseif (is_bool($input)) {
626 return $input === TRUE ? 1 : 0;
627 } else {
628 return $input;
629 }
630 }
631
632 /**
633 * Parse a DynamicOperand into SQL and parameter arrays.
634 *
635 * @param Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand
636 * @param string $operator One of the JCR_OPERATOR_* constants
637 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source
638 * @param array &$sql The query parts
639 * @param array &$parameters The parameters that will replace the markers
640 * @param string $valueFunction an optional SQL function to apply to the operand value
641 * @return void
642 */
643 protected function parseDynamicOperand(Tx_Extbase_Persistence_QOM_DynamicOperandInterface $operand, $operator, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql, array &$parameters, $valueFunction = NULL, $operand2 = NULL) {
644 if ($operand instanceof Tx_Extbase_Persistence_QOM_LowerCaseInterface) {
645 $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'LOWER');
646 } elseif ($operand instanceof Tx_Extbase_Persistence_QOM_UpperCaseInterface) {
647 $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'UPPER');
648 } elseif ($operand instanceof Tx_Extbase_Persistence_QOM_PropertyValueInterface) {
649 $propertyName = $operand->getPropertyName();
650 if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) { // FIXME Only necessary to differ from Join
651 $className = $source->getNodeTypeName();
652 $tableName = $this->dataMapper->convertClassNameToTableName($className);
653 while (strpos($propertyName, '.') !== FALSE) {
654 $this->addUnionStatement($className, $tableName, $propertyName, $sql);
655 }
656 } elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
657 $tableName = $source->getJoinCondition()->getSelector1Name();
658 }
659 $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
660 $operator = $this->resolveOperator($operator);
661
662 $constraintSQL = '';
663 if ($valueFunction === NULL) {
664 $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $operator . ' ?';
665 } else {
666 $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $operator . ' ?';
667 }
668
669 $sql['where'][] = $constraintSQL;
670 }
671 }
672
673 protected function addUnionStatement(&$className, &$tableName, &$propertyPath, array &$sql) {
674 $explodedPropertyPath = explode('.', $propertyPath, 2);
675 $propertyName = $explodedPropertyPath[0];
676 $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
677 $tableName = $this->dataMapper->convertClassNameToTableName($className);
678 $columnMap = $this->dataMapper->getDataMap($className)->getColumnMap($propertyName);
679 $parentKeyFieldName = $columnMap->getParentKeyFieldName();
680 $childTableName = $columnMap->getChildTableName();
681 if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_ONE) {
682 if (isset($parentKeyFieldName)) {
683 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
684 } else {
685 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $columnName . '=' . $childTableName . '.uid';
686 }
687 $className = $this->dataMapper->getType($className, $propertyName);
688 } elseif ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
689 if (isset($parentKeyFieldName)) {
690 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
691 } else {
692 $onStatement = '(FIND_IN_SET(' . $childTableName . '.uid, ' . $tableName . '.' . $columnName . '))';
693 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $onStatement;
694 }
695 $className = $this->dataMapper->getType($className, $propertyName);
696 } elseif ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
697 $relationTableName = $columnMap->getRelationTableName();
698 $sql['unions'][$relationTableName] = 'LEFT JOIN ' . $relationTableName . ' ON ' . $tableName . '.uid=' . $relationTableName . '.' . $columnMap->getParentKeyFieldName();
699 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $relationTableName . '.'. $columnMap->getChildKeyFieldName() . '=' . $childTableName . '.uid';
700 $className = $this->dataMapper->getType($className, $propertyName);
701 } else {
702 throw new Tx_Extbase_Persistence_Exception('Could not determine type of relation.', 1252502725);
703 }
704 // TODO check if there is another solution for this
705 $sql['keywords']['distinct'] = 'DISTINCT';
706 $propertyPath = $explodedPropertyPath[1];
707 $tableName = $childTableName;
708 }
709
710 /**
711 * Returns the SQL operator for the given JCR operator type.
712 *
713 * @param string $operator One of the JCR_OPERATOR_* constants
714 * @return string an SQL operator
715 */
716 protected function resolveOperator($operator) {
717 switch ($operator) {
718 case self::OPERATOR_EQUAL_TO_NULL:
719 $operator = 'IS';
720 break;
721 case self::OPERATOR_NOT_EQUAL_TO_NULL:
722 $operator = 'IS NOT';
723 break;
724 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_IN:
725 $operator = 'IN';
726 break;
727 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO:
728 $operator = '=';
729 break;
730 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_NOT_EQUAL_TO:
731 $operator = '!=';
732 break;
733 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN:
734 $operator = '<';
735 break;
736 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO:
737 $operator = '<=';
738 break;
739 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN:
740 $operator = '>';
741 break;
742 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO:
743 $operator = '>=';
744 break;
745 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_LIKE:
746 $operator = 'LIKE';
747 break;
748 default:
749 throw new Tx_Extbase_Persistence_Exception('Unsupported operator encountered.', 1242816073);
750 }
751
752 return $operator;
753 }
754
755 /**
756 * Replace query placeholders in a query part by the given
757 * parameters.
758 *
759 * @param string $sqlString The query part with placeholders
760 * @param array $parameters The parameters
761 * @return string The query part with replaced placeholders
762 */
763 protected function replacePlaceholders(&$sqlString, array $parameters) {
764 // TODO profile this method again
765 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);
766 $offset = 0;
767 foreach ($parameters as $parameter) {
768 $markPosition = strpos($sqlString, '?', $offset);
769 if ($markPosition !== FALSE) {
770 if ($parameter === NULL) {
771 $parameter = 'NULL';
772 } elseif (is_array($parameter) || ($parameter instanceof ArrayAccess) || ($parameter instanceof Traversable)) {
773 $items = array();
774 foreach ($parameter as $item) {
775 $items[] = $this->databaseHandle->fullQuoteStr($item, 'foo');
776 }
777 $parameter = '(' . implode(',', $items) . ')';
778 } else {
779 $parameter = $this->databaseHandle->fullQuoteStr($parameter, 'foo'); // FIXME This may not work with DBAL; check this
780 }
781 $sqlString = substr($sqlString, 0, $markPosition) . $parameter . substr($sqlString, $markPosition + 1);
782 }
783 $offset = $markPosition + strlen($parameter);
784 }
785 }
786
787 /**
788 * Adds additional WHERE statements according to the query settings.
789 *
790 * @param Tx_Extbase_Persistence_QuerySettingsInterface $querySettings The TYPO3 4.x specific query settings
791 * @param string $tableName The table name to add the additional where clause for
792 * @param string $sql
793 * @return void
794 */
795 protected function addAdditionalWhereClause(Tx_Extbase_Persistence_QuerySettingsInterface $querySettings, $tableName, &$sql) {
796 if ($querySettings->getRespectEnableFields()) {
797 $this->addEnableFieldsStatement($tableName, $sql);
798 }
799 if ($querySettings->getRespectSysLanguage()) {
800 $this->addSysLanguageStatement($tableName, $sql);
801 }
802 if ($querySettings->getRespectStoragePage()) {
803 $this->addPageIdStatement($tableName, $sql, $querySettings->getStoragePageIds());
804 }
805 }
806
807 /**
808 * Builds the enable fields statement
809 *
810 * @param string $tableName The database table name
811 * @param array &$sql The query parts
812 * @return void
813 */
814 protected function addEnableFieldsStatement($tableName, array &$sql) {
815 if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
816 if (TYPO3_MODE === 'FE') {
817 $statement = $GLOBALS['TSFE']->sys_page->enableFields($tableName);
818 } else { // TYPO3_MODE === 'BE'
819 $statement = t3lib_BEfunc::deleteClause($tableName);
820 $statement .= t3lib_BEfunc::BEenableFields($tableName);
821 }
822 if(!empty($statement)) {
823 $statement = substr($statement, 5);
824 $sql['additionalWhereClause'][] = $statement;
825 }
826 }
827 }
828
829 /**
830 * Builds the language field statement
831 *
832 * @param string $tableName The database table name
833 * @param array &$sql The query parts
834 * @return void
835 */
836 protected function addSysLanguageStatement($tableName, array &$sql) {
837 if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
838 if(isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== NULL) {
839 $sql['additionalWhereClause'][] = $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (0,-1)';
840 }
841 }
842 }
843
844 /**
845 * Builds the page ID checking statement
846 *
847 * @param string $tableName The database table name
848 * @param array &$sql The query parts
849 * @param array $storagePageIds list of storage page ids
850 * @return void
851 */
852 protected function addPageIdStatement($tableName, array &$sql, array $storagePageIds) {
853 if (empty($this->tableInformationCache[$tableName]['columnNames'])) {
854 $this->tableInformationCache[$tableName]['columnNames'] = $this->databaseHandle->admin_get_fields($tableName);
855 }
856 if (is_array($GLOBALS['TCA'][$tableName]['ctrl']) && array_key_exists('pid', $this->tableInformationCache[$tableName]['columnNames'])) {
857 $sql['additionalWhereClause'][] = $tableName . '.pid IN (' . implode(', ', $storagePageIds) . ')';
858 }
859 }
860
861 /**
862 * Transforms orderings into SQL.
863 *
864 * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering)
865 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source
866 * @param array &$sql The query parts
867 * @return void
868 */
869 protected function parseOrderings(array $orderings, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql) {
870 foreach ($orderings as $propertyName => $order) {
871 switch ($order) {
872 case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING: // Deprecated since Extbase 1.1
873 case Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING:
874 $order = 'ASC';
875 break;
876 case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING: // Deprecated since Extbase 1.1
877 case Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING:
878 $order = 'DESC';
879 break;
880 default:
881 throw new Tx_Extbase_Persistence_Exception_UnsupportedOrder('Unsupported order encountered.', 1242816074);
882 }
883 if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
884 $className = $source->getNodeTypeName();
885 $tableName = $this->dataMapper->convertClassNameToTableName($className);
886 while (strpos($propertyName, '.') !== FALSE) {
887 $this->addUnionStatement($className, $tableName, $propertyName, $sql);
888 }
889 } elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
890 $tableName = $source->getLeft()->getSelectorName();
891 }
892 $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
893 if (strlen($tableName) > 0) {
894 $sql['orderings'][] = $tableName . '.' . $columnName . ' ' . $order;
895 } else {
896 $sql['orderings'][] = $columnName . ' ' . $order;
897 }
898 }
899 }
900
901 /**
902 * Transforms limit and offset into SQL
903 *
904 * @param int $limit
905 * @param int $offset
906 * @param array &$sql
907 * @return void
908 */
909 protected function parseLimitAndOffset($limit, $offset, array &$sql) {
910 if ($limit !== NULL && $offset !== NULL) {
911 $sql['limit'] = $offset . ', ' . $limit;
912 } elseif ($limit !== NULL) {
913 $sql['limit'] = $limit;
914 }
915 }
916
917 /**
918 * Transforms a Resource from a database query to an array of rows.
919 *
920 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source (selector od join)
921 * @param resource $result The result
922 * @return array The result as an array of rows (tuples)
923 */
924 protected function getRowsFromResult(Tx_Extbase_Persistence_QOM_SourceInterface $source, $result) {
925 $rows = array();
926 while ($row = $this->databaseHandle->sql_fetch_assoc($result)) {
927 if (is_array($row)) {
928 // TODO Check if this is necessary, maybe the last line is enough
929 $arrayKeys = range(0, count($row));
930 array_fill_keys($arrayKeys, $row);
931 $rows[] = $row;
932 }
933 }
934 return $rows;
935 }
936
937 /**
938 * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
939 * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
940 *
941 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source (selector od join)
942 * @param array $row The row array (as reference)
943 * @param string $languageUid The language id
944 * @param string $workspaceUidUid The workspace id
945 * @return void
946 */
947 protected function doLanguageAndWorkspaceOverlay(Tx_Extbase_Persistence_QOM_SourceInterface $source, array $rows, $languageUid = NULL, $workspaceUid = NULL) {
948 $overlayedRows = array();
949 foreach ($rows as $row) {
950 if (!($this->pageSelectObject instanceof t3lib_pageSelect)) {
951 if (TYPO3_MODE == 'FE') {
952 if (is_object($GLOBALS['TSFE'])) {
953 $this->pageSelectObject = $GLOBALS['TSFE']->sys_page;
954 } else {
955 $this->pageSelectObject = t3lib_div::makeInstance('t3lib_pageSelect');
956 }
957 } else {
958 $this->pageSelectObject = t3lib_div::makeInstance( 't3lib_pageSelect' );
959 }
960 }
961 if (is_object($GLOBALS['TSFE'])) {
962 if ($languageUid === NULL) {
963 // get the language UID of the content that should be output
964 $languageUid = $GLOBALS['TSFE']->sys_language_content;
965 $languageMode = $GLOBALS['TSFE']->sys_language_mode;
966 }
967 if ($workspaceUid !== NULL) {
968 $this->pageSelectObject->versioningWorkspaceId = $workspaceUid;
969 }
970 } else {
971 if ($languageUid === NULL) {
972 $languageUid = intval(t3lib_div::_GP('L'));
973 }
974 if ($workspaceUid === NULL) {
975 $workspaceUid = $GLOBALS['BE_USER']->workspace;
976 }
977 $this->pageSelectObject->versioningWorkspaceId = $workspaceUid;
978 }
979 if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
980 $tableName = $source->getSelectorName();
981 } elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
982 $tableName = $source->getRight()->getSelectorName();
983 }
984 $this->pageSelectObject->versionOL($tableName, $row, TRUE);
985 if ($this->pageSelectObject->versioningPreview && isset($row['_ORIG_uid'])) {
986 $row['uid'] = $row['_ORIG_uid'];
987 }
988 if($tableName == 'pages') {
989 $row = $this->pageSelectObject->getPageOverlay($row, $languageUid);
990 } elseif(isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '') {
991 if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1,0))) {
992 $overlayMode = ($languageMode === 'strict') ? 'hideNonTranslated' : '';
993 $row = $this->pageSelectObject->getRecordOverlay($tableName, $row, $languageUid, $overlayMode);
994 }
995 }
996 if ($row !== NULL && is_array($row)) {
997 $overlayedRows[] = $row;
998 }
999 }
1000 return $overlayedRows;
1001 }
1002
1003 /**
1004 * Checks if there are SQL errors in the last query, and if yes, throw an exception.
1005 *
1006 * @return void
1007 * @param string $sql The SQL statement
1008 * @throws Tx_Extbase_Persistence_Storage_Exception_SqlError
1009 */
1010 protected function checkSqlErrors($sql='') {
1011 $error = $this->databaseHandle->sql_error();
1012 if ($error !== '') {
1013 $error .= $sql ? ': ' . $sql : '';
1014 throw new Tx_Extbase_Persistence_Storage_Exception_SqlError($error, 1247602160);
1015 }
1016 }
1017
1018 /**
1019 * Clear the TYPO3 page cache for the given record.
1020 * If the record lies on a page, then we clear the cache of this page.
1021 * If the record has no PID column, we clear the cache of the current page as best-effort.
1022 *
1023 * Much of this functionality is taken from t3lib_tcemain::clear_cache() which unfortunately only works with logged-in BE user.
1024 *
1025 * @param $tableName Table name of the record
1026 * @param $uid UID of the record
1027 * @return void
1028 */
1029 protected function clearPageCache($tableName, $uid) {
1030 $frameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
1031 if (isset($frameworkConfiguration['persistence']['enableAutomaticCacheClearing']) && $frameworkConfiguration['persistence']['enableAutomaticCacheClearing'] === '1') {
1032 } else {
1033 // if disabled, return
1034 return;
1035 }
1036
1037 $pageIdsToClear = array();
1038 $storagePage = NULL;
1039
1040 $columns = $this->databaseHandle->admin_get_fields($tableName);
1041 if (array_key_exists('pid', $columns)) {
1042 $result = $this->databaseHandle->exec_SELECTquery('pid', $tableName, 'uid='.intval($uid));
1043 if ($row = $this->databaseHandle->sql_fetch_assoc($result)) {
1044 $storagePage = $row['pid'];
1045 $pageIdsToClear[] = $storagePage;
1046 }
1047 } elseif (isset($GLOBALS['TSFE'])) {
1048 // No PID column - we can do a best-effort to clear the cache of the current page if in FE
1049 $storagePage = $GLOBALS['TSFE']->id;
1050 $pageIdsToClear[] = $storagePage;
1051 }
1052
1053 if ($storagePage === NULL) {
1054 return;
1055 }
1056 if (!isset($this->pageTSConfigCache[$storagePage])) {
1057 $this->pageTSConfigCache[$storagePage] = t3lib_BEfunc::getPagesTSconfig($storagePage);
1058 }
1059 if (isset($this->pageTSConfigCache[$storagePage]['TCEMAIN.']['clearCacheCmd'])) {
1060 $clearCacheCommands = t3lib_div::trimExplode(',',strtolower($this->pageTSConfigCache[$storagePage]['TCEMAIN.']['clearCacheCmd']),1);
1061 $clearCacheCommands = array_unique($clearCacheCommands);
1062 foreach ($clearCacheCommands as $clearCacheCommand) {
1063 if (t3lib_utility_Math::canBeInterpretedAsInteger($clearCacheCommand)) {
1064 $pageIdsToClear[] = $clearCacheCommand;
1065 }
1066 }
1067 }
1068
1069 // 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
1070 $this->cacheService->clearPageCache($pageIdsToClear);
1071 }
1072 }
1073
1074 ?>