39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Admin\Actions\DeleteParentGroup;
|
|
|
|
class DeleteParentGroupAction
|
|
{
|
|
public function __construct(private DeleteParentGroupRequest $request)
|
|
{
|
|
}
|
|
|
|
public function execute(): DeleteParentGroupResponse
|
|
{
|
|
$response = new DeleteParentGroupResponse();
|
|
|
|
// Die Fallback-Gruppe nimmt Mandanten ohne Zuordnung auf und muss deshalb bestehen bleiben.
|
|
if ($this->request->parentGroup->is_fallback) {
|
|
$response->message = sprintf('„%s" kann nicht gelöscht werden.', $this->request->parentGroup->name);
|
|
|
|
return $response;
|
|
}
|
|
|
|
if ($this->request->inUse) {
|
|
$response->message = sprintf(
|
|
'„%s" ist noch zugeordnet und kann deshalb nicht gelöscht werden.',
|
|
$this->request->parentGroup->name,
|
|
);
|
|
|
|
return $response;
|
|
}
|
|
|
|
$this->request->parentGroup->delete();
|
|
|
|
$response->success = true;
|
|
$response->message = sprintf('„%s" wurde gelöscht.', $this->request->parentGroup->name);
|
|
|
|
return $response;
|
|
}
|
|
}
|