Add force delete for servers

This commit is contained in:
notCharles 2024-04-23 20:03:57 -04:00
parent 07244c38eb
commit 7bbbba37f5
2 changed files with 8 additions and 1 deletions

View File

@ -590,11 +590,17 @@ class EditServer extends EditRecord
protected function getHeaderActions(): array protected function getHeaderActions(): array
{ {
return [ return [
Actions\Action::make('Force Delete')
->successRedirectUrl($this->getResource()::getUrl('index'))
->color('danger')
->action(fn (Server $server) => resolve(ServerDeletionService::class)->withForce()->handle($server))
->requiresConfirmation(),
Actions\Action::make('Delete') Actions\Action::make('Delete')
->successRedirectUrl($this->getResource()::getUrl('index')) ->successRedirectUrl($this->getResource()::getUrl('index'))
->color('danger') ->color('danger')
->action(fn (Server $server) => resolve(ServerDeletionService::class)->handle($server)) ->action(fn (Server $server) => resolve(ServerDeletionService::class)->handle($server))
->requiresConfirmation(), ->requiresConfirmation(),
]; ];
} }
} }

View File

@ -2,6 +2,7 @@
namespace App\Services\Servers; namespace App\Services\Servers;
use Exception;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use App\Models\Server; use App\Models\Server;
use Illuminate\Database\ConnectionInterface; use Illuminate\Database\ConnectionInterface;
@ -43,7 +44,7 @@ class ServerDeletionService
{ {
try { try {
$this->daemonServerRepository->setServer($server)->delete(); $this->daemonServerRepository->setServer($server)->delete();
} catch (DaemonConnectionException $exception) { } catch (Exception $exception) {
// If there is an error not caused a 404 error and this isn't a forced delete, // If there is an error not caused a 404 error and this isn't a forced delete,
// go ahead and bail out. We specifically ignore a 404 since that can be assumed // go ahead and bail out. We specifically ignore a 404 since that can be assumed
// to be a safe error, meaning the server doesn't exist at all on daemon so there // to be a safe error, meaning the server doesn't exist at all on daemon so there