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