Skip to content

Commit 08466c5

Browse files
committed
Fix regression left over from rebase
1 parent ee8da15 commit 08466c5

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

app/code/Magento/Customer/Model/Visitor.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ public function initByRequest($observer)
158158

159159
$this->setLastVisitAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT));
160160

161+
// prevent saving Visitor for safe methods, e.g. GET request
162+
if ($this->getRequest()->isSafeMethod()) {
163+
return $this;
164+
}
161165
if (!$this->getId()) {
162166
$this->setSessionId($this->session->getSessionId());
163167
$this->save();
@@ -177,7 +181,8 @@ public function initByRequest($observer)
177181
*/
178182
public function saveByRequest($observer)
179183
{
180-
if ($this->skipRequestLogging || $this->isModuleIgnored($observer)) {
184+
// prevent saving Visitor for safe methods, e.g. GET request
185+
if ($this->skipRequestLogging || $this->getRequest()->isSafeMethod() || $this->isModuleIgnored($observer)) {
181186
return $this;
182187
}
183188

@@ -321,15 +326,15 @@ public function getOnlineInterval()
321326
* If the request wasn't injected because of the backward compatible optional constructor dependency,
322327
* create a new request instance.
323328
*
324-
* @return \Magento\Framework\App\RequestInterface|\Magento\Framework\App\Request\Http
329+
* @return \Magento\Framework\App\RequestSafetyInterface|\Magento\Framework\App\Request\Http
325330
*/
326331
private function getRequest()
327332
{
328-
if (null === $this->request) {
329-
$this->request = \Magento\Framework\App\ObjectManager::getInstance()->create(
333+
if (null === $this->requestSafety) {
334+
$this->requestSafety = \Magento\Framework\App\ObjectManager::getInstance()->create(
330335
\Magento\Framework\App\RequestInterface::class
331336
);
332337
}
333-
return $this->request;
338+
return $this->requestSafety;
334339
}
335340
}

app/code/Magento/Customer/Test/Unit/Model/VisitorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function testIsModuleIgnored()
108108
'session' => $this->session,
109109
'resource' => $this->resource,
110110
'ignores' => ['test_route_name' => true],
111-
'request' => $this->request,
111+
'requestSafety' => $this->request,
112112
]
113113
);
114114
$this->request->method('getRouteName')->willReturn('test_route_name');

0 commit comments

Comments
 (0)