diff --git a/web/app/Filament/Resources/BackupResource.php b/web/app/Filament/Resources/BackupResource.php
index 907d834..5391d9f 100644
--- a/web/app/Filament/Resources/BackupResource.php
+++ b/web/app/Filament/Resources/BackupResource.php
@@ -113,6 +113,26 @@ class BackupResource extends Resource
return redirect($tempUrl);
}),
+
+ Tables\Actions\Action::make('viewLog')
+ ->label('View Log')
+ ->icon('heroicon-o-document')
+ ->hidden(function (Backup $backup) {
+ $hide = false;
+ if ($backup->status === BackupStatus::Completed) {
+ $hide = true;
+ }
+ return $hide;
+ })
+ ->modalContent(function (Backup $backup) {
+ return view('filament.modals.view-livewire-component', [
+ 'component' => 'backup-log',
+ 'componentProps' => [
+ 'backupId' => $backup->id,
+ ],
+ ]);
+ }),
+
Tables\Actions\ViewAction::make(),
])
->defaultSort('id', 'desc')
@@ -132,7 +152,7 @@ class BackupResource extends Resource
public static function getWidgets(): array
{
return [
- BackupStats::class,
+ // BackupStats::class,
];
}
diff --git a/web/app/Filament/Resources/BackupResource/Widgets/BackupStats.php b/web/app/Filament/Resources/BackupResource/Widgets/BackupStats.php
index beae90d..5cb7927 100644
--- a/web/app/Filament/Resources/BackupResource/Widgets/BackupStats.php
+++ b/web/app/Filament/Resources/BackupResource/Widgets/BackupStats.php
@@ -11,6 +11,7 @@ use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Flowframe\Trend\Trend;
use Flowframe\Trend\TrendValue;
+use Illuminate\Support\Facades\Cache;
class BackupStats extends BaseWidget
{
@@ -25,21 +26,28 @@ class BackupStats extends BaseWidget
protected function getStats(): array
{
- $findBackups = Backup::select(['id'])->where('status', 'processing')->get();
- if ($findBackups->count() > 0) {
- foreach ($findBackups as $backup) {
- $backup->checkBackup();
+
+ $stats = Cache::remember('backup-stats', 300, function () {
+ $findBackups = Backup::select(['id'])->where('status', 'processing')->get();
+ if ($findBackups->count() > 0) {
+ foreach ($findBackups as $backup) {
+ $backup->checkBackup();
+ }
}
- }
- $usedSpace = 0;
- $backupPath = BackupStorage::getPath();
- if (is_dir($backupPath)) {
- $usedSpace = $this->getDirectorySize($backupPath);
- }
+ $usedSpace = 0;
+ $backupPath = BackupStorage::getPath();
+ if (is_dir($backupPath)) {
+ $usedSpace = $this->getDirectorySize($backupPath);
+ }
+ return [
+ 'totalBackups' => Backup::count(),
+ 'usedSpace' => $usedSpace,
+ ];
+ });
return [
- Stat::make('Total backups', Backup::count()),
- Stat::make('Total used space', $usedSpace),
+ Stat::make('Total backups', $stats['totalBackups']),
+ Stat::make('Total used space', $stats['usedSpace']),
];
}
diff --git a/web/app/Livewire/BackupLog.php b/web/app/Livewire/BackupLog.php
new file mode 100644
index 0000000..f0c9ef7
--- /dev/null
+++ b/web/app/Livewire/BackupLog.php
@@ -0,0 +1,37 @@
+backupId)->first();
+ if ($findBackup) {
+ $backupLog = $findBackup->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($backupId)
+ {
+ $this->backupId = $backupId;
+ }
+
+ public function render()
+ {
+ return view('livewire.hosting-subscription-backup-log');
+ }
+}
diff --git a/web/app/Livewire/HostingSubscriptionBackupLog.php b/web/app/Livewire/HostingSubscriptionBackupLog.php
index 13f5162..5b3ba9b 100644
--- a/web/app/Livewire/HostingSubscriptionBackupLog.php
+++ b/web/app/Livewire/HostingSubscriptionBackupLog.php
@@ -30,7 +30,7 @@ class HostingSubscriptionBackupLog extends Component
$this->hostingSubscriptionBackupId = $hostingSubscriptionBackupId;
}
- public function view()
+ public function render()
{
return view('livewire.hosting-subscription-backup-log');
}
diff --git a/web/app/Providers/AppServiceProvider.php b/web/app/Providers/AppServiceProvider.php
index b59af07..cd666ef 100644
--- a/web/app/Providers/AppServiceProvider.php
+++ b/web/app/Providers/AppServiceProvider.php
@@ -11,6 +11,7 @@ use App\Listeners\ModelDomainCreatedListener;
use App\Listeners\ModelDomainDeletingListener;
use App\Listeners\ModelHostingSubscriptionCreatingListener;
use App\Listeners\ModelHostingSubscriptionDeletingListener;
+use App\Livewire\BackupLog;
use App\Livewire\Components\QuickServiceRestartMenu;
use App\Livewire\HostingSubscriptionBackupLog;
use App\Models\Domain;
@@ -65,6 +66,7 @@ class AppServiceProvider extends ServiceProvider
Livewire::component('quick-service-restart-menu', QuickServiceRestartMenu::class);
Livewire::component('hosting-subscription-backup-log', HostingSubscriptionBackupLog::class);
+ Livewire::component('backup-log', BackupLog::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
index 47b9a8c..c3e9f8f 100644
--- a/web/resources/views/filament/modals/view-livewire-component.blade.php
+++ b/web/resources/views/filament/modals/view-livewire-component.blade.php
@@ -1,3 +1,5 @@