11
11
use Magento \Framework \App \Backpressure \ContextInterface ;
12
12
use Magento \Framework \App \Backpressure \SlidingWindow \LimitConfig ;
13
13
use Magento \Framework \App \Backpressure \SlidingWindow \LimitConfigManagerInterface ;
14
+ use Magento \Framework \App \Backpressure \SlidingWindow \RequestLoggerInterface ;
14
15
use Magento \Framework \App \Config \ScopeConfigInterface ;
15
- use Magento \Framework \App \ObjectManager ;
16
+ use Magento \Framework \App \DeploymentConfig ;
17
+ use Magento \Framework \Exception \FileSystemException ;
16
18
use Magento \Framework \Exception \RuntimeException ;
17
19
use Magento \Store \Model \ScopeInterface ;
18
20
@@ -28,12 +30,21 @@ class OrderLimitConfigManager implements LimitConfigManagerInterface
28
30
*/
29
31
private ScopeConfigInterface $ config ;
30
32
33
+ /**
34
+ * @var DeploymentConfig
35
+ */
36
+ private DeploymentConfig $ deploymentConfig ;
37
+
31
38
/**
32
39
* @param ScopeConfigInterface $config
40
+ * @param DeploymentConfig $deploymentConfig
33
41
*/
34
- public function __construct (ScopeConfigInterface $ config )
35
- {
42
+ public function __construct (
43
+ ScopeConfigInterface $ config ,
44
+ DeploymentConfig $ deploymentConfig
45
+ ) {
36
46
$ this ->config = $ config ;
47
+ $ this ->deploymentConfig = $ deploymentConfig ;
37
48
}
38
49
39
50
/**
@@ -62,73 +73,50 @@ public function readLimit(ContextInterface $context): LimitConfig
62
73
* Checks if enforcement enabled for the current store
63
74
*
64
75
* @return bool
76
+ * @throws RuntimeException
77
+ * @throws FileSystemException
65
78
*/
66
79
public function isEnforcementEnabled (): bool
67
80
{
81
+ $ loggerType = $ this ->deploymentConfig ->get (RequestLoggerInterface::CONFIG_PATH_BACKPRESSURE_LOGGER );
68
82
$ enabled = $ this ->config ->isSetFlag ('sales/backpressure/enabled ' , ScopeInterface::SCOPE_STORE );
69
- if (!$ enabled ) {
70
- return false ;
71
- }
72
-
73
- try {
74
- $ this ->fetchPeriod ();
75
- $ this ->fetchAuthenticatedLimit ();
76
- $ this ->fetchGuestLimit ();
77
- } catch (RuntimeException $ ex ) {
78
- return false ;
83
+ if ($ loggerType && $ enabled ) {
84
+ return true ;
79
85
}
80
86
81
- return true ;
87
+ return false ;
82
88
}
83
89
84
90
/**
85
91
* Limit for authenticated customers
86
92
*
87
93
* @return int
88
- * @throws RuntimeException
89
94
*/
90
95
private function fetchAuthenticatedLimit (): int
91
96
{
92
- $ value = (int )$ this ->config ->getValue ('sales/backpressure/limit ' , ScopeInterface::SCOPE_STORE );
93
- if ($ value <= 0 ) {
94
- throw new RuntimeException (__ ("Invalid order backpressure limit config " ));
95
- }
96
-
97
- return $ value ;
97
+ return (int )$ this ->config ->getValue ('sales/backpressure/limit ' , ScopeInterface::SCOPE_STORE );
98
98
}
99
99
100
100
/**
101
101
* Limit for guests
102
102
*
103
103
* @return int
104
- * @throws RuntimeException
105
104
*/
106
105
private function fetchGuestLimit (): int
107
106
{
108
- $ value = (int )$ this ->config ->getValue (
107
+ return (int )$ this ->config ->getValue (
109
108
'sales/backpressure/guest_limit ' ,
110
109
ScopeInterface::SCOPE_STORE
111
110
);
112
- if ($ value <= 0 ) {
113
- throw new RuntimeException (__ ("Invalid order backpressure guest limit config " ));
114
- }
115
-
116
- return $ value ;
117
111
}
118
112
119
113
/**
120
114
* Counter reset period
121
115
*
122
116
* @return int
123
- * @throws RuntimeException
124
117
*/
125
118
private function fetchPeriod (): int
126
119
{
127
- $ value = (int )$ this ->config ->getValue ('sales/backpressure/period ' , ScopeInterface::SCOPE_STORE );
128
- if ($ value <= 0 ) {
129
- throw new RuntimeException (__ ("Invalid order backpressure counter reset period config " ));
130
- }
131
-
132
- return $ value ;
120
+ return (int )$ this ->config ->getValue ('sales/backpressure/period ' , ScopeInterface::SCOPE_STORE );
133
121
}
134
122
}
0 commit comments