From def84114503dd5f4933bb0a5e6d8a9b4aab14481 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Wed, 24 May 2023 00:43:06 -0500 Subject: [PATCH 1/3] Store Url fixes --- app/code/Magento/Store/Model/Store.php | 17 ++++++++++++++++- .../Magento/Framework/App/Request/Http.php | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Store/Model/Store.php b/app/code/Magento/Store/Model/Store.php index 34cbd76d24dc2..6e5f13e971395 100644 --- a/app/code/Magento/Store/Model/Store.php +++ b/app/code/Magento/Store/Model/Store.php @@ -17,6 +17,7 @@ use Magento\Framework\DataObject\IdentityInterface; use Magento\Framework\Filesystem; use Magento\Framework\Model\AbstractExtensibleModel; +use Magento\Framework\ObjectManager\ResetAfterRequestInterface; use Magento\Framework\Url\ModifierInterface; use Magento\Framework\Url\ScopeInterface as UrlScopeInterface; use Magento\Framework\UrlInterface; @@ -43,7 +44,8 @@ class Store extends AbstractExtensibleModel implements AppScopeInterface, UrlScopeInterface, IdentityInterface, - StoreInterface + StoreInterface, + ResetAfterRequestInterface { /** * Store Id key name @@ -1421,4 +1423,17 @@ public function __debugInfo() { return []; } + + /** + * @inheritDoc + */ + public function _resetState(): void + { + $this->_baseUrlCache = []; + $this->_configCache = null; + $this->_configCacheBaseNodes = []; + $this->_dirCache = []; + $this->_urlCache = []; + $this->_baseUrlCache = []; + } } diff --git a/lib/internal/Magento/Framework/App/Request/Http.php b/lib/internal/Magento/Framework/App/Request/Http.php index 4ecc40f0e3ceb..2535b499f8a6f 100644 --- a/lib/internal/Magento/Framework/App/Request/Http.php +++ b/lib/internal/Magento/Framework/App/Request/Http.php @@ -458,5 +458,6 @@ public function _resetState(): void $this->headers = null; $this->metadata = []; $this->content = ''; + $this->distroBaseUrl = null; } } From d3eec3e46e91784ec57ce54e6460c16f77d316d4 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Tue, 30 May 2023 18:16:22 -0500 Subject: [PATCH 2/3] Store Url fixes --- .../GraphQl/Store/AvailableStoresTest.php | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/AvailableStoresTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/AvailableStoresTest.php index b722762cf8a06..b2aa977bbb59f 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/AvailableStoresTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Store/AvailableStoresTest.php @@ -48,24 +48,13 @@ protected function setUp(): void /** * @magentoConfigFixture default_store web/seo/use_rewrites 1 - * @magentoApiDataFixture Magento/Store/_files/store.php - * @magentoApiDataFixture Magento/Store/_files/inactive_store.php + * @magentoConfigFixture default_store web/unsecure/base_url http://example.com/ + * @magentoConfigFixture default_store web/unsecure/base_link_url http://example.com/ + * @magentoApiDataFixture Magento/Store/_files/second_website_with_two_stores.php */ - public function testDefaultWebsiteAvailableStoreConfigs(): void + public function testNonDefaultWebsiteAvailableStoreConfigs(): void { - $storeConfigs = $this->storeConfigManager->getStoreConfigs(); - - $expectedAvailableStores = []; - $expectedAvailableStoreCodes = [ - 'default', - 'test' - ]; - - foreach ($storeConfigs as $storeConfig) { - if (in_array($storeConfig->getCode(), $expectedAvailableStoreCodes)) { - $expectedAvailableStores[] = $storeConfig; - } - } + $storeConfigs = $this->storeConfigManager->getStoreConfigs(['fixture_second_store', 'fixture_third_store']); $query = <<graphQlQuery($query); + $headerMap = ['Store' => 'fixture_second_store']; + $response = $this->graphQlQuery($query, [], '', $headerMap); $this->assertArrayHasKey('availableStores', $response); - foreach ($expectedAvailableStores as $key => $storeConfig) { + foreach ($storeConfigs as $key => $storeConfig) { $this->validateStoreConfig($storeConfig, $response['availableStores'][$key]); } } /** * @magentoConfigFixture default_store web/seo/use_rewrites 1 - * @magentoApiDataFixture Magento/Store/_files/second_website_with_two_stores.php + * @magentoConfigFixture default_store web/unsecure/base_url http://example.com/ + * @magentoConfigFixture default_store web/unsecure/base_link_url http://example.com/ + * @magentoApiDataFixture Magento/Store/_files/store.php + * @magentoApiDataFixture Magento/Store/_files/inactive_store.php */ - public function testNonDefaultWebsiteAvailableStoreConfigs(): void + public function testDefaultWebsiteAvailableStoreConfigs(): void { - $storeConfigs = $this->storeConfigManager->getStoreConfigs(['fixture_second_store', 'fixture_third_store']); + $storeConfigs = $this->storeConfigManager->getStoreConfigs(); + + $expectedAvailableStores = []; + $expectedAvailableStoreCodes = [ + 'default', + 'test' + ]; + + foreach ($storeConfigs as $storeConfig) { + if (in_array($storeConfig->getCode(), $expectedAvailableStoreCodes)) { + $expectedAvailableStores[] = $storeConfig; + } + } $query = << 'fixture_second_store']; - $response = $this->graphQlQuery($query, [], '', $headerMap); + $response = $this->graphQlQuery($query); $this->assertArrayHasKey('availableStores', $response); - foreach ($storeConfigs as $key => $storeConfig) { + foreach ($expectedAvailableStores as $key => $storeConfig) { $this->validateStoreConfig($storeConfig, $response['availableStores'][$key]); } } @@ -209,6 +213,8 @@ private function validateStoreConfig(StoreConfigInterface $storeConfig, array $r /** * @magentoConfigFixture default_store web/seo/use_rewrites 1 + * @magentoConfigFixture default_store web/unsecure/base_url http://example.com/ + * @magentoConfigFixture default_store web/unsecure/base_link_url http://example.com/ * @magentoApiDataFixture Magento/Store/_files/second_website_with_four_stores_divided_in_groups.php * @magentoConfigFixture web/url/use_store 1 */ @@ -270,6 +276,8 @@ public function testAllStoreConfigsWithCodeInUrlEnabled(): void /** * @magentoConfigFixture default_store web/seo/use_rewrites 1 + * @magentoConfigFixture default_store web/unsecure/base_url http://example.com/ + * @magentoConfigFixture default_store web/unsecure/base_link_url http://example.com/ * @magentoApiDataFixture Magento/Store/_files/second_website_with_four_stores_divided_in_groups.php */ public function testCurrentGroupStoreConfigs(): void From 77f75591752cd27e6fa7f08c30a008b81c42e728 Mon Sep 17 00:00:00 2001 From: Andrii Kasian Date: Fri, 2 Jun 2023 10:25:39 -0500 Subject: [PATCH 3/3] Proper generate classes with reset state method --- app/code/Magento/Store/Model/Store.php | 1 - .../Magento/TestFramework/Event/Transaction.php | 3 ++- .../Interception/Code/Generator/Interceptor.php | 2 +- .../Framework/ObjectManager/Code/Generator/Proxy.php | 12 +++++++++++- .../Magento/Framework/Session/SessionManager.php | 8 +++++++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Store/Model/Store.php b/app/code/Magento/Store/Model/Store.php index 6e5f13e971395..2c1ad47693870 100644 --- a/app/code/Magento/Store/Model/Store.php +++ b/app/code/Magento/Store/Model/Store.php @@ -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; diff --git a/dev/tests/integration/framework/Magento/TestFramework/Event/Transaction.php b/dev/tests/integration/framework/Magento/TestFramework/Event/Transaction.php index 2add2ed48fb98..edc6f6d9159c5 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Event/Transaction.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Event/Transaction.php @@ -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), @@ -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(); } diff --git a/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php b/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php index f04bea1030ade..1d0417ad23aca 100644 --- a/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php +++ b/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php @@ -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']); } /** diff --git a/lib/internal/Magento/Framework/ObjectManager/Code/Generator/Proxy.php b/lib/internal/Magento/Framework/ObjectManager/Code/Generator/Proxy.php index 2ed3859de4012..8bb78ba303e94 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Code/Generator/Proxy.php +++ b/lib/internal/Magento/Framework/ObjectManager/Code/Generator/Proxy.php @@ -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; diff --git a/lib/internal/Magento/Framework/Session/SessionManager.php b/lib/internal/Magento/Framework/Session/SessionManager.php index 5a6eea4cbef2c..f79f0900c2c28 100644 --- a/lib/internal/Magento/Framework/Session/SessionManager.php +++ b/lib/internal/Magento/Framework/Session/SessionManager.php @@ -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 = []; } }