Skip to content

Commit a430f26

Browse files
oshmyheliukshiftedreality
authored andcommitted
MAGECLOUD-4094: Warm-up fails on {{base_url}}/magento/ however it is not configured in the WARM_UP_PAGES (#10)
1 parent 4be32d5 commit a430f26

File tree

5 files changed

+75
-10
lines changed

5 files changed

+75
-10
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
.idea
2-
composer.lock
1+
/.idea
2+
/composer.lock
3+
/vendor

Console/Command/ConfigShowDefaultUrlCommand.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CloudComponents\Console\Command;
77

8+
use Magento\CloudComponents\Model\UrlFixer;
89
use Magento\Framework\Console\Cli;
910
use Magento\Framework\UrlInterface;
1011
use Magento\Store\Model\Store;
@@ -23,13 +24,20 @@ class ConfigShowDefaultUrlCommand extends Command
2324
*/
2425
private $storeManager;
2526

27+
/**
28+
* @var UrlFixer
29+
*/
30+
private $urlFixer;
31+
2632
/**
2733
* @param StoreManagerInterface $storeManager
34+
* @param UrlFixer $urlFixer
2835
*/
29-
public function __construct(StoreManagerInterface $storeManager)
36+
public function __construct(StoreManagerInterface $storeManager, UrlFixer $urlFixer)
3037
{
3138
parent::__construct();
3239
$this->storeManager = $storeManager;
40+
$this->urlFixer = $urlFixer;
3341
}
3442

3543
/**
@@ -52,7 +60,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
5260
{
5361
/** @var Store $store */
5462
$store = $this->storeManager->getDefaultStoreView();
55-
$output->write($store->getBaseUrl(UrlInterface::URL_TYPE_LINK, $store->isUrlSecure()));
63+
$baseUrl = $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, $store->isUrlSecure());
64+
$output->write($this->urlFixer->run($store, $baseUrl));
5665

5766
return Cli::RETURN_SUCCESS;
5867
}

Console/Command/ConfigShowEntityUrlsCommand.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CloudComponents\Console\Command;
77

8+
use Magento\CloudComponents\Model\UrlFixer;
89
use Magento\Framework\App\Area;
910
use Magento\Framework\App\State;
1011
use Magento\Framework\Console\Cli;
@@ -14,11 +15,11 @@
1415
use Magento\Store\Model\StoreManagerInterface;
1516
use Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite;
1617
use Magento\UrlRewrite\Model\UrlFinderInterface;
18+
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
1719
use Symfony\Component\Console\Command\Command;
1820
use Symfony\Component\Console\Input\InputInterface;
1921
use Symfony\Component\Console\Input\InputOption;
2022
use Symfony\Component\Console\Output\OutputInterface;
21-
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
2223

2324
/**
2425
* Returns list of category or cms-page urls for given stores
@@ -51,6 +52,11 @@ class ConfigShowEntityUrlsCommand extends Command
5152
*/
5253
private $state;
5354

55+
/**
56+
* @var UrlFixer
57+
*/
58+
private $urlFixer;
59+
5460
/**
5561
* @var array
5662
*/
@@ -61,17 +67,20 @@ class ConfigShowEntityUrlsCommand extends Command
6167
* @param UrlFinderInterface $urlFinder
6268
* @param UrlFactory $urlFactory
6369
* @param State $state
70+
* @param UrlFixer $urlFixer
6471
*/
6572
public function __construct(
6673
StoreManagerInterface $storeManager,
6774
UrlFinderInterface $urlFinder,
6875
UrlFactory $urlFactory,
69-
State $state
76+
State $state,
77+
UrlFixer $urlFixer
7078
) {
7179
$this->storeManager = $storeManager;
7280
$this->urlFinder = $urlFinder;
7381
$this->urlFactory = $urlFactory;
7482
$this->state = $state;
83+
$this->urlFixer = $urlFixer;
7584

7685
parent::__construct();
7786
}
@@ -157,7 +166,7 @@ private function getPageUrls(array $stores, string $entityType): array
157166
]);
158167

159168
foreach ($entities as $urlRewrite) {
160-
$urls[] = $url->getUrl($urlRewrite->getRequestPath());
169+
$urls[] = $this->urlFixer->run($store, $url->getUrl($urlRewrite->getRequestPath()));
161170
}
162171
}
163172

Console/Command/ConfigShowStoreUrlCommand.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CloudComponents\Console\Command;
77

8+
use Magento\CloudComponents\Model\UrlFixer;
89
use Magento\Framework\Console\Cli;
910
use Magento\Framework\UrlInterface;
1011
use Magento\Store\Model\Store;
@@ -29,14 +30,22 @@ class ConfigShowStoreUrlCommand extends Command
2930
*/
3031
private $storeManager;
3132

33+
/**
34+
* @var UrlFixer
35+
*/
36+
private $urlFixer;
37+
3238
/**
3339
* @param StoreManagerInterface $storeManager
40+
* @param UrlFixer $urlFixer
3441
*/
3542
public function __construct(
36-
StoreManagerInterface $storeManager
43+
StoreManagerInterface $storeManager,
44+
UrlFixer $urlFixer
3745
) {
3846
parent::__construct();
3947
$this->storeManager = $storeManager;
48+
$this->urlFixer = $urlFixer;
4049
}
4150

4251
/**
@@ -70,12 +79,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
7079
$storeId = $input->getArgument(self::INPUT_ARGUMENT_STORE_ID);
7180
if ($storeId !== null) {
7281
$store = $this->storeManager->getStore($storeId);
82+
$baseUrl = $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, $store->isUrlSecure());
7383

74-
$output->writeln($store->getBaseUrl(UrlInterface::URL_TYPE_LINK, $store->isUrlSecure()));
84+
$output->writeln($this->urlFixer->run($store, $baseUrl));
7585
} else {
7686
$urls = [];
7787
foreach ($this->storeManager->getStores(true) as $store) {
78-
$urls[$store->getId()] = $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, $store->isUrlSecure());
88+
$urls[$store->getId()] = $this->urlFixer->run(
89+
$store,
90+
$store->getBaseUrl(UrlInterface::URL_TYPE_LINK, $store->isUrlSecure())
91+
);
7992
}
8093

8194
$output->write(json_encode($urls, JSON_FORCE_OBJECT));

Model/UrlFixer.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CloudComponents\Model;
7+
8+
use Magento\Store\Model\Store;
9+
10+
/**
11+
* Removes /magento/ part from url when rewrites for store are disabled.
12+
*/
13+
class UrlFixer
14+
{
15+
/**
16+
* Removes SCRIPT_FILENAME (/magento/) from url if rewrites are disabled.
17+
*
18+
* @param Store $store
19+
* @param string $url
20+
* @return string
21+
*/
22+
public function run(Store $store, $url): string
23+
{
24+
if (
25+
($store->getForceDisableRewrites() || !$store->getConfig(Store::XML_PATH_USE_REWRITES))
26+
&& strpos($url, '/magento/') !== false
27+
) {
28+
return preg_replace('|/magento/|', '/', $url, 1);
29+
}
30+
31+
return $url;
32+
}
33+
}

0 commit comments

Comments
 (0)