Skip to content

Commit d8c2cf8

Browse files
oshmyheliukshiftedreality
authored andcommitted
MAGECLOUD-4444: Add "products" to WARM_UP_PAGES && MAGECLOUD-4445: Add "store" to WARM_UP_PAGES logic (#17)
1 parent a6835b4 commit d8c2cf8

File tree

11 files changed

+577
-57
lines changed

11 files changed

+577
-57
lines changed

Console/Command/ConfigShowDefaultUrlCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6363
/** @var Store $store */
6464
$store = $this->storeManager->getDefaultStoreView();
6565
$baseUrl = $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, $store->isUrlSecure());
66-
$output->write($this->urlFixer->run($store, $baseUrl));
66+
$output->writeln($this->urlFixer->run($store, $baseUrl));
6767

6868
return Cli::RETURN_SUCCESS;
6969
}

Console/Command/ConfigShowEntityUrlsCommand.php

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77

88
namespace Magento\CloudComponents\Console\Command;
99

10-
use Magento\CloudComponents\Model\UrlFixer;
10+
use Magento\CloudComponents\Model\UrlFinder\Product;
11+
use Magento\CloudComponents\Model\UrlFinderFactory;
1112
use Magento\Framework\App\Area;
1213
use Magento\Framework\App\State;
1314
use Magento\Framework\Console\Cli;
1415
use Magento\Framework\Exception\LocalizedException;
15-
use Magento\Framework\UrlFactory;
16+
use Magento\Framework\Exception\NoSuchEntityException;
1617
use Magento\Store\Api\Data\StoreInterface;
1718
use Magento\Store\Model\StoreManagerInterface;
1819
use Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite;
19-
use Magento\UrlRewrite\Model\UrlFinderInterface;
20-
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
2120
use Symfony\Component\Console\Command\Command;
2221
use Symfony\Component\Console\Input\InputInterface;
2322
use Symfony\Component\Console\Input\InputOption;
@@ -34,56 +33,46 @@ class ConfigShowEntityUrlsCommand extends Command
3433
*/
3534
const INPUT_OPTION_STORE_ID = 'store-id';
3635
const INPUT_OPTION_ENTITY_TYPE = 'entity-type';
36+
const INPUT_OPTION_PRODUCT_SKU = 'product-sku';
37+
const INPUT_OPTION_PRODUCT_LIMIT = 'product-limit';
3738

3839
/**
3940
* @var StoreManagerInterface
4041
*/
4142
private $storeManager;
4243

43-
/**
44-
* @var UrlFinderInterface
45-
*/
46-
private $urlFinder;
47-
48-
/**
49-
* @var UrlFactory
50-
*/
51-
private $urlFactory;
52-
5344
/**
5445
* @var State
5546
*/
5647
private $state;
5748

5849
/**
59-
* @var UrlFixer
50+
* @var UrlFinderFactory
6051
*/
61-
private $urlFixer;
52+
private $urlFinderFactory;
6253

6354
/**
6455
* @var array
6556
*/
66-
private $possibleEntities = [Rewrite::ENTITY_TYPE_CMS_PAGE, Rewrite::ENTITY_TYPE_CATEGORY];
57+
private $possibleEntities = [
58+
Rewrite::ENTITY_TYPE_CMS_PAGE,
59+
Rewrite::ENTITY_TYPE_CATEGORY,
60+
Rewrite::ENTITY_TYPE_PRODUCT
61+
];
6762

6863
/**
6964
* @param StoreManagerInterface $storeManager
70-
* @param UrlFinderInterface $urlFinder
71-
* @param UrlFactory $urlFactory
65+
* @param UrlFinderFactory $urlFinderFactory
7266
* @param State $state
73-
* @param UrlFixer $urlFixer
7467
*/
7568
public function __construct(
7669
StoreManagerInterface $storeManager,
77-
UrlFinderInterface $urlFinder,
78-
UrlFactory $urlFactory,
79-
State $state,
80-
UrlFixer $urlFixer
70+
UrlFinderFactory $urlFinderFactory,
71+
State $state
8172
) {
8273
$this->storeManager = $storeManager;
83-
$this->urlFinder = $urlFinder;
84-
$this->urlFactory = $urlFactory;
74+
$this->urlFinderFactory = $urlFinderFactory;
8575
$this->state = $state;
86-
$this->urlFixer = $urlFixer;
8776

8877
parent::__construct();
8978
}
@@ -101,7 +90,7 @@ protected function configure()
10190
$this->addOption(
10291
self::INPUT_OPTION_STORE_ID,
10392
null,
104-
InputOption::VALUE_OPTIONAL,
93+
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
10594
'Store ID'
10695
);
10796
$this->addOption(
@@ -110,6 +99,19 @@ protected function configure()
11099
InputOption::VALUE_REQUIRED,
111100
'Entity type: ' . implode(',', $this->possibleEntities)
112101
);
102+
$this->addOption(
103+
self::INPUT_OPTION_PRODUCT_SKU,
104+
null,
105+
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
106+
'Product SKUs'
107+
);
108+
$this->addOption(
109+
self::INPUT_OPTION_PRODUCT_LIMIT,
110+
null,
111+
InputOption::VALUE_OPTIONAL,
112+
'Product limit per store uses in case when product SKUs isn\'t provided',
113+
Product::PRODUCT_LIMIT
114+
);
113115

114116
parent::configure();
115117
}
@@ -133,17 +135,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
133135
return Cli::RETURN_FAILURE;
134136
}
135137

136-
$storeId = $input->getOption(self::INPUT_OPTION_STORE_ID);
137-
138-
if ($storeId === null) {
139-
$stores = $this->storeManager->getStores();
140-
} else {
141-
$stores = [$this->storeManager->getStore($storeId)];
142-
}
143-
144-
$urls = $this->getPageUrls($stores, $entityType);
138+
$urlFinder = $this->urlFinderFactory->create($entityType, [
139+
'stores' => $this->getStores($input),
140+
'productSku' => $input->getOption(self::INPUT_OPTION_PRODUCT_SKU),
141+
'productLimit' => $input->getOption(self::INPUT_OPTION_PRODUCT_LIMIT),
142+
]);
145143

146-
$output->write(json_encode(array_unique($urls)));
144+
$output->writeln(json_encode(array_unique($urlFinder->get())));
147145
return Cli::RETURN_SUCCESS;
148146
} catch (\Exception $e) {
149147
$output->writeln($e->getMessage());
@@ -152,28 +150,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
152150
}
153151

154152
/**
155-
* @param StoreInterface[] $stores
156-
* @param string $entityType
157-
* @return array
153+
* @param InputInterface $input
154+
* @return StoreInterface[]
155+
* @throws NoSuchEntityException
158156
*/
159-
private function getPageUrls(array $stores, string $entityType): array
157+
private function getStores(InputInterface $input): array
160158
{
161-
$urls = [];
162-
163-
foreach ($stores as $store) {
164-
$url = $this->urlFactory->create()->setScope($store->getId());
165-
166-
$entities = $this->urlFinder->findAllByData([
167-
UrlRewrite::STORE_ID => $store->getId(),
168-
UrlRewrite::ENTITY_TYPE => $entityType
169-
]);
159+
$storeIds = $input->getOption(self::INPUT_OPTION_STORE_ID);
170160

171-
foreach ($entities as $urlRewrite) {
172-
$urls[] = $this->urlFixer->run($store, $url->getUrl($urlRewrite->getRequestPath()));
161+
if (!empty($storeIds)) {
162+
$stores = [];
163+
foreach ($storeIds as $storeId) {
164+
$stores[] = $this->storeManager->getStore($storeId);
173165
}
166+
} else {
167+
$stores = $this->storeManager->getStores();
174168
}
175169

176-
return $urls;
170+
return $stores;
177171
}
178172

179173
/**

Console/Command/ConfigShowStoreUrlCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9393
);
9494
}
9595

96-
$output->write(json_encode($urls, JSON_FORCE_OBJECT));
96+
$output->writeln(json_encode($urls, JSON_FORCE_OBJECT));
9797
}
9898

9999
return Cli::RETURN_SUCCESS;

Model/UrlFinder/Entity.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CloudComponents\Model\UrlFinder;
9+
10+
use Magento\CloudComponents\Model\UrlFinderInterface as CloudUrlFinderInterface;
11+
use Magento\CloudComponents\Model\UrlFixer;
12+
use Magento\Store\Api\Data\StoreInterface;
13+
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
14+
use Magento\Framework\UrlFactory;
15+
use Magento\UrlRewrite\Model\UrlFinderInterface;
16+
17+
/**
18+
* Returns list of url by store id and entity type
19+
*/
20+
class Entity implements CloudUrlFinderInterface
21+
{
22+
/**
23+
* @var UrlFactory
24+
*/
25+
private $urlFactory;
26+
27+
/**
28+
* @var UrlFinderInterface
29+
*/
30+
private $urlFinder;
31+
32+
/**
33+
* @var UrlFixer
34+
*/
35+
private $urlFixer;
36+
37+
/**
38+
* @var string
39+
*/
40+
private $entityType;
41+
42+
/**
43+
* @var StoreInterface[]
44+
*/
45+
private $stores;
46+
47+
/**
48+
* @param UrlFactory $urlFactory
49+
* @param UrlFinderInterface $urlFinder
50+
* @param UrlFixer $urlFixer
51+
* @param string $entityType
52+
* @param StoreInterface[] $stores
53+
*/
54+
public function __construct(
55+
UrlFactory $urlFactory,
56+
UrlFinderInterface $urlFinder,
57+
UrlFixer $urlFixer,
58+
string $entityType,
59+
array $stores
60+
) {
61+
$this->urlFactory = $urlFactory;
62+
$this->urlFinder = $urlFinder;
63+
$this->urlFixer = $urlFixer;
64+
$this->entityType = $entityType;
65+
$this->stores = $stores;
66+
}
67+
68+
/**
69+
* Returns list of url by store ids and entity type
70+
*
71+
* @return array
72+
*/
73+
public function get(): array
74+
{
75+
$urls = [];
76+
77+
foreach ($this->stores as $store) {
78+
$url = $this->urlFactory->create()->setScope($store->getId());
79+
80+
$entities = $this->urlFinder->findAllByData([
81+
UrlRewrite::STORE_ID => $store->getId(),
82+
UrlRewrite::ENTITY_TYPE => $this->entityType
83+
]);
84+
85+
foreach ($entities as $urlRewrite) {
86+
$urls[] = $this->urlFixer->run($store, $url->getUrl($urlRewrite->getRequestPath()));
87+
}
88+
}
89+
90+
return $urls;
91+
}
92+
}

0 commit comments

Comments
 (0)