|
7 | 7 |
|
8 | 8 | namespace Magento\Downloadable\Setup\Patch\Data;
|
9 | 9 |
|
| 10 | +use Magento\Config\Model\Config\Backend\Admin\Custom; |
10 | 11 | use Magento\Framework\App\Config\ScopeConfigInterface;
|
| 12 | +use Magento\Framework\Exception\NoSuchEntityException; |
11 | 13 | use Magento\Framework\Setup\Patch\DataPatchInterface;
|
| 14 | +use Magento\Framework\UrlInterface; |
12 | 15 | use Magento\Store\Model\ScopeInterface;
|
| 16 | +use Magento\Store\Model\Store; |
13 | 17 | use Zend\Uri\Uri as UriHandler;
|
14 | 18 | use Magento\Framework\Url\ScopeResolverInterface;
|
15 | 19 | use Magento\Downloadable\Api\DomainManagerInterface as DomainManager;
|
@@ -79,8 +83,12 @@ public function __construct(
|
79 | 83 | */
|
80 | 84 | public function apply()
|
81 | 85 | {
|
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); |
84 | 92 | }
|
85 | 93 |
|
86 | 94 | $customAdminUrl = $this->scopeConfig->getValue(
|
@@ -135,13 +143,56 @@ public function apply()
|
135 | 143 | $this->domainManager->addDomains($this->whitelist);
|
136 | 144 | }
|
137 | 145 |
|
| 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 | + |
138 | 185 | /**
|
139 | 186 | * Add host to whitelist
|
140 | 187 | *
|
141 | 188 | * @param string $url
|
142 | 189 | */
|
143 | 190 | private function addHost($url)
|
144 | 191 | {
|
| 192 | + if (!is_string($url)) { |
| 193 | + return; |
| 194 | + } |
| 195 | + |
145 | 196 | $host = $this->uriHandler->parse($url)->getHost();
|
146 | 197 | if ($host && !in_array($host, $this->whitelist)) {
|
147 | 198 | $this->whitelist[] = $host;
|
|
0 commit comments