refactor(clone): enhance application cloning by separating production and preview environment variable handling
This commit is contained in:
@@ -317,9 +317,10 @@ function clone_application(Application $source, $destination, array $overrides =
|
|||||||
$newStorage->save();
|
$newStorage->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clone environment variables
|
// Clone production environment variables without triggering the created hook
|
||||||
$environmentVariables = $source->environment_variables()->get();
|
$environmentVariables = $source->environment_variables()->get();
|
||||||
foreach ($environmentVariables as $environmentVariable) {
|
foreach ($environmentVariables as $environmentVariable) {
|
||||||
|
\App\Models\EnvironmentVariable::withoutEvents(function () use ($environmentVariable, $newApplication) {
|
||||||
$newEnvironmentVariable = $environmentVariable->replicate([
|
$newEnvironmentVariable = $environmentVariable->replicate([
|
||||||
'id',
|
'id',
|
||||||
'created_at',
|
'created_at',
|
||||||
@@ -327,8 +328,27 @@ function clone_application(Application $source, $destination, array $overrides =
|
|||||||
])->fill([
|
])->fill([
|
||||||
'resourceable_id' => $newApplication->id,
|
'resourceable_id' => $newApplication->id,
|
||||||
'resourceable_type' => $newApplication->getMorphClass(),
|
'resourceable_type' => $newApplication->getMorphClass(),
|
||||||
|
'is_preview' => false,
|
||||||
]);
|
]);
|
||||||
$newEnvironmentVariable->save();
|
$newEnvironmentVariable->save();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone preview environment variables
|
||||||
|
$previewEnvironmentVariables = $source->environment_variables_preview()->get();
|
||||||
|
foreach ($previewEnvironmentVariables as $previewEnvironmentVariable) {
|
||||||
|
\App\Models\EnvironmentVariable::withoutEvents(function () use ($previewEnvironmentVariable, $newApplication) {
|
||||||
|
$newPreviewEnvironmentVariable = $previewEnvironmentVariable->replicate([
|
||||||
|
'id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
])->fill([
|
||||||
|
'resourceable_id' => $newApplication->id,
|
||||||
|
'resourceable_type' => $newApplication->getMorphClass(),
|
||||||
|
'is_preview' => true,
|
||||||
|
]);
|
||||||
|
$newPreviewEnvironmentVariable->save();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return $newApplication;
|
return $newApplication;
|
||||||
|
Reference in New Issue
Block a user