7
7
8
8
namespace Magento \CloudComponents \Console \Command ;
9
9
10
- use Magento \CloudComponents \Model \UrlFixer ;
10
+ use Magento \CloudComponents \Model \UrlFinder \Product ;
11
+ use Magento \CloudComponents \Model \UrlFinderFactory ;
11
12
use Magento \Framework \App \Area ;
12
13
use Magento \Framework \App \State ;
13
14
use Magento \Framework \Console \Cli ;
14
15
use Magento \Framework \Exception \LocalizedException ;
15
- use Magento \Framework \UrlFactory ;
16
+ use Magento \Framework \Exception \ NoSuchEntityException ;
16
17
use Magento \Store \Api \Data \StoreInterface ;
17
18
use Magento \Store \Model \StoreManagerInterface ;
18
19
use Magento \UrlRewrite \Controller \Adminhtml \Url \Rewrite ;
19
- use Magento \UrlRewrite \Model \UrlFinderInterface ;
20
- use Magento \UrlRewrite \Service \V1 \Data \UrlRewrite ;
21
20
use Symfony \Component \Console \Command \Command ;
22
21
use Symfony \Component \Console \Input \InputInterface ;
23
22
use Symfony \Component \Console \Input \InputOption ;
@@ -34,56 +33,46 @@ class ConfigShowEntityUrlsCommand extends Command
34
33
*/
35
34
const INPUT_OPTION_STORE_ID = 'store-id ' ;
36
35
const INPUT_OPTION_ENTITY_TYPE = 'entity-type ' ;
36
+ const INPUT_OPTION_PRODUCT_SKU = 'product-sku ' ;
37
+ const INPUT_OPTION_PRODUCT_LIMIT = 'product-limit ' ;
37
38
38
39
/**
39
40
* @var StoreManagerInterface
40
41
*/
41
42
private $ storeManager ;
42
43
43
- /**
44
- * @var UrlFinderInterface
45
- */
46
- private $ urlFinder ;
47
-
48
- /**
49
- * @var UrlFactory
50
- */
51
- private $ urlFactory ;
52
-
53
44
/**
54
45
* @var State
55
46
*/
56
47
private $ state ;
57
48
58
49
/**
59
- * @var UrlFixer
50
+ * @var UrlFinderFactory
60
51
*/
61
- private $ urlFixer ;
52
+ private $ urlFinderFactory ;
62
53
63
54
/**
64
55
* @var array
65
56
*/
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
+ ];
67
62
68
63
/**
69
64
* @param StoreManagerInterface $storeManager
70
- * @param UrlFinderInterface $urlFinder
71
- * @param UrlFactory $urlFactory
65
+ * @param UrlFinderFactory $urlFinderFactory
72
66
* @param State $state
73
- * @param UrlFixer $urlFixer
74
67
*/
75
68
public function __construct (
76
69
StoreManagerInterface $ storeManager ,
77
- UrlFinderInterface $ urlFinder ,
78
- UrlFactory $ urlFactory ,
79
- State $ state ,
80
- UrlFixer $ urlFixer
70
+ UrlFinderFactory $ urlFinderFactory ,
71
+ State $ state
81
72
) {
82
73
$ this ->storeManager = $ storeManager ;
83
- $ this ->urlFinder = $ urlFinder ;
84
- $ this ->urlFactory = $ urlFactory ;
74
+ $ this ->urlFinderFactory = $ urlFinderFactory ;
85
75
$ this ->state = $ state ;
86
- $ this ->urlFixer = $ urlFixer ;
87
76
88
77
parent ::__construct ();
89
78
}
@@ -101,7 +90,7 @@ protected function configure()
101
90
$ this ->addOption (
102
91
self ::INPUT_OPTION_STORE_ID ,
103
92
null ,
104
- InputOption::VALUE_OPTIONAL ,
93
+ InputOption::VALUE_IS_ARRAY | InputOption:: VALUE_OPTIONAL ,
105
94
'Store ID '
106
95
);
107
96
$ this ->addOption (
@@ -110,6 +99,19 @@ protected function configure()
110
99
InputOption::VALUE_REQUIRED ,
111
100
'Entity type: ' . implode (', ' , $ this ->possibleEntities )
112
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
+ );
113
115
114
116
parent ::configure ();
115
117
}
@@ -133,17 +135,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
133
135
return Cli::RETURN_FAILURE ;
134
136
}
135
137
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
+ ]);
145
143
146
- $ output ->write (json_encode (array_unique ($ urls )));
144
+ $ output ->writeln (json_encode (array_unique ($ urlFinder -> get () )));
147
145
return Cli::RETURN_SUCCESS ;
148
146
} catch (\Exception $ e ) {
149
147
$ output ->writeln ($ e ->getMessage ());
@@ -152,28 +150,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
152
150
}
153
151
154
152
/**
155
- * @param StoreInterface[] $stores
156
- * @param string $entityType
157
- * @return array
153
+ * @param InputInterface $input
154
+ * @return StoreInterface[]
155
+ * @throws NoSuchEntityException
158
156
*/
159
- private function getPageUrls ( array $ stores , string $ entityType ): array
157
+ private function getStores ( InputInterface $ input ): array
160
158
{
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 );
170
160
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 );
173
165
}
166
+ } else {
167
+ $ stores = $ this ->storeManager ->getStores ();
174
168
}
175
169
176
- return $ urls ;
170
+ return $ stores ;
177
171
}
178
172
179
173
/**
0 commit comments