Skip to content

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.

refactor(clone): integrate preview cloning logic directly into application cloning function for improved clarity and maintainability

Andras Bacsai6ed2fd5d663f
diff --git a/bootstrap/helpers/applications.php b/bootstrap/helpers/applications.php
index 2ae641a2b1..ca34875d82 100644
--- a/bootstrap/helpers/applications.php
+++ b/bootstrap/helpers/applications.php
@@ -238,7 +238,28 @@ function clone_application(Application $source, $destination, array $overrides =
}
// Clone previews with FQDN regeneration
- clone_application_previews($source, $newApplication);
+ $applicationPreviews = $source->previews()->get();
+ foreach ($applicationPreviews as $preview) {
+ $newPreview = $preview->replicate([
+ 'id',
+ 'created_at',
+ 'updated_at',
+ ])->fill([
+ 'uuid' => (string) new Cuid2,
+ 'application_id' => $newApplication->id,
+ 'status' => 'exited',
+ 'fqdn' => null,
+ 'docker_compose_domains' => null,
+ ]);
+ $newPreview->save();
+
+ // Regenerate FQDN for the cloned preview
+ if ($newApplication->build_pack === 'dockercompose') {
+ $newPreview->generate_preview_fqdn_compose();
+ } else {
+ $newPreview->generate_preview_fqdn();
+ }
+ }
// Clone persistent volumes
$persistentVolumes = $source->persistentStorages()->get();
@@ -312,29 +333,3 @@ function clone_application(Application $source, $destination, array $overrides =
return $newApplication;
}
-
-function clone_application_previews(Application $sourceApplication, Application $targetApplication): void
-{
- $applicationPreviews = $sourceApplication->previews()->get();
- foreach ($applicationPreviews as $preview) {
- $newPreview = $preview->replicate([
- 'id',
- 'created_at',
- 'updated_at',
- ])->fill([
- 'uuid' => (string) new Cuid2,
- 'application_id' => $targetApplication->id,
- 'status' => 'exited',
- 'fqdn' => null,
- 'docker_compose_domains' => null,
- ]);
- $newPreview->save();
-
- // Regenerate FQDN for the cloned preview
- if ($targetApplication->build_pack === 'dockercompose') {
- $newPreview->generate_preview_fqdn_compose();
- } else {
- $newPreview->generate_preview_fqdn();
- }
- }
-}