Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Sortable/SortableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,18 @@ protected function processDeletion(SortableAdapter $ea, array $config, $meta, $o
// Get groups
$groups = $this->getGroups($meta, $config, $object);

// Check if any group entities are scheduled for deletion
// If the parent entity is being deleted, there's no point in reorganizing positions
// and it would cause errors trying to bind entities without identifiers
$em = $ea->getObjectManager();
$uow = $em->getUnitOfWork();
foreach ($groups as $val) {
if (is_object($val) && $uow->isScheduledForDelete($val)) {
// Skip relocation - parent entity is being deleted anyway
return;
}
}

// Get hash
$hash = $this->getHash($groups, $config);

Expand Down Expand Up @@ -654,8 +666,10 @@ protected function getMaxPosition(SortableAdapter $ea, $meta, $config, $object,
// Check for groups that are associations. If the value is an object and is
// scheduled for insert, it has no identifier yet and is obviously new
// see issue #226
// Also check if the group entity is scheduled for deletion - if so, we should
// skip position updates as the parent and all children are being deleted
foreach ($groups as $val) {
if (is_object($val) && ($uow->isScheduledForInsert($val) || !$em->getMetadataFactory()->isTransient(ClassUtils::getClass($val)) && $uow::STATE_MANAGED !== $ea->getObjectState($uow, $val))) {
if (is_object($val) && ($uow->isScheduledForInsert($val) || $uow->isScheduledForDelete($val) || !$em->getMetadataFactory()->isTransient(ClassUtils::getClass($val)) && $uow::STATE_MANAGED !== $ea->getObjectState($uow, $val))) {
return -1;
}
}
Expand Down