25
25
use Magento \Framework \Mview \View ;
26
26
use Magento \Indexer \Model \WorkingStateProvider ;
27
27
use Magento \Framework \ObjectManagerInterface ;
28
+ use Magento \Framework \App \ProductMetadataInterface ;
28
29
29
30
class FacebookCatalogUpdateFullReindexPlugin
30
31
{
@@ -48,21 +49,29 @@ class FacebookCatalogUpdateFullReindexPlugin
48
49
*/
49
50
private $ objectManager ;
50
51
52
+ /**
53
+ * @var ProductMetadataInterface
54
+ */
55
+ private $ productMetadataInterface ;
56
+
51
57
/**
52
58
* FacebookCatalogUpdateOnIndexerPlugin constructor
53
59
*
54
60
* @param WorkingStateProvider $workingStateProvider
55
61
* @param FBCatalogUpdateResourceModel $fbCatalogUpdateResourceModel
56
62
* @param ObjectManagerInterface $objectManager
63
+ * @param ProductMetadataInterface $productMetadataInterface
57
64
*/
58
65
public function __construct (
59
66
WorkingStateProvider $ workingStateProvider ,
60
67
FBCatalogUpdateResourceModel $ fbCatalogUpdateResourceModel ,
61
- ObjectManagerInterface $ objectManager
68
+ ObjectManagerInterface $ objectManager ,
69
+ ProductMetadataInterface $ productMetadataInterface
62
70
) {
63
71
$ this ->workingStateProvider = $ workingStateProvider ;
64
72
$ this ->fbCatalogUpdateResourceModel = $ fbCatalogUpdateResourceModel ;
65
73
$ this ->objectManager = $ objectManager ;
74
+ $ this ->productMetadataInterface = $ productMetadataInterface ;
66
75
}
67
76
68
77
/**
@@ -110,10 +119,10 @@ public function beforeReindexAll(Indexer $subject)
110
119
*/
111
120
public function getChangelogBatchWalkerInstance ()
112
121
{
113
- $ changeLogWalkerFactory = $ this ->objectManager -> create (
114
- \ Magento \ Framework \ Mview \ View \ChangeLogBatchWalkerFactory::class // @phpstan-ignore-line
115
- );
116
- if ( get_class ( $ changeLogWalkerFactory ) == " ChangeLogBatchWalkerFactory " ) {
122
+ if ( $ this ->isMagentoVersionLessThan ( " 2.4.7 " )) {
123
+ $ changeLogWalkerFactory = $ this -> objectManager -> create (
124
+ \ Magento \ Framework \ Mview \ View \ChangeLogBatchWalkerFactory::class // @phpstan-ignore-line
125
+ );
117
126
return $ changeLogWalkerFactory ->create (
118
127
\Magento \Framework \Mview \View \ChangeLogBatchWalker::class // @phpstan-ignore-line
119
128
);
@@ -127,6 +136,17 @@ public function getChangelogBatchWalkerInstance()
127
136
);
128
137
}
129
138
139
+ /**
140
+ * Returns true if the version is lower than the expected version
141
+ *
142
+ * @param $version
143
+ * @return bool
144
+ */
145
+ private function isMagentoVersionLessThan ($ version )
146
+ {
147
+ return version_compare ($ this ->productMetadataInterface ->getVersion (), $ version , '< ' ) === true ;
148
+ }
149
+
130
150
/**
131
151
* Add products with children
132
152
*
0 commit comments