Skip to content

Commit

Permalink
Forcibly remove all *:n relations before import
Browse files Browse the repository at this point in the history
Unfortunately, due to the way Extbase persistence works
with references that get removed, deletion of the M:N
record does not always occur. This means that there can
be leftover relations if an entity was previously imported
with more/different relations and then imported again with
new/updated relations. Most prominently a concern with
sys_file_reference which masquerades as M:N but is not
really an M:N with cascading flushes.
  • Loading branch information
NamelessCoder committed Feb 26, 2018
1 parent 8712b7c commit 1b6e598
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Classes/Mapping/AbstractMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ protected function mapPropertyValueToObject($propertyName, $propertyValue, $obje
$childType = substr($targetType, strpos($targetType, '<') + 1, -1);
$childType = trim($childType, '\\');
$objectStorage = ObjectAccess::getProperty($object, $propertyName) ?? new ObjectStorage();
// Step one is to detach all currently related objects. Please note that $objectStorage->removeAll($objectStorage)
// does not work due to array pointer reset issues with Iterators. The only functioning way is to iterate and
// detach all, one by one, as below.
foreach ($objectStorage->toArray() as $item) {
$objectStorage->detach($item);
}

foreach ((array) $propertyValue as $identifier) {
if (!$identifier) {
continue;
Expand Down

0 comments on commit 1b6e598

Please sign in to comment.