From 3d424972cc44a1350241ae75abdcd008b93dac33 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 11 Mar 2023 15:04:16 +0100 Subject: [PATCH] Fix #7201 --- app/Console/Commands/VerifySecurityAlerts.php | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/VerifySecurityAlerts.php b/app/Console/Commands/VerifySecurityAlerts.php index 6c1f9dbf48..2b18fcd82d 100644 --- a/app/Console/Commands/VerifySecurityAlerts.php +++ b/app/Console/Commands/VerifySecurityAlerts.php @@ -25,6 +25,7 @@ declare(strict_types=1); namespace FireflyIII\Console\Commands; use Illuminate\Console\Command; +use Illuminate\Database\QueryException; use League\Flysystem\FilesystemException; use Log; use Storage; @@ -55,9 +56,7 @@ class VerifySecurityAlerts extends Command */ public function handle(): int { - // remove old advisory - app('fireflyconfig')->delete('upgrade_security_message'); - app('fireflyconfig')->delete('upgrade_security_level'); + $this->removeOldAdvisory(); // check for security advisories. $version = config('firefly.version'); @@ -76,8 +75,7 @@ class VerifySecurityAlerts extends Command if ($version === $array['version'] && true === $array['advisory']) { Log::debug(sprintf('Version %s has an alert!', $array['version'])); // add advisory to configuration. - app('fireflyconfig')->set('upgrade_security_message', $array['message']); - app('fireflyconfig')->set('upgrade_security_level', $array['level']); + $this->saveSecurityAdvisory($array); // depends on level if ('info' === $array['level']) { @@ -110,4 +108,31 @@ class VerifySecurityAlerts extends Command return 0; } + + /** + * @return void + */ + private function removeOldAdvisory(): void + { + try { + app('fireflyconfig')->delete('upgrade_security_message'); + app('fireflyconfig')->delete('upgrade_security_level'); + } catch (QueryException $e) { + Log::debug(sprintf('Could not delete old security advisory, but thats OK: %s', $e->getMessage())); + } + } + + /** + * @param array $array + * @return void + */ + private function saveSecurityAdvisory(array $array): void + { + try { + app('fireflyconfig')->set('upgrade_security_message', $array['message']); + app('fireflyconfig')->set('upgrade_security_level', $array['level']); + } catch (QueryException $e) { + Log::debug(sprintf('Could not save new security advisory, but thats OK: %s', $e->getMessage())); + } + } }