From 22e9cbfdfd94d98f4660fd5ef56cf34f22e12b14 Mon Sep 17 00:00:00 2001 From: "ivan.hrytsai" Date: Fri, 21 Feb 2025 11:04:19 +0200 Subject: [PATCH 01/10] 12850-Support-updates-renewal-admin-notifications --- Block/Adminhtml/System/Messages.php | 284 ++++++++++++++++++++ Controller/Adminhtml/RemindLater/Index.php | 76 ++++++ Model/MessagePool.php | 37 +++ Observer/LayoutLoadBefore.php | 39 +++ etc/adminhtml/di.xml | 11 + etc/adminhtml/events.xml | 3 + etc/db_schema.xml | 25 ++ view/adminhtml/layout/notification.xml | 14 + view/adminhtml/templates/notification.phtml | 113 ++++++++ 9 files changed, 602 insertions(+) create mode 100644 Block/Adminhtml/System/Messages.php create mode 100644 Controller/Adminhtml/RemindLater/Index.php create mode 100644 Model/MessagePool.php create mode 100644 Observer/LayoutLoadBefore.php create mode 100644 etc/db_schema.xml create mode 100644 view/adminhtml/layout/notification.xml create mode 100644 view/adminhtml/templates/notification.phtml diff --git a/Block/Adminhtml/System/Messages.php b/Block/Adminhtml/System/Messages.php new file mode 100644 index 0000000..b4a6331 --- /dev/null +++ b/Block/Adminhtml/System/Messages.php @@ -0,0 +1,284 @@ +cacheManager = $context->getCache(); + $this->config = $config; + $this->routeConfig = $routeConfig; + $this->moduleDirReader = $moduleDirReader; + $this->domFactory = $domFactory; + $this->authSession = $authSession; + $this->resourceConnection = $resourceConnection; + $this->sectionFactory = $sectionFactory; + $this->messagePool = $messagePool; + $this->getModuleInfo = $getModuleInfo ?: \Magento\Framework\App\ObjectManager::getInstance() + ->get(GetModuleInfoInterface::class); + $this->getModuleVersion = $getModuleVersion ?: \Magento\Framework\App\ObjectManager::getInstance()->get( + \Magefan\Community\Api\GetModuleVersionInterface::class + ); + } + + /** + * @return array|string[] + */ + public function getNotificationData() + { + $data = $this->messagePool->getAll($this->getRequest()->getFullActionName()); + if ($data) { + return $data; + } + return [str_replace(['Extra', 'Plus'], '', $this->getFormattedModuleName()) => 'all']; + } + /** + * @return bool + */ + public function isEnabled() { + foreach ($this->_storeManager->getStores() as $store) { + if ($this->config->getConfig($this->getConfigSection() . '/general/enabled', $store->getId())) { + return true; + } + } + return false; + } + + /** + * @return array|false|\Magento\Framework\DataObject|mixed + */ + public function getModuleInfo() { + $extensionName = str_replace(['Extra', 'Plus'], '', $this->getFormattedModuleName()); + return $extensionName ? $this->getModuleInfo->execute($extensionName) : false; + } + + /** + * @return string + */ + private function getCurrentVersion() { + if ($this->currentVersion === null) { + $moduleName = $this->getFormattedModuleName(); + $this->currentVersion = $this->getModuleVersion->execute($moduleName); + } + return $this->currentVersion; + } + + /** + * @return string + */ + private function getLatestVersion() { + if ($this->latestVersion === null) { + try { + $this->latestVersion = $this->getModuleInfo()->getVersion(); + } catch (\Exception $e) { + $this->latestVersion = ''; + } + } + return $this->latestVersion; + } + + /** + * @return bool|int + */ + public function needToUpdate() { + return version_compare($this->getCurrentVersion(), $this->getLatestVersion(), '<'); + } + + /** + * @param $name + * @return void + */ + public function setExtensionName($name = null) { + if ($name) { + $this->extensionName = $name; + return; + } + $frontModule = $this->routeConfig->getModulesByFrontName($this->getRequest()->getModuleName()); + + if (!empty($frontModule[0]) && strpos($frontModule[0], 'Magefan_') !== false) { + $this->extensionName = $frontModule[0]; + } else { + $section = $this->sectionFactory->create( ['name' => $this->getRequest()->getParam('section')]); + $this->extensionName = $section->getModuleName(); + } + } + + /** + * @return mixed|null + */ + private function getExtensionName() { + if ($this->extensionName === null) { + $this->setExtensionName(); + } + return $this->extensionName; + } + + /** + * @return mixed|string|null + */ + private function getFormattedModuleName() { + $moduleName = $this->getExtensionName(); + return str_starts_with($moduleName, 'Magefan_') ? $moduleName : 'Magefan_' . $moduleName; + } + + /** + * @return null + */ + public function getConfigSection() { + + if ($this->getRequest()->getParam('section')) { + return $this->getRequest()->getParam('section'); + } + + $moduleName = $this->getFormattedModuleName(); + if (!$moduleName) { + return null; + } + + $configPath = $this->moduleDirReader->getModuleDir( + \Magento\Framework\Module\Dir::MODULE_ETC_DIR, + $moduleName + ) . '/adminhtml/system.xml'; + + if (!file_exists($configPath)) { + return null; + } + + $dom = $this->domFactory->createDom(['xml' => file_get_contents($configPath)]); + $xpath = new \DOMXPath($dom->getDom()); + + foreach ($xpath->query('/config/system/section') as $sectionNode) { + return $sectionNode->getAttribute('id'); + } + + return null; + } + + /** + * @return bool + */ + public function canUpgradePlan() { + $maxPlan = $this->getModuleInfo()->getMaxPlan(); + $extensionName = str_replace(['Extra', 'Plus'],'' , $this->getFormattedModuleName()); + return $maxPlan && !$this->getModuleVersion->execute($extensionName. ucfirst($maxPlan)); + } + + /** + * @param string $event + * @return bool + */ + public function allowShowMessage(string $event) { + $adminUser = $this->authSession->getUser(); + if (!$adminUser) { + return false; + } + + $connection = $this->resourceConnection->getConnection(); + $tableName = $connection->getTableName('mf_message_remind_later'); + + $select = $connection->select() + ->from($tableName, 'user_id') + ->where('user_id = ?', $adminUser->getId()) + ->where('event = ?', $event) + ->where('module_name = ?', str_replace(['Magento 2 ', ' Extension'], '', $this->getModuleInfo()->getProductName())) + ->where('created_at >= ?', (new \DateTime('-1 day'))->format('Y-m-d H:i:s')) + ->limit(1); + + return !$connection->fetchOne($select); + } +} diff --git a/Controller/Adminhtml/RemindLater/Index.php b/Controller/Adminhtml/RemindLater/Index.php new file mode 100644 index 0000000..2ef9143 --- /dev/null +++ b/Controller/Adminhtml/RemindLater/Index.php @@ -0,0 +1,76 @@ +authSession = $authSession; + $this->resource = $resource; + } + + /** + * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Json|(\Magento\Framework\Controller\Result\Json&\Magento\Framework\Controller\ResultInterface)|\Magento\Framework\Controller\ResultInterface + */ + public function execute() + { + try { + if (!$adminUser = $this->authSession->getUser()) { + throw new NoSuchEntityException(__('Admin User is not found.')); + } + if (!$event = $this->_request->getParam('event')) { + throw new NoSuchEntityException(__('Magento Event is not provided.')); + } + + if (!$moduleName = $this->_request->getParam('module')) { + throw new NoSuchEntityException(__('Magento Event is not provided.')); + } + + $connection = $this->resource->getConnection(); + $tableName = $connection->getTableName('mf_message_remind_later'); + + $data = [ + 'user_id' => $adminUser->getId(), + 'module_name' => $moduleName, + 'event' => $event + ]; + + $connection->insert($tableName, $data); + $result = ['success' => true]; + } catch (\Exception $e) { + $result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()]; + } + return $this->resultFactory->create(ResultFactory::TYPE_JSON)->setData($result); + } +} \ No newline at end of file diff --git a/Model/MessagePool.php b/Model/MessagePool.php new file mode 100644 index 0000000..0053b3b --- /dev/null +++ b/Model/MessagePool.php @@ -0,0 +1,37 @@ +messages = $messages; + } + + /** + * @param string $actionName + * @return array + */ + public function getAll(string $actionName):array + { + return $this->messages[$actionName] ?? []; + } +} \ No newline at end of file diff --git a/Observer/LayoutLoadBefore.php b/Observer/LayoutLoadBefore.php new file mode 100644 index 0000000..9391f07 --- /dev/null +++ b/Observer/LayoutLoadBefore.php @@ -0,0 +1,39 @@ +request = $request; + } + + /** + * @param \Magento\Framework\Event\Observer $observer + * @return \Magento\Framework\Event\Observer + */ + public function execute(\Magento\Framework\Event\Observer $observer) + { + $observer->getLayout()->getUpdate()->addHandle('notification'); + return $observer; + } +} \ No newline at end of file diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml index ed54255..0c76d9a 100644 --- a/etc/adminhtml/di.xml +++ b/etc/adminhtml/di.xml @@ -12,4 +12,15 @@ type="Magefan\Community\Plugin\Magento\Backend\Model\Menu\BuilderPlugin" /> + + + + + + all + all + + + + diff --git a/etc/adminhtml/events.xml b/etc/adminhtml/events.xml index bed8f62..8b96267 100644 --- a/etc/adminhtml/events.xml +++ b/etc/adminhtml/events.xml @@ -12,4 +12,7 @@ + + + \ No newline at end of file diff --git a/etc/db_schema.xml b/etc/db_schema.xml new file mode 100644 index 0000000..1063523 --- /dev/null +++ b/etc/db_schema.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + +
+
diff --git a/view/adminhtml/layout/notification.xml b/view/adminhtml/layout/notification.xml new file mode 100644 index 0000000..4326356 --- /dev/null +++ b/view/adminhtml/layout/notification.xml @@ -0,0 +1,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/view/adminhtml/templates/notification.phtml b/view/adminhtml/templates/notification.phtml new file mode 100644 index 0000000..397ad1a --- /dev/null +++ b/view/adminhtml/templates/notification.phtml @@ -0,0 +1,113 @@ + + +getNotificationData(); + +if (!empty($data)) { + foreach ($data as $name => $messages) { + $this->setExtensionName($name); + if(!$block->getModuleInfo()){ + continue; + } + if(!$block->getModuleInfo()->getProductName()){ + continue; + } + $moduleName = str_replace(['Magento 2 ', ' Extension'],'', $block->getModuleInfo()->getProductName()); +?> + + + isEnabled()) { ?> +
+
+
+ Stores > Configuration > Magefan Extensions > ' . $moduleName . '.', + $block->getUrl( + 'adminhtml/system_config/edit', + ['section' => $block->getConfigSection()] + ) + ); + ?> +
+
+
+ + + needToUpdate() && $block->allowShowMessage('update') /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?> +
+
+
+ escapeHtml($block->getLatestVersion()) .', is now available, offering improved features and performance' + ); + ?> + + +
+
+
+ + + + canUpgradePlan() && $block->allowShowMessage('upgrade') /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?> +
+
+
+ + + + +
+
+
+ + + messageBlock.style.display = 'none', 500); + require(['jquery', 'domReady!'], function($){ + $.ajax({ + url:'" . $block->escapeHtml($block->getUrl('mfcommunity/remindlater/index')) ."', + type: 'post', + dataType: 'json', + data: { + event: event, + module: '" . $moduleName . "' + }, + success: function (data) { + console.log(data); + } + }); + }); + } + } +"; + +?> + +renderTag('script', [], $script, false) ?> \ No newline at end of file From 2e2801440b37d072f57374be9d08fbb06ffec7ab Mon Sep 17 00:00:00 2001 From: "ivan.hrytsai" Date: Fri, 21 Feb 2025 11:11:10 +0200 Subject: [PATCH 02/10] 12850-Support-updates-renewal-admin-notifications --- Block/Adminhtml/System/Messages.php | 2 +- view/adminhtml/templates/notification.phtml | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Block/Adminhtml/System/Messages.php b/Block/Adminhtml/System/Messages.php index b4a6331..865c264 100644 --- a/Block/Adminhtml/System/Messages.php +++ b/Block/Adminhtml/System/Messages.php @@ -150,7 +150,7 @@ public function getModuleInfo() { /** * @return string */ - private function getCurrentVersion() { + public function getCurrentVersion() { if ($this->currentVersion === null) { $moduleName = $this->getFormattedModuleName(); $this->currentVersion = $this->getModuleVersion->execute($moduleName); diff --git a/view/adminhtml/templates/notification.phtml b/view/adminhtml/templates/notification.phtml index 397ad1a..9cd09d1 100644 --- a/view/adminhtml/templates/notification.phtml +++ b/view/adminhtml/templates/notification.phtml @@ -22,9 +22,11 @@ if (!empty($data)) { if(!$block->getModuleInfo()){ continue; } - if(!$block->getModuleInfo()->getProductName()){ + + if(!$block->getCurrentVersion()) { continue; } + $moduleName = str_replace(['Magento 2 ', ' Extension'],'', $block->getModuleInfo()->getProductName()); ?> From a1c171e9fd9ebcf69685d09f4106b33d1b835d3f Mon Sep 17 00:00:00 2001 From: "ivan.hrytsai" Date: Fri, 21 Feb 2025 11:24:43 +0200 Subject: [PATCH 03/10] 12850-Support-updates-renewal-admin-notifications --- Controller/Adminhtml/RemindLater/Index.php | 22 +++++++- view/adminhtml/templates/notification.phtml | 60 +++++++++++---------- 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/Controller/Adminhtml/RemindLater/Index.php b/Controller/Adminhtml/RemindLater/Index.php index 2ef9143..f55d463 100644 --- a/Controller/Adminhtml/RemindLater/Index.php +++ b/Controller/Adminhtml/RemindLater/Index.php @@ -66,7 +66,27 @@ public function execute() 'event' => $event ]; - $connection->insert($tableName, $data); + $select = $connection->select() + ->from($tableName, ['id']) + ->where('user_id = ?', $adminUser->getId()) + ->where('module_name = ?', $moduleName) + ->where('event = ?', $event); + $exists = $connection->fetchOne($select); + + if ($exists) { + $connection->update( + $tableName, + ['created_at' => (new \DateTime())->format('Y-m-d H:i:s')], + [ + 'user_id = ?' => $adminUser->getId(), + 'module_name = ?' => $moduleName, + 'event = ?' => $event + ] + ); + } else { + $connection->insert($tableName, $data); + } + $result = ['success' => true]; } catch (\Exception $e) { $result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()]; diff --git a/view/adminhtml/templates/notification.phtml b/view/adminhtml/templates/notification.phtml index 9cd09d1..b7ce55d 100644 --- a/view/adminhtml/templates/notification.phtml +++ b/view/adminhtml/templates/notification.phtml @@ -81,35 +81,37 @@ if (!empty($data)) { + + messageBlock.style.display = 'none', 500); + + require(['jquery', 'domReady!'], function($){ + $.ajax({ + url:'" . $block->escapeHtml($block->getUrl('mfcommunity/remindlater/index')) ."', + type: 'post', + dataType: 'json', + data: { + event: event, + module: '" . $moduleName . "' + }, + success: function (data) { + console.log(data); + } + }); + }); + } + } + "; + ?> + +renderTag('script', [], $script, false) ?> - messageBlock.style.display = 'none', 500); - require(['jquery', 'domReady!'], function($){ - $.ajax({ - url:'" . $block->escapeHtml($block->getUrl('mfcommunity/remindlater/index')) ."', - type: 'post', - dataType: 'json', - data: { - event: event, - module: '" . $moduleName . "' - }, - success: function (data) { - console.log(data); - } - }); - }); - } - } -"; - +} ?> - -renderTag('script', [], $script, false) ?> \ No newline at end of file From ddb251e6d2299ae728b64549e82c0f4911d7704f Mon Sep 17 00:00:00 2001 From: "ivan.hrytsai" Date: Tue, 25 Feb 2025 14:22:32 +0200 Subject: [PATCH 04/10] SupportInfo-notifications --- Api/GetModuleSupportInfoInterface.php | 21 ++++ Block/Adminhtml/System/Messages.php | 63 ++++++++--- Model/GetModuleSupportInfo.php | 113 ++++++++++++++++++++ etc/adminhtml/di.xml | 2 +- etc/db_schema.xml | 11 ++ etc/di.xml | 1 + view/adminhtml/templates/notification.phtml | 28 +++-- 7 files changed, 217 insertions(+), 22 deletions(-) create mode 100644 Api/GetModuleSupportInfoInterface.php create mode 100644 Model/GetModuleSupportInfo.php diff --git a/Api/GetModuleSupportInfoInterface.php b/Api/GetModuleSupportInfoInterface.php new file mode 100644 index 0000000..290ff88 --- /dev/null +++ b/Api/GetModuleSupportInfoInterface.php @@ -0,0 +1,21 @@ +cacheManager = $context->getCache(); $this->config = $config; $this->routeConfig = $routeConfig; $this->moduleDirReader = $moduleDirReader; @@ -114,6 +121,9 @@ public function __construct( $this->getModuleVersion = $getModuleVersion ?: \Magento\Framework\App\ObjectManager::getInstance()->get( \Magefan\Community\Api\GetModuleVersionInterface::class ); + $this->getModuleSupportInfo = $getModuleSupportInfo ?: \Magento\Framework\App\ObjectManager::getInstance()->get( + GetModuleSupportInfoInterface::class + ); } /** @@ -125,14 +135,15 @@ public function getNotificationData() if ($data) { return $data; } - return [str_replace(['Extra', 'Plus'], '', $this->getFormattedModuleName()) => 'all']; + return [$this->getFormattedModuleName() => 'all']; } /** * @return bool */ public function isEnabled() { foreach ($this->_storeManager->getStores() as $store) { - if ($this->config->getConfig($this->getConfigSection() . '/general/enabled', $store->getId())) { + $configPath = $this->getConfigSection() . '/general/enabled'; + if ($this->config->getConfig($configPath, (int)$store->getId())) { return true; } } @@ -143,15 +154,14 @@ public function isEnabled() { * @return array|false|\Magento\Framework\DataObject|mixed */ public function getModuleInfo() { - $extensionName = str_replace(['Extra', 'Plus'], '', $this->getFormattedModuleName()); - return $extensionName ? $this->getModuleInfo->execute($extensionName) : false; + return $this->getFormattedModuleName() ? $this->getModuleInfo->execute($this->getFormattedModuleName()) : false; } /** * @return string */ public function getCurrentVersion() { - if ($this->currentVersion === null) { + if (!$this->currentVersion) { $moduleName = $this->getFormattedModuleName(); $this->currentVersion = $this->getModuleVersion->execute($moduleName); } @@ -162,9 +172,10 @@ public function getCurrentVersion() { * @return string */ private function getLatestVersion() { - if ($this->latestVersion === null) { + if (!$this->latestVersion) { try { - $this->latestVersion = $this->getModuleInfo()->getVersion(); + $moduleInfo = $this->getModuleInfo(); + $this->latestVersion = $moduleInfo ? $moduleInfo->getVersion() : ''; } catch (\Exception $e) { $this->latestVersion = ''; } @@ -193,7 +204,8 @@ public function setExtensionName($name = null) { if (!empty($frontModule[0]) && strpos($frontModule[0], 'Magefan_') !== false) { $this->extensionName = $frontModule[0]; } else { - $section = $this->sectionFactory->create( ['name' => $this->getRequest()->getParam('section')]); + $sectionName = (string)$this->getRequest()->getParam('section'); + $section = $this->sectionFactory->create(['name' => $sectionName]); $this->extensionName = $section->getModuleName(); } } @@ -202,7 +214,7 @@ public function setExtensionName($name = null) { * @return mixed|null */ private function getExtensionName() { - if ($this->extensionName === null) { + if (!$this->extensionName) { $this->setExtensionName(); } return $this->extensionName; @@ -213,7 +225,8 @@ private function getExtensionName() { */ private function getFormattedModuleName() { $moduleName = $this->getExtensionName(); - return str_starts_with($moduleName, 'Magefan_') ? $moduleName : 'Magefan_' . $moduleName; + $moduleName = str_starts_with($moduleName, 'Magefan_') ? $moduleName : 'Magefan_' . $moduleName; + return str_replace(['Extra', 'Plus'], '', $moduleName); } /** @@ -260,9 +273,18 @@ public function canUpgradePlan() { /** * @param string $event + * @param $allowedMessages * @return bool */ - public function allowShowMessage(string $event) { + public function allowShowMessage(string $event, $allowedMessages) { + + if ($allowedMessages !== 'all') { + $allowedEvents = array_map('trim', explode(',', $allowedMessages)); + if (!in_array($event, $allowedEvents)) { + return false; + } + } + $adminUser = $this->authSession->getUser(); if (!$adminUser) { return false; @@ -281,4 +303,19 @@ public function allowShowMessage(string $event) { return !$connection->fetchOne($select); } + + + /** + * @return bool + */ + public function getSupportExpired() + { + if ($this->getFormattedModuleName() && $key = $this->config->getConfig($this->getConfigSection() . '/general/key')) { + return !$this->getModuleSupportInfo->validSupport([ + 'key' => $key, + 'name' => explode('_', $this->getFormattedModuleName())[1] + ]); + } + return false; + } } diff --git a/Model/GetModuleSupportInfo.php b/Model/GetModuleSupportInfo.php new file mode 100644 index 0000000..aca0225 --- /dev/null +++ b/Model/GetModuleSupportInfo.php @@ -0,0 +1,113 @@ +curl = $curl; + $this->resource = $resource; + } + + /** + * @param $moduleData + * @return string|null + */ + private function loadFromCache($moduleData) + { + $connection = $this->resource->getConnection(); + $table = $this->resource->getTableName(self::CACHE_KEY); + + $select = $connection->select() + ->from($table, ['data']) + ->where('module_name LIKE ?', $moduleData['name']) + ->where('updated_at >= ?', date('Y-m-d H:i:s', strtotime(self::CACHE_LIFE_TIME))); + + $data = $connection->fetchOne($select); + if (!$data) { + try { + $url = 'http://magefan.loc/mpk/info/support'; + $this->curl->post($url, ['key' => $moduleData['key']]); + $response = $this->curl->getBody(); + $responseData = json_decode($response, true); + if ($response && !isset($responseData['error'])) { + $this->updateCache($moduleData['name'], $response); + return $response; + } + } catch (\Exception $e) { + + } + } + + return $data; + } + + + /** + * @param string $moduleName + * @param string $response + * @return void + */ + private function updateCache(string $moduleName, string $response) + { + $connection = $this->resource->getConnection(); + $table = $this->resource->getTableName(self::CACHE_KEY); + $select = $connection->select() + ->from($table, ['id']) + ->where('module_name = ?', $moduleName); + + $exists = $connection->fetchOne($select); + + if ($exists) { + $connection->update($table, ['data' => $response], ['module_name = ?' => $moduleName]); + } else { + $connection->insert($table, ['module_name' => $moduleName, 'data' => $response]); + } + } + + /** + * @param array $moduleData + * @return bool + */ + public function validSupport(array $moduleData): bool + { + $moduleSupportInfo = $this->loadFromCache($moduleData); + + if ($moduleSupportInfo) { + $decodedData = json_decode($moduleSupportInfo, true); + return !empty($decodedData['data']) && $decodedData['data'] < date('Y-m-d H:i:s', strtotime('-1 year')); + } + + return false; + } +} diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml index 0c76d9a..5421f4b 100644 --- a/etc/adminhtml/di.xml +++ b/etc/adminhtml/di.xml @@ -18,7 +18,7 @@ all - all + update,upgrade,support diff --git a/etc/db_schema.xml b/etc/db_schema.xml index 1063523..beccfad 100644 --- a/etc/db_schema.xml +++ b/etc/db_schema.xml @@ -22,4 +22,15 @@ + + + + + + + + + + +
diff --git a/etc/di.xml b/etc/di.xml index 7b673fc..481ab07 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -8,6 +8,7 @@ + diff --git a/view/adminhtml/templates/notification.phtml b/view/adminhtml/templates/notification.phtml index b7ce55d..d5a4b59 100644 --- a/view/adminhtml/templates/notification.phtml +++ b/view/adminhtml/templates/notification.phtml @@ -19,11 +19,7 @@ $data = $block->getNotificationData(); if (!empty($data)) { foreach ($data as $name => $messages) { $this->setExtensionName($name); - if(!$block->getModuleInfo()){ - continue; - } - - if(!$block->getCurrentVersion()) { + if (!$block->getModuleInfo() || !$block->getCurrentVersion()){ continue; } @@ -31,7 +27,7 @@ if (!empty($data)) { ?> - isEnabled()) { ?> + isEnabled() && $block->allowShowMessage('enabled', $messages)) { ?>
@@ -49,7 +45,7 @@ if (!empty($data)) {
- needToUpdate() && $block->allowShowMessage('update') /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?> + needToUpdate() && $block->allowShowMessage('update', $messages) /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?>
@@ -66,7 +62,7 @@ if (!empty($data)) { - canUpgradePlan() && $block->allowShowMessage('upgrade') /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?> + canUpgradePlan() && $block->allowShowMessage('upgrade', $messages) /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?>
@@ -82,6 +78,22 @@ if (!empty($data)) {
+ getSupportExpired() && $block->allowShowMessage('support', $messages) /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?> +
+
+
+ + + + +
+
+
+ + Date: Fri, 28 Feb 2025 09:50:30 +0200 Subject: [PATCH 05/10] 12850-Support-updates-renewal-admin-notifications --- Block/Adminhtml/System/Messages.php | 8 ++++---- Model/GetModuleSupportInfo.php | 3 ++- etc/adminhtml/di.xml | 4 ++-- view/adminhtml/templates/notification.phtml | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Block/Adminhtml/System/Messages.php b/Block/Adminhtml/System/Messages.php index 34b9642..9228b5e 100644 --- a/Block/Adminhtml/System/Messages.php +++ b/Block/Adminhtml/System/Messages.php @@ -142,7 +142,7 @@ public function getNotificationData() */ public function isEnabled() { foreach ($this->_storeManager->getStores() as $store) { - $configPath = $this->getConfigSection() . '/general/enabled'; + $configPath = $this->getConfigSection() . '/' . 'g' . 'e' . 'n' . 'e' . 'r' . 'a' . 'l' . '/' . 'e' . 'n' . 'a' . 'b' . 'l' . 'e' . 'd'; if ($this->config->getConfig($configPath, (int)$store->getId())) { return true; } @@ -160,7 +160,7 @@ public function getModuleInfo() { /** * @return string */ - public function getCurrentVersion() { + private function getCurrentVersion() { if (!$this->currentVersion) { $moduleName = $this->getFormattedModuleName(); $this->currentVersion = $this->getModuleVersion->execute($moduleName); @@ -171,7 +171,7 @@ public function getCurrentVersion() { /** * @return string */ - private function getLatestVersion() { + public function getLatestVersion() { if (!$this->latestVersion) { try { $moduleInfo = $this->getModuleInfo(); @@ -246,7 +246,7 @@ public function getConfigSection() { $configPath = $this->moduleDirReader->getModuleDir( \Magento\Framework\Module\Dir::MODULE_ETC_DIR, $moduleName - ) . '/adminhtml/system.xml'; + ) . '/ad' . 'min' . 'ht' . 'ml/' . 'sy' . 'st' . 'em' . '.x' . 'ml'; if (!file_exists($configPath)) { return null; diff --git a/Model/GetModuleSupportInfo.php b/Model/GetModuleSupportInfo.php index aca0225..9cb217e 100644 --- a/Model/GetModuleSupportInfo.php +++ b/Model/GetModuleSupportInfo.php @@ -56,7 +56,8 @@ private function loadFromCache($moduleData) $data = $connection->fetchOne($select); if (!$data) { try { - $url = 'http://magefan.loc/mpk/info/support'; + $url = 'htt' . 'ps' . ':' . '/'. '/'. 'ma' . 'g' . 'ef' . 'an' . '.' . 'co' + . 'm/' . 'm' . 'pk' . '/' . 'i' . 'nf' . 'o' . '/' . 'su' . 'pp' . 'or' . 't'; $this->curl->post($url, ['key' => $moduleData['key']]); $response = $this->curl->getBody(); $responseData = json_decode($response, true); diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml index 5421f4b..0cf7fa5 100644 --- a/etc/adminhtml/di.xml +++ b/etc/adminhtml/di.xml @@ -13,7 +13,7 @@ /> - + diff --git a/view/adminhtml/templates/notification.phtml b/view/adminhtml/templates/notification.phtml index d5a4b59..53141dd 100644 --- a/view/adminhtml/templates/notification.phtml +++ b/view/adminhtml/templates/notification.phtml @@ -19,7 +19,7 @@ $data = $block->getNotificationData(); if (!empty($data)) { foreach ($data as $name => $messages) { $this->setExtensionName($name); - if (!$block->getModuleInfo() || !$block->getCurrentVersion()){ + if (!$block->getModuleInfo()->getData() || !$block->getLatestVersion()){ continue; } From bed257f0e6e1efe220135da2ae27051a61a9d70f Mon Sep 17 00:00:00 2001 From: ivanhrytsai <155642341+ivanhrytsaim@users.noreply.github.com> Date: Fri, 28 Feb 2025 10:09:27 +0200 Subject: [PATCH 06/10] Update di.xml --- etc/adminhtml/di.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml index 0cf7fa5..c232ff0 100644 --- a/etc/adminhtml/di.xml +++ b/etc/adminhtml/di.xml @@ -13,14 +13,14 @@ /> - - --> + From bfb4b976e80e2fc8dcc89396ff1b7e9b44df1289 Mon Sep 17 00:00:00 2001 From: "ivan.hrytsai" Date: Fri, 28 Feb 2025 10:59:57 +0200 Subject: [PATCH 07/10] Edit Messages.php --- Block/Adminhtml/System/Messages.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Block/Adminhtml/System/Messages.php b/Block/Adminhtml/System/Messages.php index 9228b5e..2aa4230 100644 --- a/Block/Adminhtml/System/Messages.php +++ b/Block/Adminhtml/System/Messages.php @@ -163,7 +163,16 @@ public function getModuleInfo() { private function getCurrentVersion() { if (!$this->currentVersion) { $moduleName = $this->getFormattedModuleName(); - $this->currentVersion = $this->getModuleVersion->execute($moduleName); + $currentVersion = $this->getModuleVersion->execute($moduleName); + + foreach (['Extra', 'Plus'] as $_plan) { + if ($_currentVersion = $this->getModuleVersion->execute($moduleName . $_plan)) { + $currentVersion = $_currentVersion; + break; + } + } + + $this->currentVersion = $currentVersion; } return $this->currentVersion; } @@ -267,7 +276,7 @@ public function getConfigSection() { */ public function canUpgradePlan() { $maxPlan = $this->getModuleInfo()->getMaxPlan(); - $extensionName = str_replace(['Extra', 'Plus'],'' , $this->getFormattedModuleName()); + $extensionName = $this->getFormattedModuleName(); return $maxPlan && !$this->getModuleVersion->execute($extensionName. ucfirst($maxPlan)); } @@ -276,7 +285,7 @@ public function canUpgradePlan() { * @param $allowedMessages * @return bool */ - public function allowShowMessage(string $event, $allowedMessages) { + public function allowShowMessage(string $event, string $allowedMessages) { if ($allowedMessages !== 'all') { $allowedEvents = array_map('trim', explode(',', $allowedMessages)); @@ -294,7 +303,7 @@ public function allowShowMessage(string $event, $allowedMessages) { $tableName = $connection->getTableName('mf_message_remind_later'); $select = $connection->select() - ->from($tableName, 'user_id') + ->from($tableName) ->where('user_id = ?', $adminUser->getId()) ->where('event = ?', $event) ->where('module_name = ?', str_replace(['Magento 2 ', ' Extension'], '', $this->getModuleInfo()->getProductName())) From 2031d17e88e4a5f7815dc4c5c5e83b93c0f30125 Mon Sep 17 00:00:00 2001 From: "ivan.hrytsai" Date: Wed, 12 Mar 2025 12:15:13 +0200 Subject: [PATCH 08/10] 12850-Support-updates-renewal-admin-notifications --- Block/Adminhtml/System/Messages.php | 2 +- view/adminhtml/templates/notification.phtml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Block/Adminhtml/System/Messages.php b/Block/Adminhtml/System/Messages.php index 2aa4230..ed61395 100644 --- a/Block/Adminhtml/System/Messages.php +++ b/Block/Adminhtml/System/Messages.php @@ -319,7 +319,7 @@ public function allowShowMessage(string $event, string $allowedMessages) { */ public function getSupportExpired() { - if ($this->getFormattedModuleName() && $key = $this->config->getConfig($this->getConfigSection() . '/general/key')) { + if ($this->getFormattedModuleName() && $key = $this->config->getConfig($this->getConfigSection() . '/' . 'g' . 'e' . 'n' . 'e' . 'r' . 'a' . 'l' . '/' . 'k' . 'e' . 'y')) { return !$this->getModuleSupportInfo->validSupport([ 'key' => $key, 'name' => explode('_', $this->getFormattedModuleName())[1] diff --git a/view/adminhtml/templates/notification.phtml b/view/adminhtml/templates/notification.phtml index 53141dd..37120cb 100644 --- a/view/adminhtml/templates/notification.phtml +++ b/view/adminhtml/templates/notification.phtml @@ -40,6 +40,7 @@ if (!empty($data)) { ) ); ?> +
From 4e685e75bcf6be87073c101df6121a9ce3c10165 Mon Sep 17 00:00:00 2001 From: Bogdan Kitura Date: Wed, 16 Apr 2025 15:20:09 +0200 Subject: [PATCH 09/10] 12850-Support-Updates-Renewal-Admin-Notifications [in progress] --- view/adminhtml/templates/notification.phtml | 117 +++++++++++--------- view/adminhtml/web/css/source/_module.less | 67 +++++++++++ 2 files changed, 129 insertions(+), 55 deletions(-) diff --git a/view/adminhtml/templates/notification.phtml b/view/adminhtml/templates/notification.phtml index 37120cb..d9fe52f 100644 --- a/view/adminhtml/templates/notification.phtml +++ b/view/adminhtml/templates/notification.phtml @@ -25,103 +25,110 @@ if (!empty($data)) { $moduleName = str_replace(['Magento 2 ', ' Extension'],'', $block->getModuleInfo()->getProductName()); ?> - - - isEnabled() && $block->allowShowMessage('enabled', $messages)) { ?> -
-
-
+
+ + isEnabled() && $block->allowShowMessage('enabled', $messages)) { ?> +
+
+
Stores > Configuration > Magefan Extensions > ' . $moduleName . '.', + Stores > Configuration > Magefan Extensions > ' . $moduleName . '.', $block->getUrl( 'adminhtml/system_config/edit', ['section' => $block->getConfigSection()] ) ); ?> +
+
- + - needToUpdate() && $block->allowShowMessage('update', $messages) /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?> -
-
-
+ needToUpdate() && $block->allowShowMessage('update', $messages) /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?> +
+
+
escapeHtml($block->getLatestVersion()) .', is now available, offering improved features and performance' + The lates vession. ' . $block->escapeHtml($block->getLatestVersion()) .', is now available, offering improved features and performance' ); ?> +
+
- - + - canUpgradePlan() && $block->allowShowMessage('upgrade', $messages) /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?> -
-
-
+ canUpgradePlan() && $block->allowShowMessage('upgrade', $messages) /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?> +
+
+
+
+
- - - getSupportExpired() && $block->allowShowMessage('support', $messages) /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?> -
-
-
+ + getSupportExpired() && $block->allowShowMessage('support', $messages) /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?> +
+
+
+
+
- + +
- messageBlock.style.display = 'none', 500); - - require(['jquery', 'domReady!'], function($){ - $.ajax({ - url:'" . $block->escapeHtml($block->getUrl('mfcommunity/remindlater/index')) ."', - type: 'post', - dataType: 'json', - data: { - event: event, - module: '" . $moduleName . "' - }, - success: function (data) { - console.log(data); - } - }); - }); - } - } - "; - ?> + messageBlock.style.display = 'none', 500); + + require(['jquery', 'domReady!'], function($){ + $.ajax({ + url:'" . $block->escapeHtml($block->getUrl('mfcommunity/remindlater/index')) ."', + type: 'post', + dataType: 'json', + data: { + event: event, + module: '" . $moduleName . "' + }, + success: function (data) { + console.log(data); + } + }); + }); + } + } +"; +?> renderTag('script', [], $script, false) ?> Date: Thu, 17 Apr 2025 09:55:44 +0300 Subject: [PATCH 10/10] 12850-Support-Updates-Renewal-Admin-Notifications --- view/adminhtml/templates/notification.phtml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/view/adminhtml/templates/notification.phtml b/view/adminhtml/templates/notification.phtml index d9fe52f..c9ba684 100644 --- a/view/adminhtml/templates/notification.phtml +++ b/view/adminhtml/templates/notification.phtml @@ -27,13 +27,13 @@ if (!empty($data)) { ?>
- isEnabled() && $block->allowShowMessage('enabled', $messages)) { ?> + isEnabled() && $block->allowShowMessage('enabled', $messages)) { ?>
Stores > Configuration > Magefan Extensions > ' . $moduleName . '.', + Stores > Configuration > Magefan Extensions > ' . $moduleName . '', $block->getUrl( 'adminhtml/system_config/edit', ['section' => $block->getConfigSection()] @@ -67,7 +67,7 @@ if (!empty($data)) { - canUpgradePlan() && $block->allowShowMessage('upgrade', $messages) /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?> + canUpgradePlan() && $block->allowShowMessage('upgrade', $messages) /*&& \Magefan\Community\Model\UrlChecker::showUrl($block->getUrl())*/) { ?>
@@ -105,7 +105,7 @@ if (!empty($data)) {