An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix(destination): promote networks atomically
Andras Bacsai8e033c5bc3aa
diff --git a/app/Livewire/Project/Shared/Destination.php b/app/Livewire/Project/Shared/Destination.phpindex 79892d4c6c..bab5c59b0c 100644--- a/app/Livewire/Project/Shared/Destination.php+++ b/app/Livewire/Project/Shared/Destination.php@@ -8,6 +8,7 @@ use App\Events\ApplicationStatusChanged;use App\Models\Server;use App\Models\StandaloneDocker;use Illuminate\Support\Collection;+use Illuminate\Support\Facades\DB;use Livewire\Component;use Visus\Cuid2\Cuid2;@@ -115,15 +116,17 @@ class Destination extends Component$network = StandaloneDocker::ownedByCurrentTeam()->where('server_id', $server->id)->findOrFail($network_id);$this->authorize('update', $this->resource);- $main_destination = $this->resource->destination;- $this->resource->update([- 'destination_id' => $network->id,- 'destination_type' => StandaloneDocker::class,- ]);- $this->resource->additional_networks()->detach($network->id, ['server_id' => $server->id]);- $this->resource->additional_networks()->attach($main_destination->id, ['server_id' => $main_destination->server->id]);- $this->refreshServers();- $this->resource->refresh();+ DB::transaction(function () use ($network, $server) {+ $main_destination = $this->resource->destination;+ $this->resource->update([+ 'destination_id' => $network->id,+ 'destination_type' => StandaloneDocker::class,+ ]);+ $this->resource->additional_networks()->detach($network->id, ['server_id' => $server->id]);+ $this->resource->additional_networks()->attach($main_destination->id, ['server_id' => $main_destination->server->id]);+ $this->refreshServers();+ $this->resource->refresh();+ });} catch (\Exception $e) {return handleError($e, $this);}diff --git a/tests/Feature/CrossTeamDestinationAttachTest.php b/tests/Feature/CrossTeamDestinationAttachTest.phpindex 3bd1511526..e90c8334ce 100644--- a/tests/Feature/CrossTeamDestinationAttachTest.php+++ b/tests/Feature/CrossTeamDestinationAttachTest.php@@ -143,4 +143,19 @@ describe('Destination::promote GHSA-j395-3pqh-9r5g', function () {expect($this->applicationA->fresh()->destination_id)->toBe($originalDestinationId);});++ test('can promote own team network and preserve previous main as additional network', function () {+ $this->applicationA->additional_networks()->attach($this->destinationA2->id, ['server_id' => $this->serverA2->id]);++ Livewire::test(Destination::class, ['resource' => $this->applicationA])+ ->call('promote', $this->destinationA2->id, $this->serverA2->id);++ $application = $this->applicationA->fresh();+ $additional = $application->additional_networks;++ expect($application->destination_id)->toBe($this->destinationA2->id);+ expect($additional)->toHaveCount(1);+ expect($additional->first()->id)->toBe($this->destinationA->id);+ expect($additional->first()->pivot->server_id)->toBe($this->serverA->id);+ });});