Skip to content

Commit 6e8b594

Browse files
committed
MC-17700: Downloadable Product links
1 parent dd170ed commit 6e8b594

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

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

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Config\Model\Config\Backend\Admin\Custom;
1111
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\Exception\NoSuchEntityException;
1213
use Magento\Framework\Setup\Patch\DataPatchInterface;
1314
use Magento\Framework\UrlInterface;
1415
use Magento\Store\Model\ScopeInterface;
@@ -87,17 +88,7 @@ public function apply()
8788
$allStoreScopes = array_merge($storeScopes, [$customStoreScope]);
8889

8990
foreach ($allStoreScopes as $scope) {
90-
/** @var $scope Store */
91-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_WEB, false));
92-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_WEB, true));
93-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_LINK, false));
94-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_LINK, true));
95-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_DIRECT_LINK, false));
96-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_DIRECT_LINK, true));
97-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_MEDIA, false));
98-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_MEDIA, true));
99-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_STATIC, false));
100-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_STATIC, true));
91+
$this->addStoreAndWebsiteUrlsFromScope($scope);
10192
}
10293

10394
$customAdminUrl = $this->scopeConfig->getValue(
@@ -152,13 +143,53 @@ public function apply()
152143
$this->domainManager->addDomains($this->whitelist);
153144
}
154145

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+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_STATIC, false));
162+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_STATIC, true));
163+
164+
try {
165+
$website = $scope->getWebsite();
166+
} catch (NoSuchEntityException $e) {
167+
return;
168+
}
169+
170+
if ($website) {
171+
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_URL));
172+
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_URL));
173+
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_LINK_URL));
174+
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_LINK_URL));
175+
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_MEDIA_URL));
176+
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_MEDIA_URL));
177+
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_STATIC_URL));
178+
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_STATIC_URL));
179+
}
180+
}
181+
155182
/**
156183
* Add host to whitelist
157184
*
158185
* @param string $url
159186
*/
160187
private function addHost($url)
161188
{
189+
if (!is_string($url)) {
190+
return;
191+
}
192+
162193
$host = $this->uriHandler->parse($url)->getHost();
163194
if ($host && !in_array($host, $this->whitelist)) {
164195
$this->whitelist[] = $host;

0 commit comments

Comments
 (0)