[BUGFIX] Remove relations from MM table 80/51080/2
authorNicole Cordes <typo3@cordes.co>
Fri, 7 Oct 2016 11:58:00 +0000 (13:58 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 31 Dec 2016 14:41:03 +0000 (15:41 +0100)
If extbase deletes an object it doesn't delete its relations in an
MM table. This patch adds the check for a possible MM relation table and
ensures all relations get deleted as well. If the parent table supports
a deleted flag, no relations will be deleted to be able to restore the
parent record again.

Resolves: #78128
Releases: master, 7.6
Change-Id: Ibe2497c05838e261f9c67a80216385d6e60607cb
Reviewed-on: https://review.typo3.org/51080
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php

index 19ae08f..8431071 100644 (file)
@@ -1092,6 +1092,9 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
         $properties = $object->_getProperties();
         foreach ($properties as $propertyName => $propertyValue) {
             $columnMap = $dataMap->getColumnMap($propertyName);
+            if ($columnMap === null) {
+                continue;
+            }
             $propertyMetaData = $classSchema->getProperty($propertyName);
             if ($propertyMetaData['cascade'] === 'remove') {
                 if ($columnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_MANY) {
@@ -1101,6 +1104,10 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                 } elseif ($propertyValue instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) {
                     $this->removeEntity($propertyValue);
                 }
+            } elseif ($dataMap->getDeletedFlagColumnName() === null
+                && $columnMap->getTypeOfRelation() === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY
+            ) {
+                $this->deleteAllRelationsFromRelationtable($object, $propertyName);
             }
         }
     }