chore: improve delete #10
@@ -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;
|
||||
$filter = $this->collectionListFilter();
|
||||
$filter->condition('role', 'trash');
|
||||
$targets = $this->collectionList(null, $filter);
|
||||
|
||||
if (empty($targets)) {
|
||||
throw new \RuntimeException('No trash collection found for soft delete');
|
||||
}
|
||||
|
||||
if ($deleteDestination === null) {
|
||||
$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->entityMove(reset($targets)->identifier(), ...$ids);
|
||||
}
|
||||
|
||||
return $this->mailService->entityDelete(...$ids);
|
||||
|
||||
Reference in New Issue
Block a user