diff --git a/app/Livewire/Project/Shared/MoveResource.php b/app/Livewire/Project/Shared/MoveResource.php deleted file mode 100644 index f4d69dd1d..000000000 --- a/app/Livewire/Project/Shared/MoveResource.php +++ /dev/null @@ -1,58 +0,0 @@ -projectUuid = $parameters['project_uuid']; - $this->environmentName = $parameters['environment_name']; - $this->projects = Project::ownedByCurrentTeam()->get(); - } - public function moveTo($environment_id) - { - try { - $new_environment = Environment::findOrFail($environment_id); - $this->resource->update([ - 'environment_id' => $environment_id - ]); - if ($this->resource->type() === 'application') { - return redirect()->route('project.application.configuration', [ - 'project_uuid' => $new_environment->project->uuid, - 'environment_name' => $new_environment->name, - 'application_uuid' => $this->resource->uuid, - ]); - } else if (str($this->resource->type())->startsWith('standalone-')) { - return redirect()->route('project.database.configuration', [ - 'project_uuid' => $new_environment->project->uuid, - 'environment_name' => $new_environment->name, - 'database_uuid' => $this->resource->uuid, - ]); - } else if ($this->resource->type() === 'service') { - return redirect()->route('project.service.configuration', [ - 'project_uuid' => $new_environment->project->uuid, - 'environment_name' => $new_environment->name, - 'service_uuid' => $this->resource->uuid, - ]); - } - } catch (\Throwable $e) { - return handleError($e, $this); - } - } - public function render() - { - return view('livewire.project.shared.move-resource'); - } -} diff --git a/app/Livewire/Project/Shared/ResourceOperations.php b/app/Livewire/Project/Shared/ResourceOperations.php new file mode 100644 index 000000000..cd7e2be92 --- /dev/null +++ b/app/Livewire/Project/Shared/ResourceOperations.php @@ -0,0 +1,173 @@ +projectUuid = $parameters['project_uuid']; + $this->environmentName = $parameters['environment_name']; + $this->projects = Project::ownedByCurrentTeam()->get(); + $this->servers = currentTeam()->servers; + } + public function cloneTo($destination_id) + { + $new_destination = StandaloneDocker::find($destination_id); + if (!$new_destination) { + $new_destination = SwarmDocker::find($destination_id); + } + if (!$new_destination) { + return $this->addError('destination_id', 'Destination not found.'); + } + $uuid = (string)new Cuid2(7); + $server = $new_destination->server; + if ($this->resource->getMorphClass() === 'App\Models\Application') { + $new_resource = $this->resource->replicate()->fill([ + 'uuid' => $uuid, + 'name' => $this->resource->name . '-clone-' . $uuid, + 'fqdn' => generateFqdn($server, $uuid), + 'status' => 'exited', + 'destination_id' => $new_destination->id, + ]); + $new_resource->save(); + $environmentVaribles = $this->resource->environment_variables()->get(); + foreach ($environmentVaribles as $environmentVarible) { + $newEnvironmentVariable = $environmentVarible->replicate()->fill([ + 'application_id' => $new_resource->id, + ]); + $newEnvironmentVariable->save(); + } + $persistentVolumes = $this->resource->persistentStorages()->get(); + foreach ($persistentVolumes as $volume) { + $newPersistentVolume = $volume->replicate()->fill([ + 'name' => $new_resource->uuid . '-' . str($volume->name)->afterLast('-'), + 'resource_id' => $new_resource->id, + ]); + $newPersistentVolume->save(); + } + $route = route('project.application.configuration', [ + 'project_uuid' => $this->projectUuid, + 'environment_name' => $this->environmentName, + 'application_uuid' => $new_resource->uuid, + ]) . "#resource-operations"; + return redirect()->to($route); + } else if ( + $this->resource->getMorphClass() === 'App\Models\StandalonePostgresql' || + $this->resource->getMorphClass() === 'App\Models\StandaloneMongodb' || + $this->resource->getMorphClass() === 'App\Models\StandaloneMysql' || + $this->resource->getMorphClass() === 'App\Models\StandaloneMariadb' || + $this->resource->getMorphClass() === 'App\Models\StandaloneRedis' + ) { + $uuid = (string)new Cuid2(7); + $new_resource = $this->resource->replicate()->fill([ + 'uuid' => $uuid, + 'name' => $this->resource->name . '-clone-' . $uuid, + 'status' => 'exited', + 'started_at' => null, + 'destination_id' => $new_destination->id, + ]); + $new_resource->save(); + $environmentVaribles = $this->resource->environment_variables()->get(); + foreach ($environmentVaribles as $environmentVarible) { + $payload = []; + if ($this->resource->type() === 'standalone-postgresql') { + $payload['standalone_postgresql_id'] = $new_resource->id; + } else if ($this->resource->type() === 'standalone-redis') { + $payload['standalone_redis_id'] = $new_resource->id; + } else if ($this->resource->type() === 'standalone-mongodb') { + $payload['standalone_mongodb_id'] = $new_resource->id; + } else if ($this->resource->type() === 'standalone-mysql') { + $payload['standalone_mysql_id'] = $new_resource->id; + } else if ($this->resource->type() === 'standalone-mariadb') { + $payload['standalone_mariadb_id'] = $new_resource->id; + } + $newEnvironmentVariable = $environmentVarible->replicate()->fill($payload); + $newEnvironmentVariable->save(); + } + $route = route('project.database.configuration', [ + 'project_uuid' => $this->projectUuid, + 'environment_name' => $this->environmentName, + 'database_uuid' => $new_resource->uuid, + ]) . "#resource-operations"; + return redirect()->to($route); + } else if ($this->resource->type() === 'service') { + $uuid = (string)new Cuid2(7); + $new_resource = $this->resource->replicate()->fill([ + 'uuid' => $uuid, + 'name' => $this->resource->name . '-clone-' . $uuid, + 'destination_id' => $new_destination->id, + ]); + $new_resource->save(); + foreach ($new_resource->applications() as $application) { + $application->update([ + 'status' => 'exited', + ]); + } + foreach ($new_resource->databases() as $database) { + $database->update([ + 'status' => 'exited', + ]); + } + $new_resource->parse(); + $route = route('project.service.configuration', [ + 'project_uuid' => $this->projectUuid, + 'environment_name' => $this->environmentName, + 'service_uuid' => $new_resource->uuid, + ]) . "#resource-operations"; + return redirect()->to($route); + } + return; + } + public function moveTo($environment_id) + { + try { + $new_environment = Environment::findOrFail($environment_id); + $this->resource->update([ + 'environment_id' => $environment_id + ]); + if ($this->resource->type() === 'application') { + $route = route('project.application.configuration', [ + 'project_uuid' => $new_environment->project->uuid, + 'environment_name' => $new_environment->name, + 'application_uuid' => $this->resource->uuid, + ]) . "#resource-operations"; + return redirect()->to($route); + } else if (str($this->resource->type())->startsWith('standalone-')) { + $route = route('project.database.configuration', [ + 'project_uuid' => $new_environment->project->uuid, + 'environment_name' => $new_environment->name, + 'database_uuid' => $this->resource->uuid, + ]) . "#resource-operations"; + return redirect()->to($route); + } else if ($this->resource->type() === 'service') { + $route = route('project.service.configuration', [ + 'project_uuid' => $new_environment->project->uuid, + 'environment_name' => $new_environment->name, + 'service_uuid' => $this->resource->uuid, + ]) . "#resource-operations"; + return redirect()->to($route); + } + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + public function render() + { + return view('livewire.project.shared.resource-operations'); + } +} diff --git a/resources/views/livewire/project/application/configuration.blade.php b/resources/views/livewire/project/application/configuration.blade.php index 60a207acb..265927fb6 100644 --- a/resources/views/livewire/project/application/configuration.blade.php +++ b/resources/views/livewire/project/application/configuration.blade.php @@ -59,8 +59,9 @@ href="#">Resource Limits @endif - Move Resource + Resource Operations Danger Zone @@ -108,8 +109,8 @@
-
- +
+
diff --git a/resources/views/livewire/project/database/configuration.blade.php b/resources/views/livewire/project/database/configuration.blade.php index 6e3f9a613..fb63f3a26 100644 --- a/resources/views/livewire/project/database/configuration.blade.php +++ b/resources/views/livewire/project/database/configuration.blade.php @@ -44,8 +44,9 @@ window.location.hash = 'resource-limits'" href="#">Resource Limits - Move Resource + Resource Operations
-
- +
+
diff --git a/resources/views/livewire/project/service/configuration.blade.php b/resources/views/livewire/project/service/configuration.blade.php index 1ecec2f60..ac805b6b3 100644 --- a/resources/views/livewire/project/service/configuration.blade.php +++ b/resources/views/livewire/project/service/configuration.blade.php @@ -26,9 +26,10 @@ Webhooks - Move Resource - + Resource Operations +
-
- +
+
diff --git a/resources/views/livewire/project/shared/move-resource.blade.php b/resources/views/livewire/project/shared/move-resource.blade.php deleted file mode 100644 index 6dec75490..000000000 --- a/resources/views/livewire/project/shared/move-resource.blade.php +++ /dev/null @@ -1,25 +0,0 @@ -
-

Move Resource

-
You can easily move this resource to another project.
-
-
- This resource is currently in the {{ $resource->environment->project->name }} / - {{ $resource->environment->name }} environment. -
-
- @forelse ($projects as $project) -
- @foreach ($project->environments as $environment) -
-
{{ $project->name }}
-
{{ $environment->name }} environment
-
- @endforeach -
- @empty -
No projects found to move to
- @endforelse -
-
-
diff --git a/resources/views/livewire/project/shared/resource-operations.blade.php b/resources/views/livewire/project/shared/resource-operations.blade.php new file mode 100644 index 000000000..7ff48d052 --- /dev/null +++ b/resources/views/livewire/project/shared/resource-operations.blade.php @@ -0,0 +1,46 @@ +
+

Resource Operations

+
You can easily make different kind of operations on this resource.
+

Clone

+
+
+ Clone this resource to another project / environment. +
+
+ @foreach ($servers->sortBy('id') as $server) +
+
+ @foreach ($server->destinations() as $destination) +
+
{{ $server->name }}
+
{{ $destination->name }}
+
+ @endforeach +
+
+ @endforeach +
+
+

Move

+
+
+ This resource is currently in the {{ $resource->environment->project->name }} / + {{ $resource->environment->name }} environment. +
+
+ @forelse ($projects as $project) +
+ @foreach ($project->environments as $environment) +
+
{{ $project->name }}
+
{{ $environment->name }} environment
+
+ @endforeach +
+ @empty +
No projects found to move to
+ @endforelse +
+
+