From 315f7a0d16a6d001431a483a97639e1bdace6cf6 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Fri, 20 Oct 2023 08:16:22 +0200 Subject: [PATCH] MOL-1124: do not load settings without db (#644) * MOL-1124: do not load settings without db * MOL-1124: code style * MOL-1124: CS Fix --------- Co-authored-by: Vitalij Mik --- src/Resources/config/services/services.xml | 1 + src/Service/Logger/MollieLoggerFactory.php | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Resources/config/services/services.xml b/src/Resources/config/services/services.xml index 7b021e49a..4c32a5a86 100644 --- a/src/Resources/config/services/services.xml +++ b/src/Resources/config/services/services.xml @@ -10,6 +10,7 @@ %kernel.logs_dir%/mollie_%kernel.environment%.log 14 + %env(DATABASE_URL)% diff --git a/src/Service/Logger/MollieLoggerFactory.php b/src/Service/Logger/MollieLoggerFactory.php index 6bc859447..39d746d99 100644 --- a/src/Service/Logger/MollieLoggerFactory.php +++ b/src/Service/Logger/MollieLoggerFactory.php @@ -36,17 +36,24 @@ class MollieLoggerFactory */ private $retentionDays; + /** + * @var string + */ + private $dsn; + /** * @param SettingsService $settingsService * @param string $filename * @param string $retentionDays + * @param string $dsn */ - public function __construct(SettingsService $settingsService, string $filename, string $retentionDays) + public function __construct(SettingsService $settingsService, string $filename, string $retentionDays, string $dsn) { $this->settingsService = $settingsService; $this->filename = $filename; $this->retentionDays = $retentionDays; + $this->dsn = $dsn; } /** @@ -54,6 +61,11 @@ public function __construct(SettingsService $settingsService, string $filename, */ public function createLogger(): LoggerInterface { + if ($this->dsn === '' || $this->dsn === 'mysql://_placeholder.test') { + // deployment server without database + return new Logger(self::CHANNEL); + } + $config = $this->settingsService->getSettings(); # 100 = DEBUG, 200 = INFO