From 5a7b16ea5fec95f4dea0dc2e9e2ec968d72a897f Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 11 Oct 2023 14:04:21 +0200 Subject: [PATCH] command: delete server --- app/Console/Commands/ResourcesDelete.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/ResourcesDelete.php b/app/Console/Commands/ResourcesDelete.php index c9ad0f0e9..2b71cee89 100644 --- a/app/Console/Commands/ResourcesDelete.php +++ b/app/Console/Commands/ResourcesDelete.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use App\Models\Application; +use App\Models\Server; use App\Models\Service; use App\Models\StandalonePostgresql; use Illuminate\Console\Command; @@ -34,7 +35,7 @@ public function handle() { $resource = select( 'What resource do you want to delete?', - ['Application', 'Database', 'Service'], + ['Application', 'Database', 'Service', 'Server'], ); if ($resource === 'Application') { $this->deleteApplication(); @@ -42,6 +43,27 @@ public function handle() $this->deleteDatabase(); } elseif ($resource === 'Service') { $this->deleteService(); + } elseif($resource === 'Server') { + $this->deleteServer(); + } + } + private function deleteServer() { + $servers = Server::all(); + if ($servers->count() === 0) { + $this->error('There are no applications to delete.'); + return; + } + $serversToDelete = multiselect( + 'What server do you want to delete?', + $servers->pluck('id')->toArray(), + ); + $confirmed = confirm("Are you sure you want to delete all selected resources?"); + if (!$confirmed) { + return; + } + foreach ($serversToDelete as $server) { + $toDelete = $servers->where('id', $server)->first(); + $toDelete->delete(); } } private function deleteApplication()