From 91e12209128a8f95f33b147275ffb5af4c916bc5 Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:26:25 +0100 Subject: [PATCH] fix: service cloning on a separate server - To be able to clone a service to a new server we need to set the server_id as well, otherwise it will be cloned on the same server. --- app/Livewire/Project/Shared/ResourceOperations.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Livewire/Project/Shared/ResourceOperations.php b/app/Livewire/Project/Shared/ResourceOperations.php index 0c79bf0aa..091ea0356 100644 --- a/app/Livewire/Project/Shared/ResourceOperations.php +++ b/app/Livewire/Project/Shared/ResourceOperations.php @@ -30,7 +30,9 @@ public function mount() $this->servers = currentTeam()->servers; } - public function cloneTo($destination_id) + public function cloneTo($destination_id) // issues is applications table stuff is replciated but not the application_settings table stuff and also application_preveiws is not replicated, Also only volumes but not files an directory mounts are cloned + + // Also the next issue is that the thing is not coloned to the correct server { $new_destination = StandaloneDocker::find($destination_id); if (! $new_destination) { @@ -41,6 +43,7 @@ public function cloneTo($destination_id) } $uuid = (string) new Cuid2; $server = $new_destination->server; + if ($this->resource->getMorphClass() === \App\Models\Application::class) { $name = 'clone-of-'.str($this->resource->name)->limit(20).'-'.$uuid; @@ -69,7 +72,7 @@ public function cloneTo($destination_id) 'id', 'created_at', 'updated_at', - 'additional_servers_count', + 'additional_servers_count', // not needed because it only is computed for the application 'additional_networks_count', ])->fill([ 'resourceable_id' => $new_resource->id, @@ -169,7 +172,10 @@ public function cloneTo($destination_id) 'uuid' => $uuid, 'name' => $this->resource->name.'-clone-'.$uuid, 'destination_id' => $new_destination->id, + 'destination_type' => $new_destination->getMorphClass(), + 'server_id' => $new_destination->server_id, // server_id is probably not needed anymore because of the new polymorphic relationships (here it is needed for clone to work - but maybe we can drop the column) ]); + $new_resource->save(); foreach ($new_resource->applications() as $application) { $application->update([