From f4a3a3fbd3cf3909a9481e36b8ecbd8e5f46a9de Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 21 Oct 2022 16:25:19 +0300 Subject: [PATCH] extension admin notifications --- .../Core/Utils/AdminNotificationManager.php | 60 +++++++++++++++++++ .../Espo/Resources/i18n/en_US/Global.json | 3 +- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/application/Espo/Core/Utils/AdminNotificationManager.php b/application/Espo/Core/Utils/AdminNotificationManager.php index c5d104180d..f6c6e495ea 100644 --- a/application/Espo/Core/Utils/AdminNotificationManager.php +++ b/application/Espo/Core/Utils/AdminNotificationManager.php @@ -29,6 +29,7 @@ namespace Espo\Core\Utils; +use Espo\Entities\Extension; use Espo\ORM\EntityManager; /** @@ -109,6 +110,13 @@ class AdminNotificationManager } } + if (!$this->config->get('adminNotificationsExtensionLicenseDisabled')) { + $notificationList = array_merge( + $notificationList, + $this->getExtensionLicenseNotificationList() + ); + } + return $notificationList; } @@ -203,4 +211,56 @@ class AdminNotificationManager return $message; } + + /** + * @return array + */ + private function getExtensionLicenseNotificationList(): array + { + $extensionList = $this->entityManager + ->getRDBRepositoryByClass(Extension::class) + ->where([ + 'licenseStatus' => [ + Extension::LICENSE_STATUS_INVALID, + Extension::LICENSE_STATUS_EXPIRED, + Extension::LICENSE_STATUS_SOFT_EXPIRED, + ], + ]) + ->find(); + + $list = []; + + foreach ($extensionList as $extension) { + $message = + $extension->getLicenseStatusMessage() ?? + $this->getExtensionLicenseMessageLabel($extension); + + if (!$message) { + continue; + } + + $message = $this->language->translateLabel($message, 'messages'); + + $name = $extension->getName(); + + $list[] = [ + 'id' => 'newExtensionVersionIsAvailable' . Util::toCamelCase($name, ' ', true), + 'type' => 'newExtensionVersionIsAvailable', + 'message' => $this->prepareMessage($message, ['name' => $name]), + ]; + } + + return $list; + } + + private function getExtensionLicenseMessageLabel(Extension $extension): ?string + { + $status = $extension->getLicenseStatus(); + + if (!$status) { + return null; + } + + return 'extensionLicense' . ucfirst(Util::hyphenToCamelCase($status)); + } } diff --git a/application/Espo/Resources/i18n/en_US/Global.json b/application/Espo/Resources/i18n/en_US/Global.json index 1d747160fc..06ffeee1cc 100644 --- a/application/Espo/Resources/i18n/en_US/Global.json +++ b/application/Espo/Resources/i18n/en_US/Global.json @@ -361,7 +361,8 @@ "massActionProcessed": "Mass action has been processed.", "validationFailure": "Backend validation failure.\n\nField: `{field}`\nValidation: `{type}`", "extensionLicenseInvalid": "Invalid '{name}' extension license.", - "extensionLicenseExpired": "Expired '{name}' extension license.", + "extensionLicenseExpired": "The '{name}' extension license subscription has expired.", + "extensionLicenseSoftExpired": "The '{name}' extension license subscription has expired.", "confirmAppRefresh": "The application has been updated. It is recommended to refresh the page to ensure the proper functioning.", "error404": "The url you requested can't be handled.", "error403": "You don't have an access to this area."