Skip to content

Commit

Permalink
Merge pull request #542 from magento-performance/as-store-url
Browse files Browse the repository at this point in the history
Store Url fixes
  • Loading branch information
andimov authored Jun 5, 2023
2 parents 4d6f13b + 77f7559 commit 7ff5cb7
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 30 deletions.
18 changes: 16 additions & 2 deletions app/code/Magento/Store/Model/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,7 +44,8 @@ class Store extends AbstractExtensibleModel implements
AppScopeInterface,
UrlScopeInterface,
IdentityInterface,
StoreInterface
StoreInterface,
ResetAfterRequestInterface
{
/**
* Store Id key name
Expand Down Expand Up @@ -466,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 Expand Up @@ -1421,4 +1422,17 @@ public function __debugInfo()
{
return [];
}

/**
* @inheritDoc
*/
public function _resetState(): void
{
$this->_baseUrlCache = [];
$this->_configCache = null;
$this->_configCacheBaseNodes = [];
$this->_dirCache = [];
$this->_urlCache = [];
$this->_baseUrlCache = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
= <<<QUERY
Expand Down Expand Up @@ -101,21 +90,37 @@ public function testDefaultWebsiteAvailableStoreConfigs(): void
}
}
QUERY;
$response = $this->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
= <<<QUERY
Expand Down Expand Up @@ -151,11 +156,10 @@ public function testNonDefaultWebsiteAvailableStoreConfigs(): void
}
}
QUERY;
$headerMap = ['Store' => '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]);
}
}
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
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
1 change: 1 addition & 0 deletions lib/internal/Magento/Framework/App/Request/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,5 +458,6 @@ public function _resetState(): void
$this->headers = null;
$this->metadata = [];
$this->content = '';
$this->distroBaseUrl = null;
}
}
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 7ff5cb7

Please sign in to comment.