77
88namespace Magento \CloudComponents \Console \Command ;
99
10- use Magento \CloudComponents \Model \UrlFixer ;
10+ use Magento \CloudComponents \Model \UrlFinder \Product ;
11+ use Magento \CloudComponents \Model \UrlFinderFactory ;
1112use Magento \Framework \App \Area ;
1213use Magento \Framework \App \State ;
1314use Magento \Framework \Console \Cli ;
1415use Magento \Framework \Exception \LocalizedException ;
15- use Magento \Framework \UrlFactory ;
16+ use Magento \Framework \Exception \ NoSuchEntityException ;
1617use Magento \Store \Api \Data \StoreInterface ;
1718use Magento \Store \Model \StoreManagerInterface ;
1819use Magento \UrlRewrite \Controller \Adminhtml \Url \Rewrite ;
19- use Magento \UrlRewrite \Model \UrlFinderInterface ;
20- use Magento \UrlRewrite \Service \V1 \Data \UrlRewrite ;
2120use Symfony \Component \Console \Command \Command ;
2221use Symfony \Component \Console \Input \InputInterface ;
2322use 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 /**
0 commit comments