chore: improve delete
All checks were successful
Build Test / test (pull_request) Successful in 27s
JS Unit Tests / test (pull_request) Successful in 26s
PHP Unit Tests / test (pull_request) Successful in 1m19s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-04-25 21:52:48 -04:00
parent b1b3ee33cd
commit 1220e9e8ab

View File

@@ -553,37 +553,15 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
$deleteMode = strtolower(trim((string) ($this->getAuxiliary()['deleteMode'] ?? 'soft')));
if ($deleteMode === 'soft') {
$deleteDestination = $this->getAuxiliary()['deleteDestination'] ?? null;
if (is_string($deleteDestination) || is_int($deleteDestination)) {
$deleteDestination = trim((string) $deleteDestination);
if ($deleteDestination === '') {
$deleteDestination = null;
}
} else {
$deleteDestination = null;
}
if ($deleteDestination === null) {
$filter = $this->collectionListFilter();
$filter->condition(self::CAPABILITY_COLLECTION_FILTER_ROLE, CollectionRoles::Trash->value);
$filter->condition('role', 'trash');
$targets = $this->collectionList(null, $filter);
foreach ($this->collectionList(null, $filter) as $collection) {
if (!$collection instanceof CollectionBaseInterface) {
continue;
if (empty($targets)) {
throw new \RuntimeException('No trash collection found for soft delete');
}
if ($collection->getProperties()->getRole() === CollectionRoles::Trash) {
$deleteDestination = (string) $collection->identifier();
break;
}
}
}
if ($deleteDestination === null) {
throw new \RuntimeException('Soft delete is enabled but no trash collection could be resolved.');
}
return $this->mailService->entityMove($deleteDestination, ...$ids);
return $this->mailService->entityMove(reset($targets)->identifier(), ...$ids);
}
return $this->mailService->entityDelete(...$ids);