1616
1717namespace Magento \DataExporter \Service ;
1818
19- use Magento \DataExporter \Model \Indexer \FeedIndexer ;
2019use Magento \DataExporter \Model \Indexer \FeedIndexMetadata ;
2120use Magento \DataExporter \Model \Logging \CommerceDataExportLoggerInterface ;
2221use Magento \Framework \Indexer \IndexerInterface ;
23- use Magento \Framework \Mview \ActionFactory ;
24- use Magento \Indexer \Model \Indexer \Collection ;
22+ use Magento \Framework \Indexer \IndexerRegistry ;
2523
2624/**
2725 * Return Feed Indexer instance for given metadata
2826 */
2927class FeedIndexerProvider
3028{
31- /**
32- * @var array|null
33- */
34- private ?array $ feedNameToIndexerMap = null ;
35-
3629 /**
3730 * Constructor
3831 *
39- * @param Collection $indexerCollection
40- * @param ActionFactory $actionFactory
32+ * @param IndexerRegistry $indexerRegistry
4133 * @param CommerceDataExportLoggerInterface $logger
4234 */
4335 public function __construct (
44- private readonly Collection $ indexerCollection ,
45- private readonly ActionFactory $ actionFactory ,
36+ private readonly IndexerRegistry $ indexerRegistry ,
4637 private readonly CommerceDataExportLoggerInterface $ logger
4738 ) {
4839 }
@@ -55,23 +46,22 @@ public function __construct(
5546 */
5647 public function getIndexer (FeedIndexMetadata $ metadata ): ?IndexerInterface
5748 {
58- if ($ this ->feedNameToIndexerMap === null ) {
59- foreach ($ this ->indexerCollection ->getItems () as $ indexer ) {
60- try {
61- $ actionIndexer = $ this ->actionFactory ->get (
62- $ indexer ->getActionClass ()
63- );
64- if ($ actionIndexer instanceof FeedIndexer) {
65- $ this ->feedNameToIndexerMap [$ actionIndexer ->getFeedIndexMetadata ()->getFeedName ()] = $ indexer ;
66- }
67- } catch (\Exception $ e ) {
68- $ this ->logger ->error (
69- 'Cannot load feed indexer ' ,
70- ['indexer ' => $ indexer ->getId (), 'error ' => $ e ->getMessage ()]
71- );
72- }
73- }
49+ if ($ metadata ->getIndexerId () == null ) {
50+ $ this ->logger ->warning (
51+ 'Feed metadata does not contain indexer name ' ,
52+ ['feedName ' => $ metadata ->getFeedName ()]
53+ );
54+ return null ;
55+ }
56+
57+ try {
58+ return $ this ->indexerRegistry ->get ($ metadata ->getIndexerId ());
59+ } catch (\Exception $ e ) {
60+ $ this ->logger ->error (
61+ 'Cannot load feed indexer for feed ' ,
62+ ['feedName ' => $ metadata ->getFeedName (), 'error ' => $ e ->getMessage ()]
63+ );
7464 }
75- return $ this -> feedNameToIndexerMap [ $ metadata -> getFeedName ()] ?? null ;
65+ return null ;
7666 }
7767}
0 commit comments