5
5
*/
6
6
namespace Magento \Indexer \Console \Command ;
7
7
8
+ use Magento \Framework \Indexer \IndexerInterface ;
8
9
use Symfony \Component \Console \Input \InputInterface ;
9
- use Symfony \Component \Console \Output \OutputInterface ;
10
- use Symfony \Component \Console \Input \InputOption ;
11
10
use Symfony \Component \Console \Input \InputArgument ;
12
- use Magento \Framework \Indexer \IndexerInterface ;
13
- use Magento \Framework \App \ObjectManagerFactory ;
14
- use Magento \Indexer \Model \IndexerFactory ;
15
11
16
12
/**
17
13
* An Abstract class for all Indexer related commands.
@@ -25,28 +21,7 @@ abstract class AbstractIndexerManageCommand extends AbstractIndexerCommand
25
21
const INPUT_KEY_INDEXERS = 'index ' ;
26
22
27
23
/**
28
- * @var IndexerFactory
29
- * @since 2.2.0
30
- */
31
- private $ indexerFactory ;
32
-
33
- /**
34
- * Constructor
35
- *
36
- * @param ObjectManagerFactory $objectManagerFactory
37
- * @param IndexerFactory|null $indexerFactory
38
- * @since 2.2.0
39
- */
40
- public function __construct (
41
- ObjectManagerFactory $ objectManagerFactory ,
42
- IndexerFactory $ indexerFactory = null
43
- ) {
44
- parent ::__construct ($ objectManagerFactory );
45
- $ this ->indexerFactory = $ indexerFactory ;
46
- }
47
-
48
- /**
49
- * Gets list of indexers
24
+ * Returns the ordered list of indexers.
50
25
*
51
26
* @param InputInterface $input
52
27
* @return IndexerInterface[]
@@ -60,32 +35,21 @@ protected function getIndexers(InputInterface $input)
60
35
$ requestedTypes = $ input ->getArgument (self ::INPUT_KEY_INDEXERS );
61
36
$ requestedTypes = array_filter (array_map ('trim ' , $ requestedTypes ), 'strlen ' );
62
37
}
38
+
63
39
if (empty ($ requestedTypes )) {
64
- return $ this ->getAllIndexers ();
40
+ $ indexers = $ this ->getAllIndexers ();
65
41
} else {
66
- $ indexers = [];
67
- $ unsupportedTypes = [];
68
- foreach ($ requestedTypes as $ code ) {
69
- $ indexer = $ this ->getIndexerFactory ()->create ();
70
- try {
71
- $ indexer ->load ($ code );
72
- $ indexers [] = $ indexer ;
73
- } catch (\Exception $ e ) {
74
- $ unsupportedTypes [] = $ code ;
75
- }
76
- }
42
+ $ availableIndexers = $ this ->getAllIndexers ();
43
+ $ unsupportedTypes = array_diff ($ requestedTypes , array_keys ($ availableIndexers ));
77
44
if ($ unsupportedTypes ) {
78
- $ availableTypes = [];
79
- $ indexers = $ this ->getAllIndexers ();
80
- foreach ($ indexers as $ indexer ) {
81
- $ availableTypes [] = $ indexer ->getId ();
82
- }
83
45
throw new \InvalidArgumentException (
84
46
"The following requested index types are not supported: ' " . join ("', ' " , $ unsupportedTypes )
85
- . "'. " . PHP_EOL . 'Supported types: ' . join (", " , $ availableTypes )
47
+ . "'. " . PHP_EOL . 'Supported types: ' . join (", " , array_keys ( $ availableIndexers ) )
86
48
);
87
49
}
50
+ $ indexers = array_intersect_key ($ availableIndexers , array_flip ($ requestedTypes ));
88
51
}
52
+
89
53
return $ indexers ;
90
54
}
91
55
@@ -105,19 +69,4 @@ public function getInputList()
105
69
),
106
70
];
107
71
}
108
-
109
- /**
110
- * Get indexer factory
111
- *
112
- * @return IndexerFactory
113
- * @deprecated 2.2.0
114
- * @since 2.2.0
115
- */
116
- private function getIndexerFactory ()
117
- {
118
- if (null === $ this ->indexerFactory ) {
119
- $ this ->indexerFactory = $ this ->getObjectManager ()->get (IndexerFactory::class);
120
- }
121
- return $ this ->indexerFactory ;
122
- }
123
72
}
0 commit comments