Skip to content

Commit d7693bb

Browse files
committed
MC-17701: Downloadable Product links
1 parent c4bc58e commit d7693bb

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

app/code/Magento/Downloadable/Setup/UpgradeData.php

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Downloadable\Setup;
88

9+
use Magento\Framework\Exception\NoSuchEntityException;
910
use Magento\Store\Model\Store;
1011
use Zend\Uri\Uri as UriHandler;
1112
use Magento\Downloadable\Api\DomainManagerInterface as DomainManager;
@@ -109,7 +110,6 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
109110
*
110111
* @param ModuleDataSetupInterface $setup
111112
* @return void
112-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
113113
*/
114114
private function addDownloadableHostsToConfig(ModuleDataSetupInterface $setup)
115115
{
@@ -118,28 +118,7 @@ private function addDownloadableHostsToConfig(ModuleDataSetupInterface $setup)
118118
$allStoreScopes = array_merge($storeScopes, [$customStoreScope]);
119119

120120
foreach ($allStoreScopes as $scope) {
121-
/** @var $scope Store */
122-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_WEB, false));
123-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_WEB, true));
124-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_LINK, false));
125-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_LINK, true));
126-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_DIRECT_LINK, false));
127-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_DIRECT_LINK, true));
128-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_MEDIA, false));
129-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_MEDIA, true));
130-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_STATIC, false));
131-
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_STATIC, true));
132-
133-
if ($website = $scope->getWebsite()) {
134-
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_URL));
135-
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_URL));
136-
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_LINK_URL));
137-
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_LINK_URL));
138-
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_MEDIA_URL));
139-
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_MEDIA_URL));
140-
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_STATIC_URL));
141-
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_STATIC_URL));
142-
}
121+
$this->addStoreAndWebsiteUrlsFromScope($scope);
143122
}
144123

145124
$customAdminUrl = $this->scopeConfig->getValue(
@@ -198,6 +177,42 @@ private function addDownloadableHostsToConfig(ModuleDataSetupInterface $setup)
198177
$this->domainManager->addDomains($this->whitelist);
199178
}
200179

180+
/**
181+
* Add stores and website urls from store scope
182+
*
183+
* @param Store $scope
184+
*/
185+
private function addStoreAndWebsiteUrlsFromScope(Store $scope)
186+
{
187+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_WEB, false));
188+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_WEB, true));
189+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_LINK, false));
190+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_LINK, true));
191+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_DIRECT_LINK, false));
192+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_DIRECT_LINK, true));
193+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_MEDIA, false));
194+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_MEDIA, true));
195+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_STATIC, false));
196+
$this->addHost($scope->getBaseUrl(UrlInterface::URL_TYPE_STATIC, true));
197+
198+
try {
199+
$website = $scope->getWebsite();
200+
} catch (NoSuchEntityException $e) {
201+
return;
202+
}
203+
204+
if ($website) {
205+
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_URL));
206+
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_URL));
207+
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_LINK_URL));
208+
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_LINK_URL));
209+
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_MEDIA_URL));
210+
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_MEDIA_URL));
211+
$this->addHost($website->getConfig(Store::XML_PATH_SECURE_BASE_STATIC_URL));
212+
$this->addHost($website->getConfig(Store::XML_PATH_UNSECURE_BASE_STATIC_URL));
213+
}
214+
}
215+
201216
/**
202217
* Add host to whitelist
203218
*

0 commit comments

Comments
 (0)