Refactor EnvironmentVariable creation logic

This commit is contained in:
Andras Bacsai 2024-04-02 15:40:19 +02:00
parent db5d7857c8
commit fd9dae6e4b

View File

@ -25,19 +25,18 @@ class EnvironmentVariable extends Model
static::created(function (EnvironmentVariable $environment_variable) { static::created(function (EnvironmentVariable $environment_variable) {
if ($environment_variable->application_id && !$environment_variable->is_preview) { if ($environment_variable->application_id && !$environment_variable->is_preview) {
$found = ModelsEnvironmentVariable::where('key', $environment_variable->key)->where('application_id', $environment_variable->application_id)->where('is_preview', true)->first(); $found = ModelsEnvironmentVariable::where('key', $environment_variable->key)->where('application_id', $environment_variable->application_id)->where('is_preview', true)->first();
$application = Application::find($environment_variable->application_id);
if ($application->build_pack === 'dockerfile') {
return;
}
if (!$found) { if (!$found) {
ModelsEnvironmentVariable::create([ $application = Application::find($environment_variable->application_id);
'key' => $environment_variable->key, if ($application->build_pack !== 'dockerfile') {
'value' => $environment_variable->value, ModelsEnvironmentVariable::create([
'is_build_time' => $environment_variable->is_build_time, 'key' => $environment_variable->key,
'is_multiline' => $environment_variable->is_multiline, 'value' => $environment_variable->value,
'application_id' => $environment_variable->application_id, 'is_build_time' => $environment_variable->is_build_time,
'is_preview' => true 'is_multiline' => $environment_variable->is_multiline,
]); 'application_id' => $environment_variable->application_id,
'is_preview' => true
]);
}
} }
} }
$environment_variable->update([ $environment_variable->update([