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'))); $deleteMode = strtolower(trim((string) ($this->getAuxiliary()['deleteMode'] ?? 'soft')));
if ($deleteMode === 'soft') { if ($deleteMode === 'soft') {
$deleteDestination = $this->getAuxiliary()['deleteDestination'] ?? null; $filter = $this->collectionListFilter();
if (is_string($deleteDestination) || is_int($deleteDestination)) { $filter->condition('role', 'trash');
$deleteDestination = trim((string) $deleteDestination); $targets = $this->collectionList(null, $filter);
if ($deleteDestination === '') {
$deleteDestination = null; if (empty($targets)) {
} throw new \RuntimeException('No trash collection found for soft delete');
} else {
$deleteDestination = null;
} }
if ($deleteDestination === null) { return $this->mailService->entityMove(reset($targets)->identifier(), ...$ids);
$filter = $this->collectionListFilter();
$filter->condition(self::CAPABILITY_COLLECTION_FILTER_ROLE, CollectionRoles::Trash->value);
foreach ($this->collectionList(null, $filter) as $collection) {
if (!$collection instanceof CollectionBaseInterface) {
continue;
}
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->entityDelete(...$ids); return $this->mailService->entityDelete(...$ids);