TYPO3 CMS  TYPO3_6-2
Backend.php
Go to the documentation of this file.
1 <?php
3 
19 
25 
30  protected $session;
31 
36 
41 
45  protected $deletedEntities;
46 
50  protected $changedEntities;
51 
56 
61  protected $reflectionService;
62 
67  protected $qomFactory;
68 
73  protected $storageBackend;
74 
79  protected $dataMapper;
80 
86  protected $referenceIndex;
87 
92 
98 
104  public function __construct(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager) {
105  $this->configurationManager = $configurationManager;
106  $this->referenceIndex = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\ReferenceIndex');
107  $this->aggregateRootObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
108  $this->deletedEntities = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
109  $this->changedEntities = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
110  }
111 
116  $this->persistenceManager = $persistenceManager;
117  }
118 
124  public function getSession() {
125  return $this->session;
126  }
127 
133  public function getDataMapper() {
134  return $this->dataMapper;
135  }
136 
142  public function getQomFactory() {
143  return $this->qomFactory;
144  }
145 
151  public function getReflectionService() {
153  }
154 
162  public function getObjectCountByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query) {
163  return $this->storageBackend->getObjectCountByQuery($query);
164  }
165 
173  public function getObjectDataByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query) {
174  $query = $this->emitBeforeGettingObjectDataSignal($query);
175  $result = $this->storageBackend->getObjectDataByQuery($query);
176  $result = $this->emitafterGettingObjectDataSignal($query, $result);
177  return $result;
178  }
179 
186  protected function emitBeforeGettingObjectDataSignal(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query) {
187  $signalArguments = $this->signalSlotDispatcher->dispatch(__CLASS__, 'beforeGettingObjectData', array($query));
188  return $signalArguments[0];
189  }
190 
198  protected function emitAfterGettingObjectDataSignal(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query, array $result) {
199  $signalArguments = $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterGettingObjectData', array($query, $result));
200  return $signalArguments[1];
201  }
202 
210  public function getIdentifierByObject($object) {
211  if ($object instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
212  $object = $object->_loadRealInstance();
213  if (!is_object($object)) {
214  return NULL;
215  }
216  }
217  return $this->session->getIdentifierByObject($object);
218  }
219 
228  public function getObjectByIdentifier($identifier, $className) {
229  if ($this->session->hasIdentifier($identifier, $className)) {
230  return $this->session->getObjectByIdentifier($identifier, $className);
231  } else {
232  $query = $this->persistenceManager->createQueryForType($className);
233  $query->getQuerySettings()->setRespectStoragePage(FALSE);
234  $query->getQuerySettings()->setRespectSysLanguage(FALSE);
235  return $query->matching($query->equals('uid', $identifier))->execute()->getFirst();
236  }
237  }
238 
245  public function isNewObject($object) {
246  return $this->getIdentifierByObject($object) === NULL;
247  }
248 
266  public function replaceObject($existingObject, $newObject) {
267  $this->session->replaceReconstitutedEntity($existingObject, $newObject);
268  }
269 
276  public function setAggregateRootObjects(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $objects) {
277  $this->aggregateRootObjects = $objects;
278  }
279 
286  public function setChangedEntities(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $entities) {
287  $this->changedEntities = $entities;
288  }
289 
296  public function setDeletedEntities(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $entities) {
297  $this->deletedEntities = $entities;
298  }
299 
305  public function commit() {
306  $this->persistObjects();
307  $this->processDeletedObjects();
308  }
309 
317  public function setDeletedObjects(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $objects) {
318  $this->setDeletedEntities($objects);
319  }
320 
326  protected function persistObjects() {
327  $this->visitedDuringPersistence = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
328  foreach ($this->aggregateRootObjects as $object) {
330  if ($object->_isNew()) {
331  $this->insertObject($object);
332  }
333  $this->persistObject($object, NULL);
334  }
335  foreach ($this->changedEntities as $object) {
336  $this->persistObject($object, NULL);
337  }
338  }
339 
346  protected function persistObject(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object) {
347  if (isset($this->visitedDuringPersistence[$object])) {
348  return;
349  }
350  $row = array();
351  $queue = array();
352  $dataMap = $this->dataMapper->getDataMap(get_class($object));
353  $properties = $object->_getProperties();
354  foreach ($properties as $propertyName => $propertyValue) {
355  if (!$dataMap->isPersistableProperty($propertyName) || $this->propertyValueIsLazyLoaded($propertyValue)) {
356  continue;
357  }
358  $columnMap = $dataMap->getColumnMap($propertyName);
359  if ($propertyValue instanceof \TYPO3\CMS\Extbase\Persistence\ObjectStorage) {
360  $cleanProperty = $object->_getCleanProperty($propertyName);
361  // objectstorage needs to be persisted if the object is new, the objectstorge is dirty, meaning it has
362  // been changed after initial build, or a empty objectstorge is present and the cleanstate objectstorage
363  // has childelements, meaning all elements should been removed from the objectstorage
364  if ($object->_isNew() || $propertyValue->_isDirty() || ($propertyValue->count() == 0 && $cleanProperty && $cleanProperty->count() > 0)) {
365  $this->persistObjectStorage($propertyValue, $object, $propertyName, $row);
366  $propertyValue->_memorizeCleanState();
367  }
368  foreach ($propertyValue as $containedObject) {
369  if ($containedObject instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
370  $queue[] = $containedObject;
371  }
372  }
373  } elseif ($propertyValue instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface
374  && $object instanceof ObjectMonitoringInterface) {
375  if ($object->_isDirty($propertyName)) {
376  if ($propertyValue->_isNew()) {
377  $this->insertObject($propertyValue, $object, $propertyName);
378  }
379  $row[$columnMap->getColumnName()] = $this->getPlainValue($propertyValue);
380  }
381  $queue[] = $propertyValue;
382  } elseif ($object->_isNew() || $object->_isDirty($propertyName)) {
383  $row[$columnMap->getColumnName()] = $this->getPlainValue($propertyValue, $columnMap);
384  }
385  }
386  if (count($row) > 0) {
387  $this->updateObject($object, $row);
388  $object->_memorizeCleanState();
389  }
390  $this->visitedDuringPersistence[$object] = $object->getUid();
391  foreach ($queue as $queuedObject) {
392  $this->persistObject($queuedObject);
393  }
394  }
395 
402  protected function propertyValueIsLazyLoaded($propertyValue) {
403  if ($propertyValue instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
404  return TRUE;
405  }
406  if ($propertyValue instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage) {
407  if ($propertyValue->isInitialized() === FALSE) {
408  return TRUE;
409  }
410  }
411  return FALSE;
412  }
413 
425  protected function persistObjectStorage(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $objectStorage, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $propertyName, array &$row) {
426  $className = get_class($parentObject);
427  $columnMap = $this->dataMapper->getDataMap($className)->getColumnMap($propertyName);
428  $propertyMetaData = $this->reflectionService->getClassSchema($className)->getProperty($propertyName);
429  foreach ($this->getRemovedChildObjects($parentObject, $propertyName) as $removedObject) {
430  $this->detachObjectFromParentObject($removedObject, $parentObject, $propertyName);
431  if ($columnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_MANY && $propertyMetaData['cascade'] === 'remove') {
432  $this->removeEntity($removedObject);
433  }
434  }
435 
436  $currentUids = array();
437  $sortingPosition = 1;
438  $updateSortingOfFollowing = FALSE;
439 
440  foreach ($objectStorage as $object) {
442  if (empty($currentUids)) {
443  $sortingPosition = 1;
444  } else {
445  $sortingPosition++;
446  }
447  $cleanProperty = $parentObject->_getCleanProperty($propertyName);
448  if ($object->_isNew()) {
449  $this->insertObject($object);
450  $this->attachObjectToParentObject($object, $parentObject, $propertyName, $sortingPosition);
451  // if a new object is inserted, all objects after this need to have their sorting updated
452  $updateSortingOfFollowing = TRUE;
453  } elseif ($cleanProperty === NULL || $cleanProperty->getPosition($object) === NULL) {
454  // if parent object is new then it doesn't have cleanProperty yet; before attaching object it's clean position is null
455  $this->attachObjectToParentObject($object, $parentObject, $propertyName, $sortingPosition);
456  // if a relation is dirty (speaking the same object is removed and added again at a different position), all objects after this needs to be updated the sorting
457  $updateSortingOfFollowing = TRUE;
458  } elseif ($objectStorage->isRelationDirty($object) || $cleanProperty->getPosition($object) !== $objectStorage->getPosition($object)) {
459  $this->updateRelationOfObjectToParentObject($object, $parentObject, $propertyName, $sortingPosition);
460  $updateSortingOfFollowing = TRUE;
461  } elseif ($updateSortingOfFollowing) {
462  if ($sortingPosition > $objectStorage->getPosition($object)) {
463  $this->updateRelationOfObjectToParentObject($object, $parentObject, $propertyName, $sortingPosition);
464  } else {
465  $sortingPosition = $objectStorage->getPosition($object);
466  }
467  }
468  $currentUids[] = $object->getUid();
469  }
470 
471  if ($columnMap->getParentKeyFieldName() === NULL) {
472  $row[$columnMap->getColumnName()] = implode(',', $currentUids);
473  } else {
474  $row[$columnMap->getColumnName()] = $this->dataMapper->countRelated($parentObject, $propertyName);
475  }
476  }
477 
486  protected function getRemovedChildObjects(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, $propertyName) {
487  $removedObjects = array();
488  $cleanPropertyValue = $object->_getCleanProperty($propertyName);
489  if (is_array($cleanPropertyValue) || $cleanPropertyValue instanceof \Iterator) {
490  $propertyValue = $object->_getProperty($propertyName);
491  foreach ($cleanPropertyValue as $containedObject) {
492  if (!$propertyValue->contains($containedObject)) {
493  $removedObjects[] = $containedObject;
494  }
495  }
496  }
497  return $removedObjects;
498  }
499 
509  protected function attachObjectToParentObject(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $parentPropertyName, $sortingPosition = 0) {
510  $parentDataMap = $this->dataMapper->getDataMap(get_class($parentObject));
511  $parentColumnMap = $parentDataMap->getColumnMap($parentPropertyName);
512  if ($parentColumnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_MANY) {
513  $this->attachObjectToParentObjectRelationHasMany($object, $parentObject, $parentPropertyName, $sortingPosition);
514  } elseif ($parentColumnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
515  $this->insertRelationInRelationtable($object, $parentObject, $parentPropertyName, $sortingPosition);
516  }
517  }
518 
528  protected function updateRelationOfObjectToParentObject(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\AbstractEntity $parentObject, $parentPropertyName, $sortingPosition = 0) {
529  $parentDataMap = $this->dataMapper->getDataMap(get_class($parentObject));
530  $parentColumnMap = $parentDataMap->getColumnMap($parentPropertyName);
531  if ($parentColumnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_MANY) {
532  $this->attachObjectToParentObjectRelationHasMany($object, $parentObject, $parentPropertyName, $sortingPosition);
533  } elseif ($parentColumnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
534  $this->updateRelationInRelationTable($object, $parentObject, $parentPropertyName, $sortingPosition);
535  }
536  }
537 
548  protected function attachObjectToParentObjectRelationHasMany(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\AbstractEntity $parentObject, $parentPropertyName, $sortingPosition = 0) {
549  $parentDataMap = $this->dataMapper->getDataMap(get_class($parentObject));
550  $parentColumnMap = $parentDataMap->getColumnMap($parentPropertyName);
551  if ($parentColumnMap->getTypeOfRelation() !== \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_MANY) {
552  throw new \TYPO3\CMS\Extbase\Persistence\Exception\IllegalRelationTypeException(
553  'Parent column relation type is ' . $parentColumnMap->getTypeOfRelation() .
555  1345368105
556  );
557  }
558  $row = array();
559  $parentKeyFieldName = $parentColumnMap->getParentKeyFieldName();
560  if ($parentKeyFieldName !== NULL) {
561  $row[$parentKeyFieldName] = $parentObject->getUid();
562  $parentTableFieldName = $parentColumnMap->getParentTableFieldName();
563  if ($parentTableFieldName !== NULL) {
564  $row[$parentTableFieldName] = $parentDataMap->getTableName();
565  }
566  $relationTableMatchFields = $parentColumnMap->getRelationTableMatchFields();
567  if (is_array($relationTableMatchFields)) {
568  $row = array_merge($relationTableMatchFields, $row);
569  }
570  }
571  $childSortByFieldName = $parentColumnMap->getChildSortByFieldName();
572  if (!empty($childSortByFieldName)) {
573  $row[$childSortByFieldName] = $sortingPosition;
574  }
575  if (!empty($row)) {
576  $this->updateObject($object, $row);
577  }
578  }
579 
588  protected function detachObjectFromParentObject(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $parentPropertyName) {
589  $parentDataMap = $this->dataMapper->getDataMap(get_class($parentObject));
590  $parentColumnMap = $parentDataMap->getColumnMap($parentPropertyName);
591  if ($parentColumnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_MANY) {
592  $row = array();
593  $parentKeyFieldName = $parentColumnMap->getParentKeyFieldName();
594  if ($parentKeyFieldName !== NULL) {
595  $row[$parentKeyFieldName] = '';
596  $parentTableFieldName = $parentColumnMap->getParentTableFieldName();
597  if ($parentTableFieldName !== NULL) {
598  $row[$parentTableFieldName] = '';
599  }
600  $relationTableMatchFields = $parentColumnMap->getRelationTableMatchFields();
601  if (is_array($relationTableMatchFields) && count($relationTableMatchFields)) {
602  $row = array_merge(array_fill_keys(array_keys($relationTableMatchFields), ''), $row);
603  }
604  }
605  $childSortByFieldName = $parentColumnMap->getChildSortByFieldName();
606  if (!empty($childSortByFieldName)) {
607  $row[$childSortByFieldName] = 0;
608  }
609  if (count($row) > 0) {
610  $this->updateObject($object, $row);
611  }
612  } elseif ($parentColumnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
613  $this->deleteRelationFromRelationtable($object, $parentObject, $parentPropertyName);
614  }
615  }
616 
625  protected function insertObject(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject = NULL, $parentPropertyName = '') {
626  if ($object instanceof \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject) {
628  if ($result !== FALSE) {
629  $object->_setProperty('uid', (int)$result);
630  return;
631  }
632  }
633  $dataMap = $this->dataMapper->getDataMap(get_class($object));
634  $row = array();
635  $this->addCommonFieldsToRow($object, $row);
636  if ($dataMap->getLanguageIdColumnName() !== NULL && $object->_getProperty('_languageUid') === NULL) {
637  $row[$dataMap->getLanguageIdColumnName()] = 0;
638  $object->_setProperty('_languageUid', 0);
639  }
640  if ($parentObject !== NULL && $parentPropertyName) {
641  $parentColumnDataMap = $this->dataMapper->getDataMap(get_class($parentObject))->getColumnMap($parentPropertyName);
642  $relationTableMatchFields = $parentColumnDataMap->getRelationTableMatchFields();
643  if (is_array($relationTableMatchFields)) {
644  $row = array_merge($relationTableMatchFields, $row);
645  }
646  if ($parentColumnDataMap->getParentKeyFieldName() !== NULL) {
647  $row[$parentColumnDataMap->getParentKeyFieldName()] = (int)$parentObject->getUid();
648  }
649  }
650  $uid = $this->storageBackend->addRow($dataMap->getTableName(), $row);
651  $object->_setProperty('uid', (int)$uid);
652  $object->setPid((int)$row['pid']);
653  if ((int)$uid >= 1) {
654  $this->emitAfterInsertObjectSignal($object);
655  }
656  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
657  if ($frameworkConfiguration['persistence']['updateReferenceIndex'] === '1') {
658  $this->referenceIndex->updateRefIndexTable($dataMap->getTableName(), $uid);
659  }
660  $this->session->registerObject($object, $uid);
661  }
662 
669  $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterInsertObject', array($object));
670  }
671 
678  protected function getUidOfAlreadyPersistedValueObject(\TYPO3\CMS\Extbase\DomainObject\AbstractValueObject $object) {
679  return $this->storageBackend->getUidOfAlreadyPersistedValueObject($object);
680  }
681 
691  protected function insertRelationInRelationtable(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $propertyName, $sortingPosition = NULL) {
692  $dataMap = $this->dataMapper->getDataMap(get_class($parentObject));
693  $columnMap = $dataMap->getColumnMap($propertyName);
694  $parentUid = $parentObject->getUid();
695  if ($parentObject->_getProperty('_localizedUid') !== NULL) {
696  $parentUid = $parentObject->_getProperty('_localizedUid');
697  }
698  $row = array(
699  $columnMap->getParentKeyFieldName() => (int)$parentUid,
700  $columnMap->getChildKeyFieldName() => (int)$object->getUid(),
701  $columnMap->getChildSortByFieldName() => !is_null($sortingPosition) ? (int)$sortingPosition : 0
702  );
703  $relationTableName = $columnMap->getRelationTableName();
704  if ($columnMap->getRelationTablePageIdColumnName() !== NULL) {
705  $row[$columnMap->getRelationTablePageIdColumnName()] = $this->determineStoragePageIdForNewRecord();
706  }
707  $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
708  if (is_array($relationTableMatchFields)) {
709  $row = array_merge($relationTableMatchFields, $row);
710  }
711  $relationTableInsertFields = $columnMap->getRelationTableInsertFields();
712  if (is_array($relationTableInsertFields)) {
713  $row = array_merge($relationTableInsertFields, $row);
714  }
715  $res = $this->storageBackend->addRow($relationTableName, $row, TRUE);
716  return $res;
717  }
718 
728  protected function updateRelationInRelationTable(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $propertyName, $sortingPosition = 0) {
729  $dataMap = $this->dataMapper->getDataMap(get_class($parentObject));
730  $columnMap = $dataMap->getColumnMap($propertyName);
731  $row = array(
732  $columnMap->getParentKeyFieldName() => (int)$parentObject->getUid(),
733  $columnMap->getChildKeyFieldName() => (int)$object->getUid(),
734  $columnMap->getChildSortByFieldName() => (int)$sortingPosition
735  );
736  $relationTableName = $columnMap->getRelationTableName();
737  $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
738  if (is_array($relationTableMatchFields)) {
739  $row = array_merge($relationTableMatchFields, $row);
740  }
741  $res = $this->storageBackend->updateRelationTableRow(
742  $relationTableName,
743  $row);
744  return $res;
745  }
746 
754  protected function deleteAllRelationsFromRelationtable(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $parentPropertyName) {
755  $dataMap = $this->dataMapper->getDataMap(get_class($parentObject));
756  $columnMap = $dataMap->getColumnMap($parentPropertyName);
757  $relationTableName = $columnMap->getRelationTableName();
758  $relationMatchFields = array(
759  $columnMap->getParentKeyFieldName() => (int)$parentObject->getUid()
760  );
761  $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
762  if (is_array($relationTableMatchFields)) {
763  $relationMatchFields = array_merge($relationTableMatchFields, $relationMatchFields);
764  }
765  $res = $this->storageBackend->removeRow($relationTableName, $relationMatchFields, FALSE);
766  return $res;
767  }
768 
777  protected function deleteRelationFromRelationtable(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $relatedObject, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $parentPropertyName) {
778  $dataMap = $this->dataMapper->getDataMap(get_class($parentObject));
779  $columnMap = $dataMap->getColumnMap($parentPropertyName);
780  $relationTableName = $columnMap->getRelationTableName();
781  $relationMatchFields = array(
782  $columnMap->getParentKeyFieldName() => (int)$parentObject->getUid(),
783  $columnMap->getChildKeyFieldName() => (int)$relatedObject->getUid()
784  );
785  $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
786  if (is_array($relationTableMatchFields)) {
787  $relationMatchFields = array_merge($relationTableMatchFields, $relationMatchFields);
788  }
789  $res = $this->storageBackend->removeRow($relationTableName, $relationMatchFields, FALSE);
790  return $res;
791  }
792 
801  protected function fetchMaxSortingFromParentTable(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $parentPropertyName) {
802  $parentDataMap = $this->dataMapper->getDataMap(get_class($parentObject));
803  $parentColumnMap = $parentDataMap->getColumnMap($parentPropertyName);
804  if ($parentColumnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_MANY) {
805  $tableName = $parentColumnMap->getChildTableName();
806  $sortByFieldName = $parentColumnMap->getChildSortByFieldName();
807 
808  if (empty($sortByFieldName)) {
809  return FALSE;
810  }
811  $matchFields = array();
812  $parentKeyFieldName = $parentColumnMap->getParentKeyFieldName();
813  if ($parentKeyFieldName !== NULL) {
814  $matchFields[$parentKeyFieldName] = $parentObject->getUid();
815  $parentTableFieldName = $parentColumnMap->getParentTableFieldName();
816  if ($parentTableFieldName !== NULL) {
817  $matchFields[$parentTableFieldName] = $parentDataMap->getTableName();
818  }
819  }
820 
821  if (empty($matchFields)) {
822  return FALSE;
823  }
824  } elseif ($parentColumnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
825  $tableName = $parentColumnMap->getRelationTableName();
826  $sortByFieldName = $parentColumnMap->getChildSortByFieldName();
827 
828  $matchFields = array(
829  $parentColumnMap->getParentKeyFieldName() => (int)$parentObject->getUid()
830  );
831 
832  $relationTableMatchFields = $parentColumnMap->getRelationTableMatchFields();
833  if (is_array($relationTableMatchFields)) {
834  $matchFields = array_merge($relationTableMatchFields, $matchFields);
835  }
836  } else {
837  throw new \TYPO3\CMS\Extbase\Persistence\Exception\IllegalRelationTypeException('Unexpected parent column relation type:' . $parentColumnMap->getTypeOfRelation(), 1345368106);
838  }
839 
840  $result = $this->storageBackend->getMaxValueFromTable(
841  $tableName,
842  $matchFields,
843  $sortByFieldName);
844  return $result;
845  }
846 
854  protected function updateObject(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, array $row) {
855  $dataMap = $this->dataMapper->getDataMap(get_class($object));
856  $this->addCommonFieldsToRow($object, $row);
857  $row['uid'] = $object->getUid();
858  if ($dataMap->getLanguageIdColumnName() !== NULL) {
859  $row[$dataMap->getLanguageIdColumnName()] = $object->_getProperty('_languageUid');
860  if ($object->_getProperty('_localizedUid') !== NULL) {
861  $row['uid'] = $object->_getProperty('_localizedUid');
862  }
863  }
864  $res = $this->storageBackend->updateRow($dataMap->getTableName(), $row);
865  if ($res === TRUE) {
866  $this->emitAfterUpdateObjectSignal($object);
867  }
868  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
869  if ($frameworkConfiguration['persistence']['updateReferenceIndex'] === '1') {
870  $this->referenceIndex->updateRefIndexTable($dataMap->getTableName(), $row['uid']);
871  }
872  return $res;
873  }
874 
881  $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterUpdateObject', array($object));
882  }
883 
891  protected function addCommonFieldsToRow(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, array &$row) {
892  $dataMap = $this->dataMapper->getDataMap(get_class($object));
893  $this->addCommonDateFieldsToRow($object, $row);
894  if ($dataMap->getRecordTypeColumnName() !== NULL && $dataMap->getRecordType() !== NULL) {
895  $row[$dataMap->getRecordTypeColumnName()] = $dataMap->getRecordType();
896  }
897  if ($object->_isNew() && !isset($row['pid'])) {
898  $row['pid'] = $this->determineStoragePageIdForNewRecord($object);
899  }
900  }
901 
909  protected function addCommonDateFieldsToRow(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, array &$row) {
910  $dataMap = $this->dataMapper->getDataMap(get_class($object));
911  if ($object->_isNew() && $dataMap->getCreationDateColumnName() !== NULL) {
912  $row[$dataMap->getCreationDateColumnName()] = $GLOBALS['EXEC_TIME'];
913  }
914  if ($dataMap->getModificationDateColumnName() !== NULL) {
915  $row[$dataMap->getModificationDateColumnName()] = $GLOBALS['EXEC_TIME'];
916  }
917  }
918 
924  protected function processDeletedObjects() {
925  foreach ($this->deletedEntities as $entity) {
926  if ($this->session->hasObject($entity)) {
927  $this->removeEntity($entity);
928  $this->session->unregisterReconstitutedEntity($entity);
929  $this->session->unregisterObject($entity);
930  }
931  }
932  $this->deletedEntities = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
933  }
934 
942  protected function removeEntity(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, $markAsDeleted = TRUE) {
943  $dataMap = $this->dataMapper->getDataMap(get_class($object));
944  $tableName = $dataMap->getTableName();
945  if ($markAsDeleted === TRUE && $dataMap->getDeletedFlagColumnName() !== NULL) {
946  $deletedColumnName = $dataMap->getDeletedFlagColumnName();
947  $row = array(
948  'uid' => $object->getUid(),
949  $deletedColumnName => 1
950  );
951  $this->addCommonDateFieldsToRow($object, $row);
952  $res = $this->storageBackend->updateRow($tableName, $row);
953  } else {
954  $res = $this->storageBackend->removeRow($tableName, array('uid' => $object->getUid()));
955  }
956  if ($res === TRUE) {
957  $this->emitAfterRemoveObjectSignal($object);
958  }
959  $this->removeRelatedObjects($object);
960  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
961  if ($frameworkConfiguration['persistence']['updateReferenceIndex'] === '1') {
962  $this->referenceIndex->updateRefIndexTable($tableName, $object->getUid());
963  }
964  }
965 
972  $this->signalSlotDispatcher->dispatch(__CLASS__, 'afterRemoveObject', array($object));
973  }
974 
981  protected function removeRelatedObjects(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object) {
982  $className = get_class($object);
983  $dataMap = $this->dataMapper->getDataMap($className);
984  $classSchema = $this->reflectionService->getClassSchema($className);
985  $properties = $object->_getProperties();
986  foreach ($properties as $propertyName => $propertyValue) {
987  $columnMap = $dataMap->getColumnMap($propertyName);
988  $propertyMetaData = $classSchema->getProperty($propertyName);
989  if ($propertyMetaData['cascade'] === 'remove') {
990  if ($columnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_MANY) {
991  foreach ($propertyValue as $containedObject) {
992  $this->removeEntity($containedObject);
993  }
994  } elseif ($propertyValue instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
995  $this->removeEntity($propertyValue);
996  }
997  }
998  }
999  }
1000 
1012  protected function determineStoragePageIdForNewRecord(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object = NULL) {
1013  $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
1014  if ($object !== NULL) {
1015  if (\TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertyGettable($object, 'pid')) {
1017  if (isset($pid)) {
1018  return (int)$pid;
1019  }
1020  }
1021  $className = get_class($object);
1022  if (isset($frameworkConfiguration['persistence']['classes'][$className]) && !empty($frameworkConfiguration['persistence']['classes'][$className]['newRecordStoragePid'])) {
1023  return (int)$frameworkConfiguration['persistence']['classes'][$className]['newRecordStoragePid'];
1024  }
1025  }
1026  $storagePidList = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $frameworkConfiguration['persistence']['storagePid']);
1027  return (int)$storagePidList[0];
1028  }
1029 
1037  protected function getPlainValue($input, $columnMap = NULL) {
1038  if ($input instanceof \DateTime) {
1039  if (!is_null($columnMap) && !is_null($columnMap->getDateTimeStorageFormat())) {
1040  if ($columnMap->getDateTimeStorageFormat() == 'datetime') {
1041  return $input->format('Y-m-d H:i:s');
1042  }
1043  if ($columnMap->getDateTimeStorageFormat() == 'date') {
1044  return $input->format('Y-m-d');
1045  }
1046  } else {
1047  return $input->format('U');
1048  }
1049  } elseif ($input instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
1050  return $input->getUid();
1051  } elseif ($input instanceof \TYPO3\CMS\Core\Type\TypeInterface) {
1052  return (string) $input;
1053  } elseif (is_bool($input)) {
1054  return $input === TRUE ? 1 : 0;
1055  } else {
1056  return $input;
1057  }
1058  return NULL;
1059  }
1060 }
setChangedEntities(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $entities)
Definition: Backend.php:286
emitBeforeGettingObjectDataSignal(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query)
Definition: Backend.php:186
updateObject(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, array $row)
Definition: Backend.php:854
fetchMaxSortingFromParentTable(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $parentPropertyName)
Definition: Backend.php:801
setDeletedObjects(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $objects)
Definition: Backend.php:317
updateRelationInRelationTable(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $propertyName, $sortingPosition=0)
Definition: Backend.php:728
emitAfterRemoveObjectSignal(DomainObjectInterface $object)
Definition: Backend.php:971
addCommonFieldsToRow(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, array &$row)
Definition: Backend.php:891
static intExplode($delimiter, $string, $removeEmptyValues=FALSE, $limit=0)
addCommonDateFieldsToRow(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, array &$row)
Definition: Backend.php:909
getObjectCountByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query)
Definition: Backend.php:162
$uid
Definition: server.php:36
emitAfterInsertObjectSignal(DomainObjectInterface $object)
Definition: Backend.php:668
attachObjectToParentObjectRelationHasMany(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\AbstractEntity $parentObject, $parentPropertyName, $sortingPosition=0)
Definition: Backend.php:548
updateRelationOfObjectToParentObject(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\AbstractEntity $parentObject, $parentPropertyName, $sortingPosition=0)
Definition: Backend.php:528
detachObjectFromParentObject(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $parentPropertyName)
Definition: Backend.php:588
emitAfterUpdateObjectSignal(DomainObjectInterface $object)
Definition: Backend.php:880
getUidOfAlreadyPersistedValueObject(\TYPO3\CMS\Extbase\DomainObject\AbstractValueObject $object)
Definition: Backend.php:678
setAggregateRootObjects(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $objects)
Definition: Backend.php:276
attachObjectToParentObject(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $parentPropertyName, $sortingPosition=0)
Definition: Backend.php:509
persistObject(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object)
Definition: Backend.php:346
determineStoragePageIdForNewRecord(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object=NULL)
Definition: Backend.php:1012
emitAfterGettingObjectDataSignal(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query, array $result)
Definition: Backend.php:198
insertRelationInRelationtable(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $propertyName, $sortingPosition=NULL)
Definition: Backend.php:691
setDeletedEntities(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $entities)
Definition: Backend.php:296
getPlainValue($input, $columnMap=NULL)
Definition: Backend.php:1037
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.
setPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager)
Definition: Backend.php:115
replaceObject($existingObject, $newObject)
Definition: Backend.php:266
__construct(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
Definition: Backend.php:104
getObjectDataByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query)
Definition: Backend.php:173
removeRelatedObjects(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object)
Definition: Backend.php:981
deleteRelationFromRelationtable(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $relatedObject, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $parentPropertyName)
Definition: Backend.php:777
deleteAllRelationsFromRelationtable(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $parentPropertyName)
Definition: Backend.php:754
getObjectByIdentifier($identifier, $className)
Definition: Backend.php:228
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getProperty($subject, $propertyName, $forceDirectAccess=FALSE)
insertObject(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject=NULL, $parentPropertyName='')
Definition: Backend.php:625
removeEntity(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, $markAsDeleted=TRUE)
Definition: Backend.php:942
getRemovedChildObjects(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object, $propertyName)
Definition: Backend.php:486