badaebe24d0d145d1e6bb3e91cfa5d72537d093f
[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 if ($valueFunction === NULL) {
662 $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $operator . ' ?';
663 } else {
664 $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $operator . ' ?';
665 }
666
667 $sql['where'][] = $constraintSQL;
668 }
669 }
670
671 protected function addUnionStatement(&$className, &$tableName, &$propertyPath, array &$sql) {
672 $explodedPropertyPath = explode('.', $propertyPath, 2);
673 $propertyName = $explodedPropertyPath[0];
674 $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
675 $tableName = $this->dataMapper->convertClassNameToTableName($className);
676 $columnMap = $this->dataMapper->getDataMap($className)->getColumnMap($propertyName);
677 $parentKeyFieldName = $columnMap->getParentKeyFieldName();
678 $childTableName = $columnMap->getChildTableName();
679 if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_ONE) {
680 if (isset($parentKeyFieldName)) {
681 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
682 } else {
683 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $columnName . '=' . $childTableName . '.uid';
684 }
685 $className = $this->dataMapper->getType($className, $propertyName);
686 } elseif ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
687 if (isset($parentKeyFieldName)) {
688 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
689 } else {
690 $onStatement = '(FIND_IN_SET(' . $childTableName . '.uid, ' . $tableName . '.' . $columnName . '))';
691 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $onStatement;
692 }
693 $className = $this->dataMapper->getType($className, $propertyName);
694 } elseif ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
695 $relationTableName = $columnMap->getRelationTableName();
696 $sql['unions'][$relationTableName] = 'LEFT JOIN ' . $relationTableName . ' ON ' . $tableName . '.uid=' . $relationTableName . '.' . $columnMap->getParentKeyFieldName();
697 $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $relationTableName . '.'. $columnMap->getChildKeyFieldName() . '=' . $childTableName . '.uid';
698 $className = $this->dataMapper->getType($className, $propertyName);
699 } else {
700 throw new Tx_Extbase_Persistence_Exception('Could not determine type of relation.', 1252502725);
701 }
702 // TODO check if there is another solution for this
703 $sql['keywords']['distinct'] = 'DISTINCT';
704 $propertyPath = $explodedPropertyPath[1];
705 $tableName = $childTableName;
706 }
707
708 /**
709 * Returns the SQL operator for the given JCR operator type.
710 *
711 * @param string $operator One of the JCR_OPERATOR_* constants
712 * @return string an SQL operator
713 */
714 protected function resolveOperator($operator) {
715 switch ($operator) {
716 case self::OPERATOR_EQUAL_TO_NULL:
717 $operator = 'IS';
718 break;
719 case self::OPERATOR_NOT_EQUAL_TO_NULL:
720 $operator = 'IS NOT';
721 break;
722 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_IN:
723 $operator = 'IN';
724 break;
725 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_EQUAL_TO:
726 $operator = '=';
727 break;
728 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_NOT_EQUAL_TO:
729 $operator = '!=';
730 break;
731 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN:
732 $operator = '<';
733 break;
734 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO:
735 $operator = '<=';
736 break;
737 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN:
738 $operator = '>';
739 break;
740 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO:
741 $operator = '>=';
742 break;
743 case Tx_Extbase_Persistence_QueryInterface::OPERATOR_LIKE:
744 $operator = 'LIKE';
745 break;
746 default:
747 throw new Tx_Extbase_Persistence_Exception('Unsupported operator encountered.', 1242816073);
748 }
749
750 return $operator;
751 }
752
753 /**
754 * Replace query placeholders in a query part by the given
755 * parameters.
756 *
757 * @param string $sqlString The query part with placeholders
758 * @param array $parameters The parameters
759 * @return string The query part with replaced placeholders
760 */
761 protected function replacePlaceholders(&$sqlString, array $parameters) {
762 // TODO profile this method again
763 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);
764 $offset = 0;
765 foreach ($parameters as $parameter) {
766 $markPosition = strpos($sqlString, '?', $offset);
767 if ($markPosition !== FALSE) {
768 if ($parameter === NULL) {
769 $parameter = 'NULL';
770 } elseif (is_array($parameter) || ($parameter instanceof ArrayAccess) || ($parameter instanceof Traversable)) {
771 $items = array();
772 foreach ($parameter as $item) {
773 $items[] = $this->databaseHandle->fullQuoteStr($item, 'foo');
774 }
775 $parameter = '(' . implode(',', $items) . ')';
776 } else {
777 $parameter = $this->databaseHandle->fullQuoteStr($parameter, 'foo'); // FIXME This may not work with DBAL; check this
778 }
779 $sqlString = substr($sqlString, 0, $markPosition) . $parameter . substr($sqlString, $markPosition + 1);
780 }
781 $offset = $markPosition + strlen($parameter);
782 }
783 }
784
785 /**
786 * Adds additional WHERE statements according to the query settings.
787 *
788 * @param Tx_Extbase_Persistence_QuerySettingsInterface $querySettings The TYPO3 4.x specific query settings
789 * @param string $tableName The table name to add the additional where clause for
790 * @param string $sql
791 * @return void
792 */
793 protected function addAdditionalWhereClause(Tx_Extbase_Persistence_QuerySettingsInterface $querySettings, $tableName, &$sql) {
794 if ($querySettings->getRespectEnableFields()) {
795 $this->addEnableFieldsStatement($tableName, $sql);
796 }
797 if ($querySettings->getRespectSysLanguage()) {
798 $this->addSysLanguageStatement($tableName, $sql);
799 }
800 if ($querySettings->getRespectStoragePage()) {
801 $this->addPageIdStatement($tableName, $sql, $querySettings->getStoragePageIds());
802 }
803 }
804
805 /**
806 * Builds the enable fields statement
807 *
808 * @param string $tableName The database table name
809 * @param array &$sql The query parts
810 * @return void
811 */
812 protected function addEnableFieldsStatement($tableName, array &$sql) {
813 if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
814 if (TYPO3_MODE === 'FE') {
815 $statement = $GLOBALS['TSFE']->sys_page->enableFields($tableName);
816 } else { // TYPO3_MODE === 'BE'
817 $statement = t3lib_BEfunc::deleteClause($tableName);
818 $statement .= t3lib_BEfunc::BEenableFields($tableName);
819 }
820 if(!empty($statement)) {
821 $statement = substr($statement, 5);
822 $sql['additionalWhereClause'][] = $statement;
823 }
824 }
825 }
826
827 /**
828 * Builds the language field statement
829 *
830 * @param string $tableName The database table name
831 * @param array &$sql The query parts
832 * @return void
833 */
834 protected function addSysLanguageStatement($tableName, array &$sql) {
835 if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
836 if(isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== NULL) {
837 $sql['additionalWhereClause'][] = $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (0,-1)';
838 }
839 }
840 }
841
842 /**
843 * Builds the page ID checking statement
844 *
845 * @param string $tableName The database table name
846 * @param array &$sql The query parts
847 * @param array $storagePageIds list of storage page ids
848 * @return void
849 */
850 protected function addPageIdStatement($tableName, array &$sql, array $storagePageIds) {
851 if (empty($this->tableInformationCache[$tableName]['columnNames'])) {
852 $this->tableInformationCache[$tableName]['columnNames'] = $this->databaseHandle->admin_get_fields($tableName);
853 }
854 if (is_array($GLOBALS['TCA'][$tableName]['ctrl']) && array_key_exists('pid', $this->tableInformationCache[$tableName]['columnNames'])) {
855 $sql['additionalWhereClause'][] = $tableName . '.pid IN (' . implode(', ', $storagePageIds) . ')';
856 }
857 }
858
859 /**
860 * Transforms orderings into SQL.
861 *
862 * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering)
863 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source
864 * @param array &$sql The query parts
865 * @return void
866 */
867 protected function parseOrderings(array $orderings, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql) {
868 foreach ($orderings as $propertyName => $order) {
869 switch ($order) {
870 case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING: // Deprecated since Extbase 1.1
871 case Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING:
872 $order = 'ASC';
873 break;
874 case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING: // Deprecated since Extbase 1.1
875 case Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING:
876 $order = 'DESC';
877 break;
878 default:
879 throw new Tx_Extbase_Persistence_Exception_UnsupportedOrder('Unsupported order encountered.', 1242816074);
880 }
881 if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
882 $className = $source->getNodeTypeName();
883 $tableName = $this->dataMapper->convertClassNameToTableName($className);
884 while (strpos($propertyName, '.') !== FALSE) {
885 $this->addUnionStatement($className, $tableName, $propertyName, $sql);
886 }
887 } elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
888 $tableName = $source->getLeft()->getSelectorName();
889 }
890 $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
891 if (strlen($tableName) > 0) {
892 $sql['orderings'][] = $tableName . '.' . $columnName . ' ' . $order;
893 } else {
894 $sql['orderings'][] = $columnName . ' ' . $order;
895 }
896 }
897 }
898
899 /**
900 * Transforms limit and offset into SQL
901 *
902 * @param int $limit
903 * @param int $offset
904 * @param array &$sql
905 * @return void
906 */
907 protected function parseLimitAndOffset($limit, $offset, array &$sql) {
908 if ($limit !== NULL && $offset !== NULL) {
909 $sql['limit'] = $offset . ', ' . $limit;
910 } elseif ($limit !== NULL) {
911 $sql['limit'] = $limit;
912 }
913 }
914
915 /**
916 * Transforms a Resource from a database query to an array of rows.
917 *
918 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source (selector od join)
919 * @param resource $result The result
920 * @return array The result as an array of rows (tuples)
921 */
922 protected function getRowsFromResult(Tx_Extbase_Persistence_QOM_SourceInterface $source, $result) {
923 $rows = array();
924 while ($row = $this->databaseHandle->sql_fetch_assoc($result)) {
925 if (is_array($row)) {
926 // TODO Check if this is necessary, maybe the last line is enough
927 $arrayKeys = range(0, count($row));
928 array_fill_keys($arrayKeys, $row);
929 $rows[] = $row;
930 }
931 }
932 return $rows;
933 }
934
935 /**
936 * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
937 * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
938 *
939 * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source (selector od join)
940 * @param array $row The row array (as reference)
941 * @param string $languageUid The language id
942 * @param string $workspaceUidUid The workspace id
943 * @return void
944 */
945 protected function doLanguageAndWorkspaceOverlay(Tx_Extbase_Persistence_QOM_SourceInterface $source, array $rows, $languageUid = NULL, $workspaceUid = NULL) {
946 $overlayedRows = array();
947 foreach ($rows as $row) {
948 if (!($this->pageSelectObject instanceof t3lib_pageSelect)) {
949 if (TYPO3_MODE == 'FE') {
950 if (is_object($GLOBALS['TSFE'])) {
951 $this->pageSelectObject = $GLOBALS['TSFE']->sys_page;
952 } else {
953 $this->pageSelectObject = t3lib_div::makeInstance('t3lib_pageSelect');
954 }
955 } else {
956 $this->pageSelectObject = t3lib_div::makeInstance( 't3lib_pageSelect' );
957 }
958 }
959 if (is_object($GLOBALS['TSFE'])) {
960 if ($languageUid === NULL) {
961 // get the language UID of the content that should be output
962 $languageUid = $GLOBALS['TSFE']->sys_language_content;
963 $languageMode = $GLOBALS['TSFE']->sys_language_mode;
964 }
965 if ($workspaceUid !== NULL) {
966 $this->pageSelectObject->versioningWorkspaceId = $workspaceUid;
967 }
968 } else {
969 if ($languageUid === NULL) {
970 $languageUid = intval(t3lib_div::_GP('L'));
971 }
972 if ($workspaceUid === NULL) {
973 $workspaceUid = $GLOBALS['BE_USER']->workspace;
974 }
975 $this->pageSelectObject->versioningWorkspaceId = $workspaceUid;
976 }
977 if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
978 $tableName = $source->getSelectorName();
979 } elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) {
980 $tableName = $source->getRight()->getSelectorName();
981 }
982 $this->pageSelectObject->versionOL($tableName, $row, TRUE);
983 if ($this->pageSelectObject->versioningPreview && isset($row['_ORIG_uid'])) {
984 $row['uid'] = $row['_ORIG_uid'];
985 }
986 if($tableName == 'pages') {
987 $row = $this->pageSelectObject->getPageOverlay($row, $languageUid);
988 } elseif(isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '') {
989 if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1,0))) {
990 $overlayMode = ($languageMode === 'strict') ? 'hideNonTranslated' : '';
991 $row = $this->pageSelectObject->getRecordOverlay($tableName, $row, $languageUid, $overlayMode);
992 }
993 }
994 if ($row !== NULL && is_array($row)) {
995 $overlayedRows[] = $row;
996 }
997 }
998 return $overlayedRows;
999 }
1000
1001 /**
1002 * Checks if there are SQL errors in the last query, and if yes, throw an exception.
1003 *
1004 * @return void
1005 * @param string $sql The SQL statement
1006 * @throws Tx_Extbase_Persistence_Storage_Exception_SqlError
1007 */
1008 protected function checkSqlErrors($sql='') {
1009 $error = $this->databaseHandle->sql_error();
1010 if ($error !== '') {
1011 $error .= $sql ? ': ' . $sql : '';
1012 throw new Tx_Extbase_Persistence_Storage_Exception_SqlError($error, 1247602160);
1013 }
1014 }
1015
1016 /**
1017 * Clear the TYPO3 page cache for the given record.
1018 * If the record lies on a page, then we clear the cache of this page.
1019 * If the record has no PID column, we clear the cache of the current page as best-effort.
1020 *
1021 * Much of this functionality is taken from t3lib_tcemain::clear_cache() which unfortunately only works with logged-in BE user.
1022 *
1023 * @param $tableName Table name of the record
1024 * @param $uid UID of the record
1025 * @return void
1026 */
1027 protected function clearPageCache($tableName, $uid) {
1028 $frameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
1029 if (isset($frameworkConfiguration['persistence']['enableAutomaticCacheClearing']) && $frameworkConfiguration['persistence']['enableAutomaticCacheClearing'] === '1') {
1030 } else {
1031 // if disabled, return
1032 return;
1033 }
1034
1035 $pageIdsToClear = array();
1036 $storagePage = NULL;
1037
1038 $columns = $this->databaseHandle->admin_get_fields($tableName);
1039 if (array_key_exists('pid', $columns)) {
1040 $result = $this->databaseHandle->exec_SELECTquery('pid', $tableName, 'uid='.intval($uid));
1041 if ($row = $this->databaseHandle->sql_fetch_assoc($result)) {
1042 $storagePage = $row['pid'];
1043 $pageIdsToClear[] = $storagePage;
1044 }
1045 } elseif (isset($GLOBALS['TSFE'])) {
1046 // No PID column - we can do a best-effort to clear the cache of the current page if in FE
1047 $storagePage = $GLOBALS['TSFE']->id;
1048 $pageIdsToClear[] = $storagePage;
1049 }
1050
1051 if ($storagePage === NULL) {
1052 return;
1053 }
1054 if (!isset($this->pageTSConfigCache[$storagePage])) {
1055 $this->pageTSConfigCache[$storagePage] = t3lib_BEfunc::getPagesTSconfig($storagePage);
1056 }
1057 if (isset($this->pageTSConfigCache[$storagePage]['TCEMAIN.']['clearCacheCmd'])) {
1058 $clearCacheCommands = t3lib_div::trimExplode(',',strtolower($this->pageTSConfigCache[$storagePage]['TCEMAIN.']['clearCacheCmd']),1);
1059 $clearCacheCommands = array_unique($clearCacheCommands);
1060 foreach ($clearCacheCommands as $clearCacheCommand) {
1061 if (t3lib_utility_Math::canBeInterpretedAsInteger($clearCacheCommand)) {
1062 $pageIdsToClear[] = $clearCacheCommand;
1063 }
1064 }
1065 }
1066
1067 // 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
1068 $this->cacheService->clearPageCache($pageIdsToClear);
1069 }
1070 }
1071
1072 ?>