From 09ea8a75ddba6a083cb3774ab771f0bd3aaabfac Mon Sep 17 00:00:00 2001 From: Christophe Francey Date: Sun, 20 Oct 2024 14:13:01 +0200 Subject: [PATCH 1/2] fix issue with `spatie/laravel-backup` v9 --- src/Http/Controllers/BackupStatusesController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Http/Controllers/BackupStatusesController.php b/src/Http/Controllers/BackupStatusesController.php index 7195cf6..52cd425 100644 --- a/src/Http/Controllers/BackupStatusesController.php +++ b/src/Http/Controllers/BackupStatusesController.php @@ -12,7 +12,12 @@ class BackupStatusesController extends ApiController public function index() { return Cache::remember('backup-statuses', now()->addSeconds(4), function () { - return BackupDestinationStatusFactory::createForMonitorConfig(config('backup.monitor_backups')) + $monitorConfiguration = (new \ReflectionMethod(BackupDestinationStatusFactory::class, 'createForMonitorConfig')) + ->getParameters()[0]->getType()->getName() === 'Spatie\Backup\Config\MonitoredBackupsConfig' + ? \Spatie\Backup\Config\MonitoredBackupsConfig::fromArray(config('backup.monitor_backups')) + : config('backup.monitor_backups'); + + return BackupDestinationStatusFactory::createForMonitorConfig($monitorConfiguration) ->map(function (BackupDestinationStatus $backupDestinationStatus) { return [ 'name' => $backupDestinationStatus->backupDestination()->backupName(), From fbdf5e9a5e700aaebb90c8067e776c9b7c4add64 Mon Sep 17 00:00:00 2001 From: Christophe Francey Date: Mon, 18 Nov 2024 21:33:35 +0100 Subject: [PATCH 2/2] Update BackupStatusesController.php move logic to method --- .../Controllers/BackupStatusesController.php | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Http/Controllers/BackupStatusesController.php b/src/Http/Controllers/BackupStatusesController.php index 52cd425..8aa92eb 100644 --- a/src/Http/Controllers/BackupStatusesController.php +++ b/src/Http/Controllers/BackupStatusesController.php @@ -12,12 +12,7 @@ class BackupStatusesController extends ApiController public function index() { return Cache::remember('backup-statuses', now()->addSeconds(4), function () { - $monitorConfiguration = (new \ReflectionMethod(BackupDestinationStatusFactory::class, 'createForMonitorConfig')) - ->getParameters()[0]->getType()->getName() === 'Spatie\Backup\Config\MonitoredBackupsConfig' - ? \Spatie\Backup\Config\MonitoredBackupsConfig::fromArray(config('backup.monitor_backups')) - : config('backup.monitor_backups'); - - return BackupDestinationStatusFactory::createForMonitorConfig($monitorConfiguration) + return BackupDestinationStatusFactory::createForMonitorConfig($this->getMonitorConfig()) ->map(function (BackupDestinationStatus $backupDestinationStatus) { return [ 'name' => $backupDestinationStatus->backupDestination()->backupName(), @@ -35,4 +30,20 @@ public function index() ->toArray(); }); } + + /** + * Get monitor configuration data. + * spatie/laravel-backup ^9.x introduce DTO parameter instead of array. + * + * @return \Spatie\Backup\Config\MonitoredBackupsConfig|array + */ + protected function getMonitorConfig() + { + $reflection = new \ReflectionMethod(BackupDestinationStatusFactory::class, 'createForMonitorConfig'); + $monitorBackupsType = $reflection->getParameters()[0]->getType()->getName(); + + return $monitorBackupsType === 'Spatie\Backup\Config\MonitoredBackupsConfig' + ? \Spatie\Backup\Config\MonitoredBackupsConfig::fromArray(config('backup.monitor_backups')) + : config('backup.monitor_backups'); + } }