Merge pull request 'chore: improve delete' (#10) from chore/improve-delete into main
Some checks failed
Renovate / renovate (push) Failing after 1m19s

Reviewed-on: #10
This commit was merged in pull request #10.
This commit is contained in:
2026-04-26 01:53:46 +00:00

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);