From 538246e795dd8abb7eab5f7905516ff14cba9b62 Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Thu, 9 May 2024 14:50:58 +0300 Subject: [PATCH] add hosting backup view log --- .../ManageHostingSubscriptionBackups.php | 14 +++++++ .../Livewire/HostingSubscriptionBackupLog.php | 37 +++++++++++++++++++ web/app/Providers/AppServiceProvider.php | 2 + .../modals/view-livewire-component.blade.php | 3 ++ .../hosting-subscription-backup-log.blade.php | 14 +++++++ 5 files changed, 70 insertions(+) create mode 100644 web/app/Livewire/HostingSubscriptionBackupLog.php create mode 100644 web/resources/views/filament/modals/view-livewire-component.blade.php create mode 100644 web/resources/views/livewire/hosting-subscription-backup-log.blade.php diff --git a/web/app/Filament/Resources/HostingSubscriptionResource/Pages/ManageHostingSubscriptionBackups.php b/web/app/Filament/Resources/HostingSubscriptionResource/Pages/ManageHostingSubscriptionBackups.php index 3ec5cf3..6730183 100644 --- a/web/app/Filament/Resources/HostingSubscriptionResource/Pages/ManageHostingSubscriptionBackups.php +++ b/web/app/Filament/Resources/HostingSubscriptionResource/Pages/ManageHostingSubscriptionBackups.php @@ -12,6 +12,7 @@ use App\Models\DatabaseUser; use App\Models\HostingSubscriptionBackup; use App\Models\RemoteDatabaseServer; use Filament\Forms; +use Filament\Forms\Components\TextInput; use Filament\Forms\Form; use Filament\Infolists\Components\IconEntry; use Filament\Infolists\Components\TextEntry; @@ -141,6 +142,19 @@ class ManageHostingSubscriptionBackups extends ManageRelatedRecords return redirect($tempUrl); }), + + Tables\Actions\Action::make('viewLog') + ->label('View Log') + ->icon('heroicon-o-document') + ->modalContent(function (HostingSubscriptionBackup $backup) { + return view('filament.modals.view-livewire-component', [ + 'component' => 'hosting-subscription-backup-log', + 'componentProps' => [ + 'hostingSubscriptionBackupId' => $backup->id, + ], + ]); + }), + Tables\Actions\ViewAction::make(), // Tables\Actions\EditAction::make(), Tables\Actions\DeleteAction::make(), diff --git a/web/app/Livewire/HostingSubscriptionBackupLog.php b/web/app/Livewire/HostingSubscriptionBackupLog.php new file mode 100644 index 0000000..13f5162 --- /dev/null +++ b/web/app/Livewire/HostingSubscriptionBackupLog.php @@ -0,0 +1,37 @@ +hostingSubscriptionBackupId)->first(); + if ($findHsb) { + $backupLog = $findHsb->path . '/backup.log'; + if (file_exists($backupLog)) { + $backupLogContent = file_get_contents($backupLog); + // Get last 1000 lines of the log + $backupLogContent = substr($backupLogContent, -5000, 5000); + $backupLogContent = str_replace("\n", "
", $backupLogContent); + + $this->backupLog = $backupLogContent; + } + } + } + public function mount($hostingSubscriptionBackupId) + { + $this->hostingSubscriptionBackupId = $hostingSubscriptionBackupId; + } + + public function view() + { + return view('livewire.hosting-subscription-backup-log'); + } +} diff --git a/web/app/Providers/AppServiceProvider.php b/web/app/Providers/AppServiceProvider.php index a517f51..b59af07 100644 --- a/web/app/Providers/AppServiceProvider.php +++ b/web/app/Providers/AppServiceProvider.php @@ -12,6 +12,7 @@ use App\Listeners\ModelDomainDeletingListener; use App\Listeners\ModelHostingSubscriptionCreatingListener; use App\Listeners\ModelHostingSubscriptionDeletingListener; use App\Livewire\Components\QuickServiceRestartMenu; +use App\Livewire\HostingSubscriptionBackupLog; use App\Models\Domain; use App\Models\HostingSubscription; use App\Policies\CustomerPolicy; @@ -63,6 +64,7 @@ class AppServiceProvider extends ServiceProvider }); Livewire::component('quick-service-restart-menu', QuickServiceRestartMenu::class); + Livewire::component('hosting-subscription-backup-log', HostingSubscriptionBackupLog::class); Gate::define('delete-customer', [CustomerPolicy::class, 'delete']); diff --git a/web/resources/views/filament/modals/view-livewire-component.blade.php b/web/resources/views/filament/modals/view-livewire-component.blade.php new file mode 100644 index 0000000..47b9a8c --- /dev/null +++ b/web/resources/views/filament/modals/view-livewire-component.blade.php @@ -0,0 +1,3 @@ +
+ @livewire($component, $componentProps, key($component)) +
diff --git a/web/resources/views/livewire/hosting-subscription-backup-log.blade.php b/web/resources/views/livewire/hosting-subscription-backup-log.blade.php new file mode 100644 index 0000000..0d49a6c --- /dev/null +++ b/web/resources/views/livewire/hosting-subscription-backup-log.blade.php @@ -0,0 +1,14 @@ +
+
+ + {!! $this->backupLog !!} + +
+ + +