Skip to content

Commit

Permalink
Proper generate classes with reset state method
Browse files Browse the repository at this point in the history
  • Loading branch information
kandy committed Jun 2, 2023
1 parent f778962 commit 77f7559
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
1 change: 0 additions & 1 deletion app/code/Magento/Store/Model/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ protected function _construct()
protected function _getSession()
{
if (!$this->_session->isSessionExists()) {
$this->_session->setName('store_' . $this->getCode());
$this->_session->start();
}
return $this->_session;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function ($errNo, $errStr, $errFile, $errLine) use ($test) {
$this->_eventManager->fireEvent('startTransaction', [$test]);
restore_error_handler();
} catch (\Exception $e) {
$this->_isTransactionActive = false;
$test->getTestResultObject()->addFailure(
$test,
new \PHPUnit\Framework\AssertionFailedError((string)$e),
Expand All @@ -125,8 +126,8 @@ function ($errNo, $errStr, $errFile, $errLine) use ($test) {
protected function _rollbackTransaction()
{
if ($this->_isTransactionActive) {
$this->_getConnection()->rollbackTransparentTransaction();
$this->_isTransactionActive = false;
$this->_getConnection()->rollbackTransparentTransaction();
$this->_eventManager->fireEvent('rollbackTransaction');
$this->_getConnection()->closeConnection();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function _getClassMethods()
protected function isInterceptedMethod(\ReflectionMethod $method)
{
return !($method->isConstructor() || $method->isFinal() || $method->isStatic() || $method->isDestructor()) &&
!in_array($method->getName(), ['__sleep', '__wakeup', '__clone']);
!in_array($method->getName(), ['__sleep', '__wakeup', '__clone', '_resetState']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,21 @@ protected function _getClassMethods()
)
&& !in_array(
$method->getName(),
['__sleep', '__wakeup', '__clone', '__debugInfo']
['__sleep', '__wakeup', '__clone', '__debugInfo', '_resetState']
)
) {
$methods[] = $this->_getMethodInfo($method);
}
if ($method->getName() === '_resetState') {
$methods[] = [
'name' => '_resetState',
'returnType' => 'void',
'body' => "if (\$this->_subject) {\n" .
" \$this->_subject->_resetState(); \n" .
"}\n",
'docblock' => ['shortDescription' => 'Reset state of proxied instance'],
];
}
}

return $methods;
Expand Down
8 changes: 7 additions & 1 deletion lib/internal/Magento/Framework/Session/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,13 @@ private function initIniOptions()
*/
public function _resetState(): void
{
session_write_close();
if (session_status() === PHP_SESSION_ACTIVE) {
session_write_close();
session_id('');
}
session_name('PHPSESSID');
session_unset();
static::$urlHostCache = [];
$_SESSION = [];
}
}

0 comments on commit 77f7559

Please sign in to comment.