Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Magento 2.2.8 scope configuration bug in future 2.3.x releases #1367

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Romain Ruaud <[email protected]>
* @copyright 2018 Smile
* @license Open Software License ("OSL") v. 3.0
*/

namespace Smile\ElasticsuiteCore\Search\Request\RelevanceConfig\App\Config;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ScopeResolverPool;

/**
* Elasticsuite Relevance Configuration Scope Code Resolver.
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Romain Ruaud <[email protected]>
*/
class ScopeCodeResolver
{
/**
* @var ScopeResolverPool
*/
private $scopeResolverPool;

/**
* @var array
*/
private $resolvedScopeCodes = [];

/**
* @param ScopeResolverPool $scopeResolverPool Scope Resolver Pool
*/
public function __construct(ScopeResolverPool $scopeResolverPool)
{
$this->scopeResolverPool = $scopeResolverPool;
}

/**
* Resolve scope code
*
* @param string $scopeType Scope Type
* @param string|null $scopeCode Scope code
*
* @return string
*/
public function resolve($scopeType, $scopeCode)
{
if (isset($this->resolvedScopeCodes[$scopeType][$scopeCode])) {
return $this->resolvedScopeCodes[$scopeType][$scopeCode];
}

$resolverScopeCode = $scopeCode;

if (($scopeCode === null || is_numeric($scopeCode))
&& $scopeType !== ScopeConfigInterface::SCOPE_TYPE_DEFAULT
) {
$scopeResolver = $this->scopeResolverPool->get($scopeType);
$resolverScopeCode = $scopeResolver->getScope($scopeCode);
}

if ($resolverScopeCode instanceof \Magento\Framework\App\ScopeInterface) {
$resolverScopeCode = $resolverScopeCode->getCode();
}

$this->resolvedScopeCodes[$scopeType][$scopeCode] = $resolverScopeCode;

return $resolverScopeCode;
}

/**
* Clean resolvedScopeCodes, store codes may have been renamed
*
* @return void
*/
public function clean()
{
$this->resolvedScopeCodes = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
namespace Smile\ElasticsuiteCore\Search\Request\RelevanceConfig\App\Config;

use Magento\Framework\App\Config\ScopeCodeResolver;
use Magento\Framework\App\Config\ScopeConfigInterface;

/**
Expand Down Expand Up @@ -60,14 +59,14 @@ class ScopePool
* @param \Smile\ElasticsuiteCore\Model\Search\Request\RelevanceConfig\ReaderPool $readerPool Reader Pool
* @param \Magento\Framework\App\Config\DataFactory $dataFactory Config Data Factory
* @param \Magento\Framework\App\CacheInterface $cache Cache Interface
* @param \Magento\Framework\App\Config\ScopeCodeResolver $scopeCodeResolver Scope Code Resolver
* @param ScopeCodeResolver $scopeCodeResolver Scope Code Resolver
* @param string $cacheId Cache Id
*/
public function __construct(
\Smile\ElasticsuiteCore\Model\Search\Request\RelevanceConfig\ReaderPool $readerPool,
\Magento\Framework\App\Config\DataFactory $dataFactory,
\Magento\Framework\App\CacheInterface $cache,
\Magento\Framework\App\Config\ScopeCodeResolver $scopeCodeResolver,
ScopeCodeResolver $scopeCodeResolver,
$cacheId = 'default_config_cache'
) {
$this->readerPool = $readerPool;
Expand Down