fix: implement all the cloneMe changes for ResourceOperations as well
This commit is contained in:
@@ -30,9 +30,7 @@ class ResourceOperations extends Component
|
|||||||
$this->servers = currentTeam()->servers;
|
$this->servers = currentTeam()->servers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cloneTo($destination_id) // issues is applications table stuff is replciated but not the application_settings table stuff and also application_preveiws is not replicated, Also only volumes but not files an directory mounts are cloned
|
public function cloneTo($destination_id)
|
||||||
|
|
||||||
// Also the next issue is that the thing is not coloned to the correct server
|
|
||||||
{
|
{
|
||||||
$new_destination = StandaloneDocker::find($destination_id);
|
$new_destination = StandaloneDocker::find($destination_id);
|
||||||
if (! $new_destination) {
|
if (! $new_destination) {
|
||||||
@@ -46,6 +44,12 @@ class ResourceOperations extends Component
|
|||||||
|
|
||||||
if ($this->resource->getMorphClass() === \App\Models\Application::class) {
|
if ($this->resource->getMorphClass() === \App\Models\Application::class) {
|
||||||
$name = 'clone-of-'.str($this->resource->name)->limit(20).'-'.$uuid;
|
$name = 'clone-of-'.str($this->resource->name)->limit(20).'-'.$uuid;
|
||||||
|
$applicationSettings = $this->resource->settings;
|
||||||
|
$url = $this->resource->fqdn;
|
||||||
|
|
||||||
|
if ($server->proxyType() !== 'NONE' && $applicationSettings->is_container_label_readonly_enabled === true) {
|
||||||
|
$url = generateFqdn($server, $uuid);
|
||||||
|
}
|
||||||
|
|
||||||
$new_resource = $this->resource->replicate([
|
$new_resource = $this->resource->replicate([
|
||||||
'id',
|
'id',
|
||||||
@@ -56,28 +60,62 @@ class ResourceOperations extends Component
|
|||||||
])->fill([
|
])->fill([
|
||||||
'uuid' => $uuid,
|
'uuid' => $uuid,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'fqdn' => generateFqdn($server, $uuid),
|
'fqdn' => $url,
|
||||||
'status' => 'exited',
|
'status' => 'exited',
|
||||||
'destination_id' => $new_destination->id,
|
'destination_id' => $new_destination->id,
|
||||||
]);
|
]);
|
||||||
$new_resource->save();
|
$new_resource->save();
|
||||||
if ($new_resource->destination->server->proxyType() !== 'NONE') {
|
|
||||||
|
if ($new_resource->destination->server->proxyType() !== 'NONE' && $applicationSettings->is_container_label_readonly_enabled === true) {
|
||||||
$customLabels = str(implode('|coolify|', generateLabelsApplication($new_resource)))->replace('|coolify|', "\n");
|
$customLabels = str(implode('|coolify|', generateLabelsApplication($new_resource)))->replace('|coolify|', "\n");
|
||||||
$new_resource->custom_labels = base64_encode($customLabels);
|
$new_resource->custom_labels = base64_encode($customLabels);
|
||||||
$new_resource->save();
|
$new_resource->save();
|
||||||
}
|
}
|
||||||
$environmentVaribles = $this->resource->environment_variables()->get();
|
|
||||||
foreach ($environmentVaribles as $environmentVarible) {
|
$new_resource->settings()->delete();
|
||||||
$newEnvironmentVariable = $environmentVarible->replicate([
|
if ($applicationSettings) {
|
||||||
|
$newApplicationSettings = $applicationSettings->replicate([
|
||||||
'id',
|
'id',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
])->fill([
|
])->fill([
|
||||||
'resourceable_id' => $new_resource->id,
|
'application_id' => $new_resource->id,
|
||||||
'resourceable_type' => $new_resource->getMorphClass(),
|
|
||||||
]);
|
]);
|
||||||
$newEnvironmentVariable->save();
|
$newApplicationSettings->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$tags = $this->resource->tags;
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$new_resource->tags()->attach($tag->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$scheduledTasks = $this->resource->scheduled_tasks()->get();
|
||||||
|
foreach ($scheduledTasks as $task) {
|
||||||
|
$newTask = $task->replicate([
|
||||||
|
'id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
])->fill([
|
||||||
|
'uuid' => (string) new Cuid2,
|
||||||
|
'application_id' => $new_resource->id,
|
||||||
|
'team_id' => currentTeam()->id,
|
||||||
|
]);
|
||||||
|
$newTask->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
$applicationPreviews = $this->resource->previews()->get();
|
||||||
|
foreach ($applicationPreviews as $preview) {
|
||||||
|
$newPreview = $preview->replicate([
|
||||||
|
'id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
])->fill([
|
||||||
|
'application_id' => $new_resource->id,
|
||||||
|
'status' => 'exited',
|
||||||
|
]);
|
||||||
|
$newPreview->save();
|
||||||
|
}
|
||||||
|
|
||||||
$persistentVolumes = $this->resource->persistentStorages()->get();
|
$persistentVolumes = $this->resource->persistentStorages()->get();
|
||||||
foreach ($persistentVolumes as $volume) {
|
foreach ($persistentVolumes as $volume) {
|
||||||
$volumeName = str($volume->name)->replace($this->resource->uuid, $new_resource->uuid)->value();
|
$volumeName = str($volume->name)->replace($this->resource->uuid, $new_resource->uuid)->value();
|
||||||
@@ -94,6 +132,32 @@ class ResourceOperations extends Component
|
|||||||
]);
|
]);
|
||||||
$newPersistentVolume->save();
|
$newPersistentVolume->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$fileStorages = $this->resource->fileStorages()->get();
|
||||||
|
foreach ($fileStorages as $storage) {
|
||||||
|
$newStorage = $storage->replicate([
|
||||||
|
'id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
])->fill([
|
||||||
|
'resource_id' => $new_resource->id,
|
||||||
|
]);
|
||||||
|
$newStorage->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
$environmentVaribles = $this->resource->environment_variables()->get();
|
||||||
|
foreach ($environmentVaribles as $environmentVarible) {
|
||||||
|
$newEnvironmentVariable = $environmentVarible->replicate([
|
||||||
|
'id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
])->fill([
|
||||||
|
'resourceable_id' => $new_resource->id,
|
||||||
|
'resourceable_type' => $new_resource->getMorphClass(),
|
||||||
|
]);
|
||||||
|
$newEnvironmentVariable->save();
|
||||||
|
}
|
||||||
|
|
||||||
$route = route('project.application.configuration', [
|
$route = route('project.application.configuration', [
|
||||||
'project_uuid' => $this->projectUuid,
|
'project_uuid' => $this->projectUuid,
|
||||||
'environment_uuid' => $this->environmentUuid,
|
'environment_uuid' => $this->environmentUuid,
|
||||||
@@ -124,20 +188,85 @@ class ResourceOperations extends Component
|
|||||||
'destination_id' => $new_destination->id,
|
'destination_id' => $new_destination->id,
|
||||||
]);
|
]);
|
||||||
$new_resource->save();
|
$new_resource->save();
|
||||||
|
|
||||||
|
$tags = $this->resource->tags;
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$new_resource->tags()->attach($tag->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$new_resource->persistentStorages()->delete();
|
||||||
|
$persistentVolumes = $this->resource->persistentStorages()->get();
|
||||||
|
foreach ($persistentVolumes as $volume) {
|
||||||
|
$originalName = $volume->name;
|
||||||
|
$newName = '';
|
||||||
|
|
||||||
|
if (str_starts_with($originalName, 'postgres-data-')) {
|
||||||
|
$newName = 'postgres-data-'.$new_resource->uuid;
|
||||||
|
} elseif (str_starts_with($originalName, 'mysql-data-')) {
|
||||||
|
$newName = 'mysql-data-'.$new_resource->uuid;
|
||||||
|
} elseif (str_starts_with($originalName, 'redis-data-')) {
|
||||||
|
$newName = 'redis-data-'.$new_resource->uuid;
|
||||||
|
} elseif (str_starts_with($originalName, 'clickhouse-data-')) {
|
||||||
|
$newName = 'clickhouse-data-'.$new_resource->uuid;
|
||||||
|
} elseif (str_starts_with($originalName, 'mariadb-data-')) {
|
||||||
|
$newName = 'mariadb-data-'.$new_resource->uuid;
|
||||||
|
} elseif (str_starts_with($originalName, 'mongodb-data-')) {
|
||||||
|
$newName = 'mongodb-data-'.$new_resource->uuid;
|
||||||
|
} elseif (str_starts_with($originalName, 'keydb-data-')) {
|
||||||
|
$newName = 'keydb-data-'.$new_resource->uuid;
|
||||||
|
} elseif (str_starts_with($originalName, 'dragonfly-data-')) {
|
||||||
|
$newName = 'dragonfly-data-'.$new_resource->uuid;
|
||||||
|
} else {
|
||||||
|
$newName = str($originalName)
|
||||||
|
->replaceFirst($this->resource->uuid, $new_resource->uuid)
|
||||||
|
->toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
$newPersistentVolume = $volume->replicate([
|
||||||
|
'id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
])->fill([
|
||||||
|
'name' => $newName,
|
||||||
|
'resource_id' => $new_resource->id,
|
||||||
|
]);
|
||||||
|
$newPersistentVolume->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileStorages = $this->resource->fileStorages()->get();
|
||||||
|
foreach ($fileStorages as $storage) {
|
||||||
|
$newStorage = $storage->replicate([
|
||||||
|
'id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
])->fill([
|
||||||
|
'resource_id' => $new_resource->id,
|
||||||
|
]);
|
||||||
|
$newStorage->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
$scheduledBackups = $this->resource->scheduledBackups()->get();
|
||||||
|
foreach ($scheduledBackups as $backup) {
|
||||||
|
$uuid = (string) new Cuid2;
|
||||||
|
$newBackup = $backup->replicate([
|
||||||
|
'id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
])->fill([
|
||||||
|
'uuid' => $uuid,
|
||||||
|
'database_id' => $new_resource->id,
|
||||||
|
'database_type' => $new_resource->getMorphClass(),
|
||||||
|
'team_id' => currentTeam()->id,
|
||||||
|
]);
|
||||||
|
$newBackup->save();
|
||||||
|
}
|
||||||
|
|
||||||
$environmentVaribles = $this->resource->environment_variables()->get();
|
$environmentVaribles = $this->resource->environment_variables()->get();
|
||||||
foreach ($environmentVaribles as $environmentVarible) {
|
foreach ($environmentVaribles as $environmentVarible) {
|
||||||
$payload = [];
|
$payload = [
|
||||||
if ($this->resource->type() === 'standalone-postgresql') {
|
'resourceable_id' => $new_resource->id,
|
||||||
$payload['standalone_postgresql_id'] = $new_resource->id;
|
'resourceable_type' => $new_resource->getMorphClass(),
|
||||||
} elseif ($this->resource->type() === 'standalone-redis') {
|
];
|
||||||
$payload['standalone_redis_id'] = $new_resource->id;
|
|
||||||
} elseif ($this->resource->type() === 'standalone-mongodb') {
|
|
||||||
$payload['standalone_mongodb_id'] = $new_resource->id;
|
|
||||||
} elseif ($this->resource->type() === 'standalone-mysql') {
|
|
||||||
$payload['standalone_mysql_id'] = $new_resource->id;
|
|
||||||
} elseif ($this->resource->type() === 'standalone-mariadb') {
|
|
||||||
$payload['standalone_mariadb_id'] = $new_resource->id;
|
|
||||||
}
|
|
||||||
$newEnvironmentVariable = $environmentVarible->replicate([
|
$newEnvironmentVariable = $environmentVarible->replicate([
|
||||||
'id',
|
'id',
|
||||||
'created_at',
|
'created_at',
|
||||||
@@ -145,6 +274,7 @@ class ResourceOperations extends Component
|
|||||||
])->fill($payload);
|
])->fill($payload);
|
||||||
$newEnvironmentVariable->save();
|
$newEnvironmentVariable->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$route = route('project.database.configuration', [
|
$route = route('project.database.configuration', [
|
||||||
'project_uuid' => $this->projectUuid,
|
'project_uuid' => $this->projectUuid,
|
||||||
'environment_uuid' => $this->environmentUuid,
|
'environment_uuid' => $this->environmentUuid,
|
||||||
@@ -167,17 +297,53 @@ class ResourceOperations extends Component
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$new_resource->save();
|
$new_resource->save();
|
||||||
|
|
||||||
|
$tags = $this->resource->tags;
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$new_resource->tags()->attach($tag->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$scheduledTasks = $this->resource->scheduled_tasks()->get();
|
||||||
|
foreach ($scheduledTasks as $task) {
|
||||||
|
$newTask = $task->replicate([
|
||||||
|
'id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
])->fill([
|
||||||
|
'uuid' => (string) new Cuid2,
|
||||||
|
'service_id' => $new_resource->id,
|
||||||
|
'team_id' => currentTeam()->id,
|
||||||
|
]);
|
||||||
|
$newTask->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
$environmentVariables = $this->resource->environment_variables()->get();
|
||||||
|
foreach ($environmentVariables as $environmentVariable) {
|
||||||
|
$newEnvironmentVariable = $environmentVariable->replicate([
|
||||||
|
'id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
])->fill([
|
||||||
|
'resourceable_id' => $new_resource->id,
|
||||||
|
'resourceable_type' => $new_resource->getMorphClass(),
|
||||||
|
]);
|
||||||
|
$newEnvironmentVariable->save();
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($new_resource->applications() as $application) {
|
foreach ($new_resource->applications() as $application) {
|
||||||
$application->update([
|
$application->update([
|
||||||
'status' => 'exited',
|
'status' => 'exited',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($new_resource->databases() as $database) {
|
foreach ($new_resource->databases() as $database) {
|
||||||
$database->update([
|
$database->update([
|
||||||
'status' => 'exited',
|
'status' => 'exited',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$new_resource->parse();
|
$new_resource->parse();
|
||||||
|
|
||||||
$route = route('project.service.configuration', [
|
$route = route('project.service.configuration', [
|
||||||
'project_uuid' => $this->projectUuid,
|
'project_uuid' => $this->projectUuid,
|
||||||
'environment_uuid' => $this->environmentUuid,
|
'environment_uuid' => $this->environmentUuid,
|
||||||
|
|||||||
Reference in New Issue
Block a user