3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \CloudComponents \Console \Command ;
7
9
10
+ use Magento \CloudComponents \Model \UrlFinder \Product ;
11
+ use Magento \CloudComponents \Model \UrlFinderFactory ;
8
12
use Magento \Framework \App \Area ;
9
13
use Magento \Framework \App \State ;
10
14
use Magento \Framework \Console \Cli ;
11
15
use Magento \Framework \Exception \LocalizedException ;
12
- use Magento \Framework \UrlFactory ;
16
+ use Magento \Framework \Exception \ NoSuchEntityException ;
13
17
use Magento \Store \Api \Data \StoreInterface ;
14
18
use Magento \Store \Model \StoreManagerInterface ;
15
19
use Magento \UrlRewrite \Controller \Adminhtml \Url \Rewrite ;
16
- use Magento \UrlRewrite \Model \UrlFinderInterface ;
17
20
use Symfony \Component \Console \Command \Command ;
18
21
use Symfony \Component \Console \Input \InputInterface ;
19
22
use Symfony \Component \Console \Input \InputOption ;
20
23
use Symfony \Component \Console \Output \OutputInterface ;
21
- use Magento \UrlRewrite \Service \V1 \Data \UrlRewrite ;
22
24
23
25
/**
24
26
* Returns list of category or cms-page urls for given stores
27
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
25
28
*/
26
29
class ConfigShowEntityUrlsCommand extends Command
27
30
{
@@ -30,47 +33,45 @@ class ConfigShowEntityUrlsCommand extends Command
30
33
*/
31
34
const INPUT_OPTION_STORE_ID = 'store-id ' ;
32
35
const INPUT_OPTION_ENTITY_TYPE = 'entity-type ' ;
36
+ const INPUT_OPTION_PRODUCT_SKU = 'product-sku ' ;
37
+ const INPUT_OPTION_PRODUCT_LIMIT = 'product-limit ' ;
33
38
34
39
/**
35
40
* @var StoreManagerInterface
36
41
*/
37
42
private $ storeManager ;
38
43
39
44
/**
40
- * @var UrlFinderInterface
41
- */
42
- private $ urlFinder ;
43
-
44
- /**
45
- * @var UrlFactory
45
+ * @var State
46
46
*/
47
- private $ urlFactory ;
47
+ private $ state ;
48
48
49
49
/**
50
- * @var State
50
+ * @var UrlFinderFactory
51
51
*/
52
- private $ state ;
52
+ private $ urlFinderFactory ;
53
53
54
54
/**
55
55
* @var array
56
56
*/
57
- 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
+ ];
58
62
59
63
/**
60
64
* @param StoreManagerInterface $storeManager
61
- * @param UrlFinderInterface $urlFinder
62
- * @param UrlFactory $urlFactory
65
+ * @param UrlFinderFactory $urlFinderFactory
63
66
* @param State $state
64
67
*/
65
68
public function __construct (
66
69
StoreManagerInterface $ storeManager ,
67
- UrlFinderInterface $ urlFinder ,
68
- UrlFactory $ urlFactory ,
70
+ UrlFinderFactory $ urlFinderFactory ,
69
71
State $ state
70
72
) {
71
73
$ this ->storeManager = $ storeManager ;
72
- $ this ->urlFinder = $ urlFinder ;
73
- $ this ->urlFactory = $ urlFactory ;
74
+ $ this ->urlFinderFactory = $ urlFinderFactory ;
74
75
$ this ->state = $ state ;
75
76
76
77
parent ::__construct ();
@@ -89,7 +90,7 @@ protected function configure()
89
90
$ this ->addOption (
90
91
self ::INPUT_OPTION_STORE_ID ,
91
92
null ,
92
- InputOption::VALUE_OPTIONAL ,
93
+ InputOption::VALUE_IS_ARRAY | InputOption:: VALUE_OPTIONAL ,
93
94
'Store ID '
94
95
);
95
96
$ this ->addOption (
@@ -98,6 +99,19 @@ protected function configure()
98
99
InputOption::VALUE_REQUIRED ,
99
100
'Entity type: ' . implode (', ' , $ this ->possibleEntities )
100
101
);
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
+ );
101
115
102
116
parent ::configure ();
103
117
}
@@ -121,17 +135,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
121
135
return Cli::RETURN_FAILURE ;
122
136
}
123
137
124
- $ storeId = $ input ->getOption (self ::INPUT_OPTION_STORE_ID );
125
-
126
- if ($ storeId === null ) {
127
- $ stores = $ this ->storeManager ->getStores ();
128
- } else {
129
- $ stores = [$ this ->storeManager ->getStore ($ storeId )];
130
- }
131
-
132
- $ 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
+ ]);
133
143
134
- $ output ->write (json_encode (array_unique ($ urls )));
144
+ $ output ->writeln (json_encode (array_unique ($ urlFinder -> get () )));
135
145
return Cli::RETURN_SUCCESS ;
136
146
} catch (\Exception $ e ) {
137
147
$ output ->writeln ($ e ->getMessage ());
@@ -140,28 +150,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
140
150
}
141
151
142
152
/**
143
- * @param StoreInterface[] $stores
144
- * @param string $entityType
145
- * @return array
153
+ * @param InputInterface $input
154
+ * @return StoreInterface[]
155
+ * @throws NoSuchEntityException
146
156
*/
147
- private function getPageUrls ( array $ stores , string $ entityType ): array
157
+ private function getStores ( InputInterface $ input ): array
148
158
{
149
- $ urls = [];
150
-
151
- foreach ($ stores as $ store ) {
152
- $ url = $ this ->urlFactory ->create ()->setScope ($ store ->getId ());
153
-
154
- $ entities = $ this ->urlFinder ->findAllByData ([
155
- UrlRewrite::STORE_ID => $ store ->getId (),
156
- UrlRewrite::ENTITY_TYPE => $ entityType
157
- ]);
159
+ $ storeIds = $ input ->getOption (self ::INPUT_OPTION_STORE_ID );
158
160
159
- foreach ($ entities as $ urlRewrite ) {
160
- $ urls [] = $ url ->getUrl ($ urlRewrite ->getRequestPath ());
161
+ if (!empty ($ storeIds )) {
162
+ $ stores = [];
163
+ foreach ($ storeIds as $ storeId ) {
164
+ $ stores [] = $ this ->storeManager ->getStore ($ storeId );
161
165
}
166
+ } else {
167
+ $ stores = $ this ->storeManager ->getStores ();
162
168
}
163
169
164
- return $ urls ;
170
+ return $ stores ;
165
171
}
166
172
167
173
/**
0 commit comments