From 9a335e2159ba4bc60b117ba1315312f7c684ead3 Mon Sep 17 00:00:00 2001 From: RahatHameed Date: Mon, 15 Jul 2024 16:18:16 +0200 Subject: [PATCH] OXDEV-8489 Extended ModuleDeactivationException --- src/Module/Exception/ModuleDeactivationException.php | 10 +++++++--- src/Module/Service/ModuleSwitchService.php | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Module/Exception/ModuleDeactivationException.php b/src/Module/Exception/ModuleDeactivationException.php index b4c40d0..6a29364 100644 --- a/src/Module/Exception/ModuleDeactivationException.php +++ b/src/Module/Exception/ModuleDeactivationException.php @@ -13,10 +13,14 @@ final class ModuleDeactivationException extends NotFound { - public const EXCEPTION_MESSAGE = "This Module is in the blocklist and cannot be deactivated."; + public const EXCEPTION_MESSAGE = "An error occurred while deactivating the module."; + public const BLOCKED_MODULE_MESSAGE = 'Module "%s" is in the blocklist and cannot be deactivated.'; - public function __construct() + public function __construct(string $message = null) { - parent::__construct(self::EXCEPTION_MESSAGE); + if (empty($message)) { + $message = self::EXCEPTION_MESSAGE; + } + parent::__construct($message); } } diff --git a/src/Module/Service/ModuleSwitchService.php b/src/Module/Service/ModuleSwitchService.php index 414a962..04a7de2 100644 --- a/src/Module/Service/ModuleSwitchService.php +++ b/src/Module/Service/ModuleSwitchService.php @@ -34,7 +34,9 @@ public function activateModule(string $moduleId): bool public function deactivateModule(string $moduleId): bool { if ($this->moduleBlocklistService->isModuleBlocked($moduleId)) { - throw new ModuleDeactivationException(); + throw new ModuleDeactivationException( + sprintf(ModuleDeactivationException::BLOCKED_MODULE_MESSAGE, $moduleId) + ); } return $this->moduleSwitchInfrastructure->deactivateModule(moduleId: $moduleId); }