From 8f5b08493182203f6d387c95ca6e287daf86c797 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 9 Nov 2023 12:40:53 +0100 Subject: [PATCH] Refactor environment variable saving logic. --- .../Project/Shared/EnvironmentVariable/All.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php index b1fa237e0..3f8b73f7b 100644 --- a/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php +++ b/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php @@ -55,12 +55,17 @@ public function saveVariables($isPreview) { if ($isPreview) { $variables = parseEnvFormatToArray($this->variablesPreview); + $this->resource->environment_variables_preview()->whereNotIn('key', array_keys($variables))->delete(); } else { $variables = parseEnvFormatToArray($this->variables); + $this->resource->environment_variables()->whereNotIn('key', array_keys($variables))->delete(); } foreach ($variables as $key => $variable) { - $found = $this->resource->environment_variables()->where('key', $key)->first(); - $foundPreview = $this->resource->environment_variables_preview()->where('key', $key)->first(); + if ($isPreview) { + $found = $this->resource->environment_variables_preview()->where('key', $key)->first(); + } else { + $found = $this->resource->environment_variables()->where('key', $key)->first(); + } if ($found) { if ($found->is_shown_once) { continue; @@ -68,14 +73,6 @@ public function saveVariables($isPreview) $found->value = $variable; $found->save(); continue; - } - if ($foundPreview) { - if ($foundPreview->is_shown_once) { - continue; - } - $foundPreview->value = $variable; - $foundPreview->save(); - continue; } else { $environment = new EnvironmentVariable(); $environment->key = $key;