diff --git a/app/Livewire/Project/Service/Configuration.php b/app/Livewire/Project/Service/Configuration.php index da49dcae9..20067b1f9 100644 --- a/app/Livewire/Project/Service/Configuration.php +++ b/app/Livewire/Project/Service/Configuration.php @@ -31,8 +31,9 @@ class Configuration extends Component return [ "echo-private:user.{$userId},ServiceStatusChanged" => 'check_status', - 'check_status', 'refreshStatus' => '$refresh', + 'check_status', + 'refreshServices', ]; } @@ -63,6 +64,13 @@ class Configuration extends Component $this->databases = $this->service->databases->sort(); } + public function refreshServices() + { + $this->service->refresh(); + $this->applications = $this->service->applications->sort(); + $this->databases = $this->service->databases->sort(); + } + public function restartApplication($id) { try { diff --git a/app/Livewire/Project/Service/Database.php b/app/Livewire/Project/Service/Database.php index c3b7577e9..28e3d3a26 100644 --- a/app/Livewire/Project/Service/Database.php +++ b/app/Livewire/Project/Service/Database.php @@ -6,6 +6,7 @@ use App\Actions\Database\StartDatabaseProxy; use App\Actions\Database\StopDatabaseProxy; use App\Models\InstanceSettings; use App\Models\ServiceDatabase; +use DB; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Livewire\Component; @@ -83,6 +84,33 @@ class Database extends Component $this->dispatch('success', 'You need to restart the service for the changes to take effect.'); } + public function convertToApplication() + { + try { + $service = $this->database->service; + $serviceDatabase = $this->database; + DB::beginTransaction(); + $service->applications()->create([ + 'name' => $serviceDatabase->name, + 'human_name' => $serviceDatabase->human_name, + 'description' => $serviceDatabase->description, + 'exclude_from_status' => $serviceDatabase->exclude_from_status, + 'is_log_drain_enabled' => $serviceDatabase->is_log_drain_enabled, + 'image' => $serviceDatabase->image, + 'service_id' => $service->id, + ]); + $serviceDatabase->delete(); + DB::commit(); + + return redirect()->route('project.service.configuration', $this->parameters); + } catch (\Throwable $e) { + DB::rollBack(); + dd($e); + + return handleError($e, $this); + } + } + public function instantSave() { if ($this->database->is_public && ! $this->database->public_port) { diff --git a/app/Livewire/Project/Service/ServiceApplicationView.php b/app/Livewire/Project/Service/ServiceApplicationView.php index f1d08ee13..24f218057 100644 --- a/app/Livewire/Project/Service/ServiceApplicationView.php +++ b/app/Livewire/Project/Service/ServiceApplicationView.php @@ -4,6 +4,7 @@ namespace App\Livewire\Project\Service; use App\Models\InstanceSettings; use App\Models\ServiceApplication; +use DB; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Livewire\Component; @@ -73,6 +74,32 @@ class ServiceApplicationView extends Component $this->parameters = get_route_parameters(); } + public function convertToDatabase() + { + try { + $service = $this->application->service; + $serviceApplication = $this->application; + DB::beginTransaction(); + $service->databases()->create([ + 'name' => $serviceApplication->name, + 'human_name' => $serviceApplication->human_name, + 'description' => $serviceApplication->description, + 'exclude_from_status' => $serviceApplication->exclude_from_status, + 'is_log_drain_enabled' => $serviceApplication->is_log_drain_enabled, + 'image' => $serviceApplication->image, + 'service_id' => $service->id, + ]); + $serviceApplication->delete(); + DB::commit(); + + return redirect()->route('project.service.configuration', $this->parameters); + } catch (\Throwable $e) { + DB::rollBack(); + + return handleError($e, $this); + } + } + public function submit() { try { diff --git a/app/Livewire/Project/Service/StackForm.php b/app/Livewire/Project/Service/StackForm.php index 368598466..a67bd9210 100644 --- a/app/Livewire/Project/Service/StackForm.php +++ b/app/Livewire/Project/Service/StackForm.php @@ -82,6 +82,7 @@ class StackForm extends Component $this->service->refresh(); $this->service->saveComposeConfigs(); $this->dispatch('refreshEnvs'); + $this->dispatch('refreshServices'); $notify && $this->dispatch('success', 'Service saved.'); } catch (\Throwable $e) { return handleError($e, $this); diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 44e20c9b3..8b2d9fb6a 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -2990,12 +2990,12 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int $applicationFound = ServiceApplication::where('name', $serviceName)->where('service_id', $resource->id)->first(); if ($applicationFound) { $savedService = $applicationFound; - $savedService = ServiceDatabase::firstOrCreate([ - 'name' => $applicationFound->name, - 'image' => $applicationFound->image, - 'service_id' => $applicationFound->service_id, - ]); - $applicationFound->delete(); + // $savedService = ServiceDatabase::firstOrCreate([ + // 'name' => $applicationFound->name, + // 'image' => $applicationFound->image, + // 'service_id' => $applicationFound->service_id, + // ]); + // $applicationFound->delete(); } else { $savedService = ServiceDatabase::firstOrCreate([ 'name' => $serviceName, @@ -3248,12 +3248,12 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int $applicationFound = ServiceApplication::where('name', $serviceName)->where('image', $image)->where('service_id', $resource->id)->first(); if ($applicationFound) { $savedService = $applicationFound; - $savedService = ServiceDatabase::firstOrCreate([ - 'name' => $applicationFound->name, - 'image' => $applicationFound->image, - 'service_id' => $applicationFound->service_id, - ]); - $applicationFound->delete(); + // $savedService = ServiceDatabase::firstOrCreate([ + // 'name' => $applicationFound->name, + // 'image' => $applicationFound->image, + // 'service_id' => $applicationFound->service_id, + // ]); + // $applicationFound->delete(); } else { $savedService = ServiceDatabase::firstOrCreate([ 'name' => $serviceName, diff --git a/resources/views/livewire/project/service/configuration.blade.php b/resources/views/livewire/project/service/configuration.blade.php index 1e287356b..15ab6fbde 100644 --- a/resources/views/livewire/project/service/configuration.blade.php +++ b/resources/views/livewire/project/service/configuration.blade.php @@ -39,7 +39,7 @@