Skip to content

Commit 5da1e2b

Browse files
authored
Merge pull request #52 from exponea/release/1.1.3
Release: v1.1.3
2 parents 6e0978c + cf9384f commit 5da1e2b

8 files changed

Lines changed: 84 additions & 4 deletions

File tree

Model/System/Message/ErrorsMessageNotification.php

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
use Bloomreach\EngagementConnector\Model\ExportQueueModel;
1111
use Bloomreach\EngagementConnector\Model\ResourceModel\ExportQueue\CollectionFactory;
12+
use Bloomreach\EngagementConnector\System\ConfigProvider;
13+
use Magento\Framework\App\CacheInterface;
1214
use Magento\Framework\Notification\MessageInterface;
1315
use Magento\Framework\Phrase;
1416

@@ -21,19 +23,38 @@ class ErrorsMessageNotification implements MessageInterface
2123
* Message identity
2224
*/
2325
private const MESSAGE_IDENTITY = 'bloomreach_errors_system_notification';
26+
private const HAS_ERRORS_CACHE_VALUE = 'has_errors';
27+
private const NO_ERRORS_CACHE_VALUE = 'no_errors';
28+
private const CACHE_LIFETIME = 600;
2429

2530
/**
2631
* @var CollectionFactory
2732
*/
2833
private $exportQueueCollectionFactory;
2934

35+
/**
36+
* @var ConfigProvider
37+
*/
38+
private $configProvider;
39+
40+
/**
41+
* @var CacheInterface
42+
*/
43+
private $cacheManagement;
44+
3045
/**
3146
* @param CollectionFactory $exportQueueCollectionFactory
47+
* @param ConfigProvider $configProvider
48+
* @param CacheInterface $cacheManagement
3249
*/
3350
public function __construct(
34-
CollectionFactory $exportQueueCollectionFactory
51+
CollectionFactory $exportQueueCollectionFactory,
52+
ConfigProvider $configProvider,
53+
CacheInterface $cacheManagement
3554
) {
55+
$this->configProvider = $configProvider;
3656
$this->exportQueueCollectionFactory = $exportQueueCollectionFactory;
57+
$this->cacheManagement = $cacheManagement;
3758
}
3859

3960
/**
@@ -53,7 +74,9 @@ public function getIdentity(): string
5374
*/
5475
public function isDisplayed(): bool
5576
{
56-
return $this->isNeedToShow();
77+
return $this->configProvider->isEnabled()
78+
&& $this->configProvider->isSystemNotificationEnabled()
79+
&& $this->isNeedToShow();
5780
}
5881

5982
/**
@@ -84,10 +107,35 @@ public function getSeverity(): int
84107

85108
/**
86109
* Show the error message if need it
110+
* - save data to cache
87111
*
88112
* @return bool
89113
*/
90114
private function isNeedToShow(): bool
115+
{
116+
$result = $this->cacheManagement->load($this->getIdentity());
117+
118+
if (is_string($result) && $result) {
119+
return $result === self::HAS_ERRORS_CACHE_VALUE;
120+
}
121+
122+
$hasErrors = $this->hasRecentErrorRecords();
123+
$this->cacheManagement->save(
124+
$hasErrors ? self::HAS_ERRORS_CACHE_VALUE : self::NO_ERRORS_CACHE_VALUE,
125+
$this->getIdentity(),
126+
['BLOCK_HTML'],
127+
self::CACHE_LIFETIME
128+
);
129+
130+
return $hasErrors;
131+
}
132+
133+
/**
134+
* Has recent error records
135+
*
136+
* @return bool
137+
*/
138+
private function hasRecentErrorRecords(): bool
91139
{
92140
$periodOfTime = date('Y-m-d H:i:s', strtotime('-24 hours'));
93141
return (bool) $this->exportQueueCollectionFactory->create()

RELEASELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# v1.1.3
2+
3+
- Fixes
4+
- Resolved an issue where system notifications were still displayed when the extension was disabled
5+
- Additions
6+
- Added a new setting to enable or disable system notifications. This setting is enabled by default
7+
- Improvements
8+
- Optimized system notification logic by implementing a 10-minute caching mechanism to reduce redundant executions when admin panel pages are loaded
9+
-
110
# v1.1.2
211

312
- Changes

System/ConfigProvider.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ class ConfigProvider
223223
*/
224224
public const XPATH_USE_STATIC_IPS = 'bloomreach_engagement/general/use_static_ips';
225225

226+
/**
227+
* System notification enabled
228+
*/
229+
public const XPATH_SYSTEM_NOTIFICATIONS_ENABLED = 'bloomreach_engagement/general/system_notifications_enabled';
230+
226231
/**
227232
* Feed enabled config type
228233
*/
@@ -810,4 +815,14 @@ public function isUseStaticIps(
810815
): bool {
811816
return $this->scopeConfig->isSetFlag(self::XPATH_USE_STATIC_IPS, $scopeType, $scopeCode);
812817
}
818+
819+
/**
820+
* Get system notifications enabled config
821+
*
822+
* @return bool
823+
*/
824+
public function isSystemNotificationEnabled(): bool
825+
{
826+
return $this->scopeConfig->isSetFlag(self::XPATH_SYSTEM_NOTIFICATIONS_ENABLED);
827+
}
813828
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bloomreach/bloomreach-engagement-connector-magento",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"description": "The module provides the Bloomreach integration with Magento 2.",
55
"type": "magento2-module",
66
"authors": [

doc/user_guide.pdf

283 Bytes
Binary file not shown.

etc/adminhtml/system.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@
109109
</depends>
110110
<validate>required-entry validate-zero-or-greater validate-digits</validate>
111111
</field>
112+
<field id="system_notifications_enabled" translate="label" type="select" sortOrder="120" showInDefault="1">
113+
<label>Enable System Notifications</label>
114+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
115+
<depends>
116+
<field id="enable">1</field>
117+
</depends>
118+
</field>
112119
</group>
113120
<group id="http_basic_auth" translate="label" type="text" sortOrder="20" showInDefault="1">
114121
<label>HTTP Basic Authentication</label>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<request_timeout>60</request_timeout>
1717
<retry_base_wait_time>60</retry_base_wait_time>
1818
<retry_max_wait_time>240</retry_max_wait_time>
19+
<system_notifications_enabled>1</system_notifications_enabled>
1920
</general>
2021
<http_basic_auth>
2122
<enabled>0</enabled>

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
10-
<module name="Bloomreach_EngagementConnector" setup_version="1.1.2"/>
10+
<module name="Bloomreach_EngagementConnector" setup_version="1.1.3"/>
1111
</config>

0 commit comments

Comments
 (0)