From 4cc2fbb40d8f31c6396a80ffb8fd23f51c3f8052 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Thu, 2 May 2024 23:06:52 +0300 Subject: [PATCH] update --- web/app/Models/Backup.php | 5 +++++ .../2024_04_24_144158_create_backups_table.php | 1 + ..._134711_create_hosting_subscription_backups_table.php | 1 + web/tests/Unit/BackupTest.php | 9 +++++++-- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/web/app/Models/Backup.php b/web/app/Models/Backup.php index 1e677f2..a6d6f75 100644 --- a/web/app/Models/Backup.php +++ b/web/app/Models/Backup.php @@ -111,6 +111,7 @@ class Backup extends Model } if (count($errorsBag) > 0) { $this->status = 'failed'; + $this->backup_log = 'Backup failed. Database or env file missing.'; $this->save(); return [ 'status' => 'failed', @@ -126,6 +127,7 @@ class Backup extends Model if (count($errorsBag) > 0) { $this->status = 'failed'; + $this->backup_log = 'Backup failed. Database or env file content mismatch.'; $this->save(); return [ 'status' => 'failed', @@ -145,6 +147,7 @@ class Backup extends Model $this->status = 'completed'; $this->completed = true; $this->completed_at = now(); + $this->backup_log = 'Backup completed'; $this->save(); return [ @@ -157,6 +160,7 @@ class Backup extends Model if (Str::contains($checkProcess, $this->process_id)) { $this->size = Helpers::checkPathSize($this->path); + $this->backup_log = 'Backup is still processing'; $this->save(); return [ @@ -164,6 +168,7 @@ class Backup extends Model 'message' => 'Backup is still processing' ]; } else { + $this->backup_log = 'Backup failed. Process not found'; $this->status = 'failed'; $this->save(); return [ diff --git a/web/database/migrations/2024_04_24_144158_create_backups_table.php b/web/database/migrations/2024_04_24_144158_create_backups_table.php index cbe32ba..fa8b98a 100644 --- a/web/database/migrations/2024_04_24_144158_create_backups_table.php +++ b/web/database/migrations/2024_04_24_144158_create_backups_table.php @@ -16,6 +16,7 @@ return new class extends Migration $table->string('backup_type')->nullable(); $table->string('status')->nullable(); + $table->string('backup_log')->nullable(); $table->string('path')->nullable(); $table->string('root_path')->nullable(); diff --git a/web/database/migrations/2024_04_25_134711_create_hosting_subscription_backups_table.php b/web/database/migrations/2024_04_25_134711_create_hosting_subscription_backups_table.php index 5571c7b..414b08d 100644 --- a/web/database/migrations/2024_04_25_134711_create_hosting_subscription_backups_table.php +++ b/web/database/migrations/2024_04_25_134711_create_hosting_subscription_backups_table.php @@ -17,6 +17,7 @@ return new class extends Migration $table->bigInteger('hosting_subscription_id')->nullable(); $table->string('backup_type')->nullable(); $table->string('status')->nullable(); + $table->string('backup_log')->nullable(); $table->string('path')->nullable(); $table->string('root_path')->nullable(); diff --git a/web/tests/Unit/BackupTest.php b/web/tests/Unit/BackupTest.php index f530623..986d123 100644 --- a/web/tests/Unit/BackupTest.php +++ b/web/tests/Unit/BackupTest.php @@ -30,7 +30,7 @@ class BackupTest extends ActionTestCase $backupFinished = false; - for ($i = 0; $i < 400; $i++) { + for ($i = 0; $i < 100; $i++) { Artisan::call('phyre:run-backup-checks'); @@ -85,7 +85,7 @@ class BackupTest extends ActionTestCase $findBackup = false; $backupCompleted = false; - for ($i = 0; $i < 400; $i++) { + for ($i = 0; $i < 100; $i++) { Artisan::call('phyre:run-backup-checks'); @@ -98,6 +98,11 @@ class BackupTest extends ActionTestCase sleep(1); } + if (!$backupCompleted) { + $findBackup = Backup::where('id', $backupId)->first(); + $this->fail('Backup not completed: '.$findBackup->backup_log); + } + $this->assertTrue($backupCompleted); $this->assertNotEmpty($findBackup->file_path); $this->assertTrue(file_exists($findBackup->file_path));