From e71032a8fc5f3127e036e723b313db7a1305c996 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 11 Apr 2024 13:20:46 +0200 Subject: [PATCH] Fix variable assignment in Import.php and ApplicationDeploymentJob.php --- app/Actions/Database/StartClickhouse.php | 8 +- app/Actions/Database/StartDragonfly.php | 8 +- app/Actions/Database/StartKeydb.php | 8 +- app/Actions/Database/StartMariadb.php | 8 +- app/Actions/Database/StartMongodb.php | 8 +- app/Actions/Database/StartMysql.php | 8 +- app/Actions/Database/StartPostgresql.php | 8 +- app/Actions/Database/StartRedis.php | 8 +- app/Jobs/ApplicationDeploymentJob.php | 6 +- app/Livewire/Project/Database/Import.php | 4 +- .../project/database/import.blade.php | 75 ++++++++++--------- 11 files changed, 95 insertions(+), 54 deletions(-) diff --git a/app/Actions/Database/StartClickhouse.php b/app/Actions/Database/StartClickhouse.php index d530bc6c3..10fe6e0d5 100644 --- a/app/Actions/Database/StartClickhouse.php +++ b/app/Actions/Database/StartClickhouse.php @@ -116,8 +116,12 @@ class StartClickhouse { $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { - $volume_name = $persistentStorage->host_path ?? $persistentStorage->name; - $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; + } else { + $volume_name = $persistentStorage->name; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + } } return $local_persistent_volumes; } diff --git a/app/Actions/Database/StartDragonfly.php b/app/Actions/Database/StartDragonfly.php index e5daf933b..a750f4412 100644 --- a/app/Actions/Database/StartDragonfly.php +++ b/app/Actions/Database/StartDragonfly.php @@ -124,8 +124,12 @@ class StartDragonfly { $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { - $volume_name = $persistentStorage->host_path ?? $persistentStorage->name; - $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; + } else { + $volume_name = $persistentStorage->name; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + } } return $local_persistent_volumes; } diff --git a/app/Actions/Database/StartKeydb.php b/app/Actions/Database/StartKeydb.php index 11f8b0022..7b4bbe124 100644 --- a/app/Actions/Database/StartKeydb.php +++ b/app/Actions/Database/StartKeydb.php @@ -121,8 +121,12 @@ class StartKeydb { $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { - $volume_name = $persistentStorage->host_path ?? $persistentStorage->name; - $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; + } else { + $volume_name = $persistentStorage->name; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + } } return $local_persistent_volumes; } diff --git a/app/Actions/Database/StartMariadb.php b/app/Actions/Database/StartMariadb.php index 8dca584f2..755c47867 100644 --- a/app/Actions/Database/StartMariadb.php +++ b/app/Actions/Database/StartMariadb.php @@ -114,8 +114,12 @@ class StartMariadb { $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { - $volume_name = $persistentStorage->host_path ?? $persistentStorage->name; - $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; + } else { + $volume_name = $persistentStorage->name; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + } } return $local_persistent_volumes; } diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.php index ef04a9be8..180ae988a 100644 --- a/app/Actions/Database/StartMongodb.php +++ b/app/Actions/Database/StartMongodb.php @@ -130,8 +130,12 @@ class StartMongodb { $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { - $volume_name = $persistentStorage->host_path ?? $persistentStorage->name; - $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; + } else { + $volume_name = $persistentStorage->name; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + } } return $local_persistent_volumes; } diff --git a/app/Actions/Database/StartMysql.php b/app/Actions/Database/StartMysql.php index 3b47483a3..0e2e75719 100644 --- a/app/Actions/Database/StartMysql.php +++ b/app/Actions/Database/StartMysql.php @@ -114,8 +114,12 @@ class StartMysql { $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { - $volume_name = $persistentStorage->host_path ?? $persistentStorage->name; - $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; + } else { + $volume_name = $persistentStorage->name; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + } } return $local_persistent_volumes; } diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.php index 844f81c31..03b460edc 100644 --- a/app/Actions/Database/StartPostgresql.php +++ b/app/Actions/Database/StartPostgresql.php @@ -136,8 +136,12 @@ class StartPostgresql { $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { - $volume_name = $persistentStorage->host_path ?? $persistentStorage->name; - $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; + } else { + $volume_name = $persistentStorage->name; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + } } return $local_persistent_volumes; } diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.php index e1a8eef41..ff8c63aab 100644 --- a/app/Actions/Database/StartRedis.php +++ b/app/Actions/Database/StartRedis.php @@ -125,8 +125,12 @@ class StartRedis { $local_persistent_volumes = []; foreach ($this->database->persistentStorages as $persistentStorage) { - $volume_name = $persistentStorage->host_path ?? $persistentStorage->name; - $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { + $local_persistent_volumes[] = $persistentStorage->host_path . ':' . $persistentStorage->mount_path; + } else { + $volume_name = $persistentStorage->name; + $local_persistent_volumes[] = $volume_name . ':' . $persistentStorage->mount_path; + } } return $local_persistent_volumes; } diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 6ad87e07f..729b2e049 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -1340,7 +1340,11 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted { $local_persistent_volumes = []; foreach ($this->application->persistentStorages as $persistentStorage) { - $volume_name = $persistentStorage->host_path ?? $persistentStorage->name; + if ($persistentStorage->host_path !== '' && $persistentStorage->host_path !== null) { + $volume_name = $persistentStorage->host_path; + } else { + $volume_name = $persistentStorage->name; + } if ($this->pull_request_id !== 0) { $volume_name = $volume_name . '-pr-' . $this->pull_request_id; } diff --git a/app/Livewire/Project/Database/Import.php b/app/Livewire/Project/Database/Import.php index 4a2a9fff2..74e41056a 100644 --- a/app/Livewire/Project/Database/Import.php +++ b/app/Livewire/Project/Database/Import.php @@ -8,7 +8,7 @@ use Illuminate\Support\Facades\Storage; class Import extends Component { - + public bool $unsupported = false; public $resource; public $parameters; public $containers; @@ -65,7 +65,7 @@ class Import extends Component $this->resource->getMorphClass() == 'App\Models\StandaloneClickhouse' || $this->resource->getMorphClass() == 'App\Models\StandaloneMongodb' ) { - $this->dispatch('error', 'Import is not supported for this resource.'); + $this->unsupported = true; } } diff --git a/resources/views/livewire/project/database/import.blade.php b/resources/views/livewire/project/database/import.blade.php index ad0199563..b35beb47a 100644 --- a/resources/views/livewire/project/database/import.blade.php +++ b/resources/views/livewire/project/database/import.blade.php @@ -37,41 +37,46 @@ @endscript

Import Backup

-
- - - - This is a destructive action, existing data will be replaced! -
- - @if (str(data_get($resource, 'status'))->startsWith('running')) - @if ($resource->type() === 'standalone-postgresql') - - @elseif ($resource->type() === 'standalone-mysql') - - @elseif ($resource->type() === 'standalone-mariadb') - - @endif - -
- -
-
-
File: /
- Restore Backup -
-
- @csrf -
- -
- -
+ @if ($unsupported) +
Database restore is not supported.
@else -
Database must be running to restore a backup.
+
+ + + + This is a destructive action, existing data will be replaced! +
+ @if (str(data_get($resource, 'status'))->startsWith('running')) + + @if ($resource->type() === 'standalone-postgresql') + + @elseif ($resource->type() === 'standalone-mysql') + + @elseif ($resource->type() === 'standalone-mariadb') + + @endif + +
+ +
+
+
File: /
+ Restore Backup +
+
+ @csrf +
+ +
+ +
+ @else +
Database must be running to restore a backup.
+ @endif @endif