@@ -40,8 +40,6 @@ class Visitor extends \Magento\Framework\Model\AbstractModel
40
40
protected $ httpHeader ;
41
41
42
42
/**
43
- * Skip logging during request. Do not use this property directly, but use self::isSkipRequestLogging instead
44
- *
45
43
* @var bool
46
44
*/
47
45
protected $ skipRequestLogging = false ;
@@ -145,19 +143,6 @@ public function setSkipRequestLogging($skipRequestLogging)
145
143
return $ this ;
146
144
}
147
145
148
- /**
149
- * Check if we can log request fot event. Additionally prevent logging for safe methods (e.g. GET request)
150
- *
151
- * @return bool
152
- */
153
- private function isSkipRequestLogging ()
154
- {
155
- if ($ this ->requestSafety ->isSafeMethod ()) {
156
- return true ;
157
- }
158
- return $ this ->skipRequestLogging ;
159
- }
160
-
161
146
/**
162
147
* Initialization visitor by request
163
148
*
@@ -168,7 +153,7 @@ private function isSkipRequestLogging()
168
153
*/
169
154
public function initByRequest ($ observer )
170
155
{
171
- if ($ this ->isSkipRequestLogging () || $ this ->isModuleIgnored ($ observer )) {
156
+ if ($ this ->skipRequestLogging || $ this ->isModuleIgnored ($ observer )) {
172
157
return $ this ;
173
158
}
174
159
@@ -181,6 +166,10 @@ public function initByRequest($observer)
181
166
182
167
$ this ->setLastVisitAt ((new \DateTime ())->format (\Magento \Framework \Stdlib \DateTime::DATETIME_PHP_FORMAT ));
183
168
169
+ // prevent saving Visitor for safe methods, e.g. GET request
170
+ if ($ this ->requestSafety ->isSafeMethod ()) {
171
+ return $ this ;
172
+ }
184
173
if (!$ this ->getId ()) {
185
174
$ this ->setSessionId ($ this ->session ->getSessionId ());
186
175
$ this ->save ();
@@ -200,7 +189,8 @@ public function initByRequest($observer)
200
189
*/
201
190
public function saveByRequest ($ observer )
202
191
{
203
- if ($ this ->isSkipRequestLogging () || $ this ->isModuleIgnored ($ observer )) {
192
+ // prevent saving Visitor for safe methods, e.g. GET request
193
+ if ($ this ->skipRequestLogging || $ this ->requestSafety ->isSafeMethod () || $ this ->isModuleIgnored ($ observer )) {
204
194
return $ this ;
205
195
}
206
196
0 commit comments