|
9 | 9 |
|
10 | 10 | use Magento\Config\Model\Config\Backend\Admin\Custom;
|
11 | 11 | use Magento\Framework\App\Config\ScopeConfigInterface;
|
| 12 | +use Magento\Framework\Exception\NoSuchEntityException; |
12 | 13 | use Magento\Framework\Setup\Patch\DataPatchInterface;
|
13 | 14 | use Magento\Framework\UrlInterface;
|
14 | 15 | use Magento\Store\Model\ScopeInterface;
|
@@ -87,17 +88,7 @@ public function apply()
|
87 | 88 | $allStoreScopes = array_merge($storeScopes, [$customStoreScope]);
|
88 | 89 |
|
89 | 90 | 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); |
101 | 92 | }
|
102 | 93 |
|
103 | 94 | $customAdminUrl = $this->scopeConfig->getValue(
|
@@ -152,13 +143,53 @@ public function apply()
|
152 | 143 | $this->domainManager->addDomains($this->whitelist);
|
153 | 144 | }
|
154 | 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 | + $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 | + |
155 | 182 | /**
|
156 | 183 | * Add host to whitelist
|
157 | 184 | *
|
158 | 185 | * @param string $url
|
159 | 186 | */
|
160 | 187 | private function addHost($url)
|
161 | 188 | {
|
| 189 | + if (!is_string($url)) { |
| 190 | + return; |
| 191 | + } |
| 192 | + |
162 | 193 | $host = $this->uriHandler->parse($url)->getHost();
|
163 | 194 | if ($host && !in_array($host, $this->whitelist)) {
|
164 | 195 | $this->whitelist[] = $host;
|
|
0 commit comments