Skip to content

Commit e947753

Browse files
authored
Merge pull request #4574 from magento-obsessive-owls/MC-17700-squashed
[owls] MC-17700: Add more hosts from more scopes
2 parents 639e3ce + d08f7e3 commit e947753

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

app/code/Magento/Downloadable/Setup/Patch/Data/AddDownloadableHostsConfig.php

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88
namespace Magento\Downloadable\Setup\Patch\Data;
99

10+
use Magento\Config\Model\Config\Backend\Admin\Custom;
1011
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\Exception\NoSuchEntityException;
1113
use Magento\Framework\Setup\Patch\DataPatchInterface;
14+
use Magento\Framework\UrlInterface;
1215
use Magento\Store\Model\ScopeInterface;
16+
use Magento\Store\Model\Store;
1317
use Zend\Uri\Uri as UriHandler;
1418
use Magento\Framework\Url\ScopeResolverInterface;
1519
use Magento\Downloadable\Api\DomainManagerInterface as DomainManager;
@@ -79,8 +83,12 @@ public function __construct(
7983
*/
8084
public function apply()
8185
{
82-
foreach ($this->scopeResolver->getScopes() as $scope) {
83-
$this->addHost($scope->getBaseUrl());
86+
$customStoreScope = $this->scopeResolver->getScope(Custom::CONFIG_SCOPE_ID);
87+
$storeScopes = $this->scopeResolver->getScopes();
88+
$allStoreScopes = array_merge($storeScopes, [$customStoreScope]);
89+
90+
foreach ($allStoreScopes as $scope) {
91+
$this->addStoreAndWebsiteUrlsFromScope($scope);
8492
}
8593

8694
$customAdminUrl = $this->scopeConfig->getValue(
@@ -135,13 +143,56 @@ public function apply()
135143
$this->domainManager->addDomains($this->whitelist);
136144
}
137145

146+
/**
147+
* Add stores and website urls from store scope
148+
*
149+
* @param Store $scope
150+
*/
151+
private function addStoreAndWebsiteUrlsFromScope(Store $scope)
152+
{
153+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_WEB, false));
154+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_WEB, true));
155+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_LINK, false));
156+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_LINK, true));
157+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_DIRECT_LINK, false));
158+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_DIRECT_LINK, true));
159+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_MEDIA, false));
160+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_MEDIA, true));
161+
162+
try {
163+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_STATIC, false));
164+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_STATIC, true));
165+
} catch (\UnexpectedValueException $e) {} //@codingStandardsIgnoreLine
166+
167+
try {
168+
$website = $scope->getWebsite();
169+
} catch (NoSuchEntityException $e) {
170+
return;
171+
}
172+
173+
if ($website) {
174+
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_URL));
175+
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_URL));
176+
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_LINK_URL));
177+
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_LINK_URL));
178+
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_MEDIA_URL));
179+
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_MEDIA_URL));
180+
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_STATIC_URL));
181+
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_STATIC_URL));
182+
}
183+
}
184+
138185
/**
139186
* Add host to whitelist
140187
*
141188
* @param string $url
142189
*/
143190
private function addHost($url)
144191
{
192+
if (!is_string($url)) {
193+
return;
194+
}
195+
145196
$host = $this->uriHandler->parse($url)->getHost();
146197
if ($host && !in_array($host, $this->whitelist)) {
147198
$this->whitelist[] = $host;

0 commit comments

Comments
 (0)