fix: resource clone name + volume name generation
This commit is contained in:
@@ -42,9 +42,11 @@ class ResourceOperations extends Component
|
|||||||
$uuid = (string) new Cuid2;
|
$uuid = (string) new Cuid2;
|
||||||
$server = $new_destination->server;
|
$server = $new_destination->server;
|
||||||
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;
|
||||||
|
|
||||||
$new_resource = $this->resource->replicate()->fill([
|
$new_resource = $this->resource->replicate()->fill([
|
||||||
'uuid' => $uuid,
|
'uuid' => $uuid,
|
||||||
'name' => $this->resource->name.'-clone-'.$uuid,
|
'name' => $name,
|
||||||
'fqdn' => generateFqdn($server, $uuid),
|
'fqdn' => generateFqdn($server, $uuid),
|
||||||
'status' => 'exited',
|
'status' => 'exited',
|
||||||
'destination_id' => $new_destination->id,
|
'destination_id' => $new_destination->id,
|
||||||
@@ -64,8 +66,12 @@ class ResourceOperations extends Component
|
|||||||
}
|
}
|
||||||
$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();
|
||||||
|
if ($volumeName === $volume->name) {
|
||||||
|
$volumeName = $new_resource->uuid.'-'.str($volume->name)->afterLast('-');
|
||||||
|
}
|
||||||
$newPersistentVolume = $volume->replicate()->fill([
|
$newPersistentVolume = $volume->replicate()->fill([
|
||||||
'name' => $new_resource->uuid.'-'.str($volume->name)->afterLast('-'),
|
'name' => $volumeName,
|
||||||
'resource_id' => $new_resource->id,
|
'resource_id' => $new_resource->id,
|
||||||
]);
|
]);
|
||||||
$newPersistentVolume->save();
|
$newPersistentVolume->save();
|
||||||
|
Reference in New Issue
Block a user