TYPO3 CMS  TYPO3_6-2
Typo3DbBackend.php
Go to the documentation of this file.
1 <?php
3 
20 
25 
31  protected $databaseHandle;
32 
37  protected $dataMapper;
38 
44  protected $pageRepository;
45 
51  protected $pageTSConfigCache = array();
52 
58 
63  protected $cacheService;
64 
69  protected $cacheManager;
70 
74  protected $tableColumnCache;
75 
79  protected $queryCache;
80 
86 
91  protected $queryParser;
92 
98  protected $queryRuntimeCache = array();
99 
103  public function __construct() {
104  $this->databaseHandle = $GLOBALS['TYPO3_DB'];
105  }
106 
112  public function initializeObject() {
113  $this->tableColumnCache = $this->cacheManager->getCache('extbase_typo3dbbackend_tablecolumns');
114  $this->queryCache = $this->cacheManager->getCache('extbase_typo3dbbackend_queries');
115  }
116 
125  public function addRow($tableName, array $fieldValues, $isRelation = FALSE) {
126  if (isset($fieldValues['uid'])) {
127  unset($fieldValues['uid']);
128  }
129 
130  $this->databaseHandle->exec_INSERTquery($tableName, $fieldValues);
131  $this->checkSqlErrors();
132  $uid = $this->databaseHandle->sql_insert_id();
133 
134  if (!$isRelation) {
135  $this->clearPageCache($tableName, $uid);
136  }
137  return (int)$uid;
138  }
139 
149  public function updateRow($tableName, array $fieldValues, $isRelation = FALSE) {
150  if (!isset($fieldValues['uid'])) {
151  throw new \InvalidArgumentException('The given row must contain a value for "uid".');
152  }
153 
154  $uid = (int)$fieldValues['uid'];
155  unset($fieldValues['uid']);
156 
157  $updateSuccessful = $this->databaseHandle->exec_UPDATEquery($tableName, 'uid = '. $uid, $fieldValues);
158  $this->checkSqlErrors();
159 
160  if (!$isRelation) {
161  $this->clearPageCache($tableName, $uid);
162  }
163 
164  return $updateSuccessful;
165  }
166 
175  public function updateRelationTableRow($tableName, array $fieldValues) {
176  if (!isset($fieldValues['uid_local']) && !isset($fieldValues['uid_foreign'])) {
177  throw new \InvalidArgumentException(
178  'The given fieldValues must contain a value for "uid_local" and "uid_foreign".', 1360500126
179  );
180  }
181 
182  $where['uid_local'] = (int)$fieldValues['uid_local'];
183  $where['uid_foreign'] = (int)$fieldValues['uid_foreign'];
184  unset($fieldValues['uid_local']);
185  unset($fieldValues['uid_foreign']);
186 
187  if (!empty($fieldValues['tablenames'])) {
188  $where['tablenames'] = $fieldValues['tablenames'];
189  unset($fieldValues['tablenames']);
190  }
191  if (!empty($fieldValues['fieldname'])) {
192  $where['fieldname'] = $fieldValues['fieldname'];
193  unset($fieldValues['fieldname']);
194  }
195 
196  $updateSuccessful = $this->databaseHandle->exec_UPDATEquery(
197  $tableName,
198  $this->resolveWhereStatement($where, $tableName),
199  $fieldValues
200  );
201  $this->checkSqlErrors();
202 
203  return $updateSuccessful;
204  }
205 
214  public function removeRow($tableName, array $where, $isRelation = FALSE) {
215  $deleteSuccessful = $this->databaseHandle->exec_DELETEquery(
216  $tableName,
217  $this->resolveWhereStatement($where, $tableName)
218  );
219  $this->checkSqlErrors();
220 
221  if (!$isRelation && isset($where['uid'])) {
222  $this->clearPageCache($tableName, $where['uid']);
223  }
224 
225  return $deleteSuccessful;
226  }
227 
236  public function getMaxValueFromTable($tableName, array $where, $columnName) {
237  $result = $this->databaseHandle->exec_SELECTgetSingleRow(
238  $columnName,
239  $tableName,
240  $this->resolveWhereStatement($where, $tableName),
241  '',
242  $columnName . ' DESC',
243  TRUE
244  );
245  $this->checkSqlErrors();
246 
247  return $result[0];
248  }
249 
257  public function getRowByIdentifier($tableName, array $where) {
258  $row = $this->databaseHandle->exec_SELECTgetSingleRow(
259  '*',
260  $tableName,
261  $this->resolveWhereStatement($where, $tableName)
262  );
263  $this->checkSqlErrors();
264 
265  return $row ?: FALSE;
266  }
267 
276  protected function resolveWhereStatement(array $where, $tableName = 'foo') {
277  $whereStatement = array();
278 
279  foreach ($where as $fieldName => $fieldValue) {
280  $whereStatement[] = $fieldName . ' = ' . $this->databaseHandle->fullQuoteStr($fieldValue, $tableName);
281  }
282 
283  return implode(' AND ', $whereStatement);
284  }
285 
292  public function getObjectDataByQuery(QueryInterface $query) {
293  $statement = $query->getStatement();
294  if ($statement instanceof Statement) {
295  $rows = $this->getObjectDataByRawQuery($statement);
296  } else {
297  $rows = $this->getRowsByStatementParts($query);
298  }
299 
300  $rows = $this->doLanguageAndWorkspaceOverlay($query->getSource(), $rows, $query->getQuerySettings());
301  return $rows;
302  }
303 
311  protected function createQueryCommandParametersFromStatementParts(array $statementParts) {
312  return array(
313  'selectFields' => implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']),
314  'fromTable' => implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']),
315  'whereClause' => (!empty($statementParts['where']) ? implode('', $statementParts['where']) : '1=1')
316  . (!empty($statementParts['additionalWhereClause'])
317  ? ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'])
318  : ''
319  ),
320  'orderBy' => (!empty($statementParts['orderings']) ? implode(', ', $statementParts['orderings']) : ''),
321  'limit' => ($statementParts['offset'] ? $statementParts['offset'] . ', ' : '')
322  . ($statementParts['limit'] ? $statementParts['limit'] : '')
323  );
324  }
325 
332  protected function getRowsByStatementParts(QueryInterface $query) {
333  if ($query->getQuerySettings()->getUsePreparedStatement()) {
334  list($statementParts, $parameters) = $this->getStatementParts($query, FALSE);
335  $rows = $this->getRowsFromPreparedDatabase($statementParts, $parameters);
336  } else {
337  list($statementParts) = $this->getStatementParts($query);
338  $rows = $this->getRowsFromDatabase($statementParts);
339  }
340 
341  return $rows;
342  }
343 
350  protected function getRowsFromDatabase(array $statementParts) {
351  $queryCommandParameters = $this->createQueryCommandParametersFromStatementParts($statementParts);
352  $rows = $this->databaseHandle->exec_SELECTgetRows(
353  $queryCommandParameters['selectFields'],
354  $queryCommandParameters['fromTable'],
355  $queryCommandParameters['whereClause'],
356  '',
357  $queryCommandParameters['orderBy'],
358  $queryCommandParameters['limit']
359  );
360  $this->checkSqlErrors();
361 
362  return $rows;
363  }
364 
372  protected function getRowsFromPreparedDatabase(array $statementParts, array $parameters) {
373  $queryCommandParameters = $this->createQueryCommandParametersFromStatementParts($statementParts);
374  $preparedStatement = $this->databaseHandle->prepare_SELECTquery(
375  $queryCommandParameters['selectFields'],
376  $queryCommandParameters['fromTable'],
377  $queryCommandParameters['whereClause'],
378  '',
379  $queryCommandParameters['orderBy'],
380  $queryCommandParameters['limit']
381  );
382 
383  $preparedStatement->execute($parameters);
384  $rows = $preparedStatement->fetchAll();
385 
386  $preparedStatement->free();
387  return $rows;
388  }
389 
396  protected function getObjectDataByRawQuery(Statement $statement) {
397  $realStatement = $statement->getStatement();
398  $parameters = $statement->getBoundVariables();
399 
400  if ($realStatement instanceof \TYPO3\CMS\Core\Database\PreparedStatement) {
401  $realStatement->execute($parameters);
402  $rows = $realStatement->fetchAll();
403 
404  $realStatement->free();
405  } else {
410  if (!empty($parameters)) {
411  $this->replacePlaceholders($realStatement, $parameters);
412  }
413 
414  $result = $this->databaseHandle->sql_query($realStatement);
415  $this->checkSqlErrors();
416 
417  $rows = array();
418  while ($row = $this->databaseHandle->sql_fetch_assoc($result)) {
419  if (is_array($row)) {
420  $rows[] = $row;
421  }
422  }
423  $this->databaseHandle->sql_free_result($result);
424  }
425 
426  return $rows;
427  }
428 
436  public function getObjectCountByQuery(QueryInterface $query) {
437  if ($query->getConstraint() instanceof Statement) {
438  throw new \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException('Could not execute count on queries with a constraint of type TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Statement', 1256661045);
439  }
440 
441  list($statementParts) = $this->getStatementParts($query);
442 
443  $fields = '*';
444  if (isset($statementParts['keywords']['distinct'])) {
445  $fields = 'DISTINCT ' . reset($statementParts['tables']) . '.uid';
446  }
447 
448  $queryCommandParameters = $this->createQueryCommandParametersFromStatementParts($statementParts);
449  $count = $this->databaseHandle->exec_SELECTcountRows(
450  $fields,
451  $queryCommandParameters['fromTable'],
452  $queryCommandParameters['whereClause']
453  );
454  $this->checkSqlErrors();
455 
456  if ($statementParts['offset']) {
457  $count -= $statementParts['offset'];
458  }
459 
460  if ($statementParts['limit']) {
461  $count = min($count, $statementParts['limit']);
462  }
463 
464  return (int)max(0, $count);
465  }
466 
475  protected function getStatementParts($query, $resolveParameterPlaceholders = TRUE) {
485  list($queryHash, $parameters) = $this->queryParser->preparseQuery($query);
486 
487  if ($query->getQuerySettings()->getUseQueryCache()) {
488  $statementParts = $this->getQueryCacheEntry($queryHash);
489  if ($queryHash && !$statementParts) {
490  $statementParts = $this->queryParser->parseQuery($query);
491  $this->setQueryCacheEntry($queryHash, $statementParts);
492  }
493  } else {
494  $statementParts = $this->queryParser->parseQuery($query);
495  }
496 
497  if (!$statementParts) {
498  throw new \RuntimeException('Your query could not be built.', 1394453197);
499  }
500 
501  $this->queryParser->addDynamicQueryParts($query->getQuerySettings(), $statementParts);
502 
503  // Limit and offset are not cached to allow caching of pagebrowser queries.
504  $statementParts['limit'] = ((int)$query->getLimit() ?: NULL);
505  $statementParts['offset'] = ((int)$query->getOffset() ?: NULL);
506 
507  if ($resolveParameterPlaceholders === TRUE) {
508  $statementParts = $this->resolveParameterPlaceholders($statementParts, $parameters);
509  }
510 
511  return array($statementParts, $parameters);
512  }
513 
521  protected function resolveParameterPlaceholders(array $statementParts, array $parameters) {
522  $tableNameForEscape = (reset($statementParts['tables']) ?: 'foo');
523 
524  foreach ($parameters as $parameterPlaceholder => $parameter) {
525  if ($parameter instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
526  $parameter = $parameter->_loadRealInstance();
527  }
528 
529  if ($parameter instanceof \DateTime) {
530  $parameter = $parameter->format('U');
531  } elseif ($parameter instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
532  $parameter = (int)$parameter->getUid();
533  } elseif (is_array($parameter)) {
534  $subParameters = array();
535  foreach ($parameter as $subParameter) {
536  $subParameters[] = $this->databaseHandle->fullQuoteStr($subParameter, $tableNameForEscape);
537  }
538  $parameter = implode(',', $subParameters);
539  } elseif ($parameter === NULL) {
540  $parameter = 'NULL';
541  } elseif (is_bool($parameter)) {
542  $parameter = (int)$parameter;
543  } else {
544  $parameter = $this->databaseHandle->fullQuoteStr((string)$parameter, $tableNameForEscape);
545  }
546 
547  $statementParts['where'] = str_replace($parameterPlaceholder, $parameter, $statementParts['where']);
548  }
549 
550  return $statementParts;
551  }
552 
560  public function getUidOfAlreadyPersistedValueObject(\TYPO3\CMS\Extbase\DomainObject\AbstractValueObject $object) {
561  $fields = array();
562  $parameters = array();
563  $dataMap = $this->dataMapper->getDataMap(get_class($object));
564  $properties = $object->_getProperties();
565  foreach ($properties as $propertyName => $propertyValue) {
566  // FIXME We couple the Backend to the Entity implementation (uid, isClone); changes there breaks this method
567  if ($dataMap->isPersistableProperty($propertyName) && $propertyName !== 'uid' && $propertyName !== 'pid' && $propertyName !== 'isClone') {
568  if ($propertyValue === NULL) {
569  $fields[] = $dataMap->getColumnMap($propertyName)->getColumnName() . ' IS NULL';
570  } else {
571  $fields[] = $dataMap->getColumnMap($propertyName)->getColumnName() . '=?';
572  $parameters[] = $this->getPlainValue($propertyValue);
573  }
574  }
575  }
576  $sql = array();
577  $sql['additionalWhereClause'] = array();
578  $tableName = $dataMap->getTableName();
579  $this->addVisibilityConstraintStatement(new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings(), $tableName, $sql);
580  $statement = 'SELECT * FROM ' . $tableName;
581  $statement .= ' WHERE ' . implode(' AND ', $fields);
582  if (!empty($sql['additionalWhereClause'])) {
583  $statement .= ' AND ' . implode(' AND ', $sql['additionalWhereClause']);
584  }
585  $this->replacePlaceholders($statement, $parameters, $tableName);
586  // debug($statement,-2);
587  $res = $this->databaseHandle->sql_query($statement);
588  $this->checkSqlErrors($statement);
589  $row = $this->databaseHandle->sql_fetch_assoc($res);
590  if ($row !== FALSE) {
591  return (int)$row['uid'];
592  } else {
593  return FALSE;
594  }
595  }
596 
605  protected function getPlainValue($input) {
606  if (is_array($input)) {
607  throw new \TYPO3\CMS\Extbase\Persistence\Generic\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 ($input instanceof \TYPO3\CMS\Core\Type\TypeInterface) {
612  return (string) $input;
613  } elseif (is_object($input)) {
614  if ($input instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
615  $realInput = $input->_loadRealInstance();
616  } else {
617  $realInput = $input;
618  }
619  if ($realInput instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
620  return $realInput->getUid();
621  } else {
622  throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An object of class "' . get_class($realInput) . '" could not be converted to a plain value.', 1274799934);
623  }
624  } elseif (is_bool($input)) {
625  return (int)$input;
626  } else {
627  return $input;
628  }
629  }
630 
643  protected function replacePlaceholders(&$sqlString, array $parameters, $tableName = 'foo') {
644  // TODO profile this method again
645  if (substr_count($sqlString, '?') !== count($parameters)) {
646  throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception('The number of question marks to replace must be equal to the number of parameters.', 1242816074);
647  }
648  $offset = 0;
649  foreach ($parameters as $parameter) {
650  $markPosition = strpos($sqlString, '?', $offset);
651  if ($markPosition !== FALSE) {
652  if ($parameter === NULL) {
653  $parameter = 'NULL';
654  } elseif (is_array($parameter) || $parameter instanceof \ArrayAccess || $parameter instanceof \Traversable) {
655  $items = array();
656  foreach ($parameter as $item) {
657  $items[] = $this->databaseHandle->fullQuoteStr($item, $tableName);
658  }
659  $parameter = '(' . implode(',', $items) . ')';
660  } else {
661  $parameter = $this->databaseHandle->fullQuoteStr($parameter, $tableName);
662  }
663  $sqlString = substr($sqlString, 0, $markPosition) . $parameter . substr($sqlString, ($markPosition + 1));
664  }
665  $offset = $markPosition + strlen($parameter);
666  }
667  }
668 
678  protected function addVisibilityConstraintStatement(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings, $tableName, array &$sql) {
679  $statement = '';
680  if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
681  $ignoreEnableFields = $querySettings->getIgnoreEnableFields();
682  $enableFieldsToBeIgnored = $querySettings->getEnableFieldsToBeIgnored();
683  $includeDeleted = $querySettings->getIncludeDeleted();
684  if ($this->environmentService->isEnvironmentInFrontendMode()) {
685  $statement .= $this->getFrontendConstraintStatement($tableName, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted);
686  } else {
687  // TYPO3_MODE === 'BE'
688  $statement .= $this->getBackendConstraintStatement($tableName, $ignoreEnableFields, $includeDeleted);
689  }
690  if (!empty($statement)) {
691  $statement = strtolower(substr($statement, 1, 3)) === 'and' ? substr($statement, 5) : $statement;
692  $sql['additionalWhereClause'][] = $statement;
693  }
694  }
695  }
696 
708  protected function getFrontendConstraintStatement($tableName, $ignoreEnableFields, array $enableFieldsToBeIgnored = array(), $includeDeleted) {
709  $statement = '';
710  if ($ignoreEnableFields && !$includeDeleted) {
711  if (count($enableFieldsToBeIgnored)) {
712  // array_combine() is necessary because of the way \TYPO3\CMS\Frontend\Page\PageRepository::enableFields() is implemented
713  $statement .= $this->getPageRepository()->enableFields($tableName, -1, array_combine($enableFieldsToBeIgnored, $enableFieldsToBeIgnored));
714  } else {
715  $statement .= $this->getPageRepository()->deleteClause($tableName);
716  }
717  } elseif (!$ignoreEnableFields && !$includeDeleted) {
718  $statement .= $this->getPageRepository()->enableFields($tableName);
719  } elseif (!$ignoreEnableFields && $includeDeleted) {
720  throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InconsistentQuerySettingsException('Query setting "ignoreEnableFields=FALSE" can not be used together with "includeDeleted=TRUE" in frontend context.', 1327678173);
721  }
722  return $statement;
723  }
724 
734  protected function getBackendConstraintStatement($tableName, $ignoreEnableFields, $includeDeleted) {
735  $statement = '';
736  if (!$ignoreEnableFields) {
737  $statement .= BackendUtility::BEenableFields($tableName);
738  }
739  if (!$includeDeleted) {
740  $statement .= BackendUtility::deleteClause($tableName);
741  }
742  return $statement;
743  }
744 
755  protected function doLanguageAndWorkspaceOverlay(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source, array $rows, \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings, $workspaceUid = NULL) {
756  if ($source instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SelectorInterface) {
757  $tableName = $source->getSelectorName();
758  } elseif ($source instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\JoinInterface) {
759  $tableName = $source->getRight()->getSelectorName();
760  } else {
761  // No proper source, so we do not have a table name here
762  // we cannot do an overlay and return the original rows instead.
763  return $rows;
764  }
765 
767  if (is_object($GLOBALS['TSFE'])) {
768  if ($workspaceUid !== NULL) {
769  $pageRepository->versioningWorkspaceId = $workspaceUid;
770  }
771  } else {
772  if ($workspaceUid === NULL) {
773  $workspaceUid = $GLOBALS['BE_USER']->workspace;
774  }
775  $pageRepository->versioningWorkspaceId = $workspaceUid;
776  }
777 
778  // Fetches the move-placeholder in case it is supported
779  // by the table and if there's only one row in the result set
780  // (applying this to all rows does not work, since the sorting
781  // order would be destroyed and possible limits not met anymore)
782  if (!empty($pageRepository->versioningWorkspaceId)
783  && !empty($GLOBALS['TCA'][$tableName]['ctrl']['versioningWS'])
784  && (int)$GLOBALS['TCA'][$tableName]['ctrl']['versioningWS'] >= 2
785  && count($rows) === 1
786  ) {
787  $movePlaceholder = $this->databaseHandle->exec_SELECTgetSingleRow(
788  $tableName . '.*',
789  $tableName,
790  't3ver_state=3 AND t3ver_wsid=' . $pageRepository->versioningWorkspaceId
791  . ' AND t3ver_move_id=' . $rows[0]['uid']
792  );
793  if (!empty($movePlaceholder)) {
794  $rows = array($movePlaceholder);
795  }
796  }
797 
798  $overlaidRows = array();
799  foreach ($rows as $row) {
800  // If current row is a translation select its parent
801  if (isset($tableName) && isset($GLOBALS['TCA'][$tableName])
802  && isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
803  && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
804  && !isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerTable'])
805  ) {
806  if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']])
807  && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0
808  ) {
809  $row = $this->databaseHandle->exec_SELECTgetSingleRow(
810  $tableName . '.*',
811  $tableName,
812  $tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] .
813  ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0'
814  );
815  }
816  }
817  $pageRepository->versionOL($tableName, $row, TRUE);
818  if ($tableName == 'pages') {
819  $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
820  } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
821  && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== ''
822  && !isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerTable'])
823  ) {
824  if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) {
825  $overlayMode = $querySettings->getLanguageMode() === 'strict' ? 'hideNonTranslated' : '';
826  $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
827  }
828  }
829  if ($row !== NULL && is_array($row)) {
830  $overlaidRows[] = $row;
831  }
832  }
833  return $overlaidRows;
834  }
835 
839  protected function getPageRepository() {
840  if (!$this->pageRepository instanceof \TYPO3\CMS\Frontend\Page\PageRepository) {
841  if ($this->environmentService->isEnvironmentInFrontendMode() && is_object($GLOBALS['TSFE'])) {
842  $this->pageRepository = $GLOBALS['TSFE']->sys_page;
843  } else {
844  $this->pageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
845  }
846  }
847 
848  return $this->pageRepository;
849  }
850 
858  protected function checkSqlErrors($sql = '') {
859  $error = $this->databaseHandle->sql_error();
860  if ($error !== '') {
861  $error .= $sql ? ': ' . $sql : '';
862  throw new \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException($error, 1247602160);
863  }
864  }
865 
877  protected function clearPageCache($tableName, $uid) {
878  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
879  if (isset($frameworkConfiguration['persistence']['enableAutomaticCacheClearing']) && $frameworkConfiguration['persistence']['enableAutomaticCacheClearing'] === '1') {
880  } else {
881  // if disabled, return
882  return;
883  }
884  $pageIdsToClear = array();
885  $storagePage = NULL;
886  $columns = $this->databaseHandle->admin_get_fields($tableName);
887  if (array_key_exists('pid', $columns)) {
888  $result = $this->databaseHandle->exec_SELECTquery('pid', $tableName, 'uid=' . (int)$uid);
889  if ($row = $this->databaseHandle->sql_fetch_assoc($result)) {
890  $storagePage = $row['pid'];
891  $pageIdsToClear[] = $storagePage;
892  }
893  } elseif (isset($GLOBALS['TSFE'])) {
894  // No PID column - we can do a best-effort to clear the cache of the current page if in FE
895  $storagePage = $GLOBALS['TSFE']->id;
896  $pageIdsToClear[] = $storagePage;
897  }
898  if ($storagePage === NULL) {
899  return;
900  }
901  if (!isset($this->pageTSConfigCache[$storagePage])) {
902  $this->pageTSConfigCache[$storagePage] = BackendUtility::getPagesTSconfig($storagePage);
903  }
904  if (isset($this->pageTSConfigCache[$storagePage]['TCEMAIN.']['clearCacheCmd'])) {
905  $clearCacheCommands = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', strtolower($this->pageTSConfigCache[$storagePage]['TCEMAIN.']['clearCacheCmd']), TRUE);
906  $clearCacheCommands = array_unique($clearCacheCommands);
907  foreach ($clearCacheCommands as $clearCacheCommand) {
908  if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($clearCacheCommand)) {
909  $pageIdsToClear[] = $clearCacheCommand;
910  }
911  }
912  }
913 
914  foreach ($pageIdsToClear as $pageIdToClear) {
915  $this->cacheService->getPageIdStack()->push($pageIdToClear);
916  }
917  }
918 
925  protected function getQueryCacheEntry($entryIdentifier) {
926  if (!isset($this->queryRuntimeCache[$entryIdentifier])) {
927  $this->queryRuntimeCache[$entryIdentifier] = $this->queryCache->get($entryIdentifier);
928  }
929  return $this->queryRuntimeCache[$entryIdentifier];
930  }
931 
939  protected function setQueryCacheEntry($entryIdentifier, $variable) {
940  $this->queryRuntimeCache[$entryIdentifier] = $variable;
941  $this->queryCache->set($entryIdentifier, $variable, array(), 0);
942  }
943 }
addRow($tableName, array $fieldValues, $isRelation=FALSE)
$sql
Definition: server.php:82
$parameters
Definition: FileDumpEID.php:15
resolveParameterPlaceholders(array $statementParts, array $parameters)
getStatementParts($query, $resolveParameterPlaceholders=TRUE)
getUidOfAlreadyPersistedValueObject(\TYPO3\CMS\Extbase\DomainObject\AbstractValueObject $object)
$uid
Definition: server.php:36
replacePlaceholders(&$sqlString, array $parameters, $tableName='foo')
getBackendConstraintStatement($tableName, $ignoreEnableFields, $includeDeleted)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
doLanguageAndWorkspaceOverlay(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source, array $rows, \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings, $workspaceUid=NULL)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
addVisibilityConstraintStatement(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings, $tableName, array &$sql)
getFrontendConstraintStatement($tableName, $ignoreEnableFields, array $enableFieldsToBeIgnored=array(), $includeDeleted)
removeRow($tableName, array $where, $isRelation=FALSE)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getPagesTSconfig($id, $rootLine=NULL, $returnPartArray=FALSE)
getMaxValueFromTable($tableName, array $where, $columnName)
static deleteClause($table, $tableAlias='')
updateRow($tableName, array $fieldValues, $isRelation=FALSE)
getRowsFromPreparedDatabase(array $statementParts, array $parameters)