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,21 +119,25 @@ 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 " ) {
117
- return $ changeLogWalkerFactory ->create (
118
- \Magento \Framework \Mview \View \ChangeLogBatchWalker::class // @phpstan-ignore-line
122
+ if ($ this ->isMagentoVersionLessThan ("2.4.7 " )) {
123
+ return $ this ->objectManager ->create (
124
+ \Magento \Framework \Mview \View \ChangeLogBatchWalkerFactory::class // @phpstan-ignore-line
119
125
);
120
126
}
121
-
122
- $ changelogWalkerFactory = $ this ->objectManager ->create (
127
+ return $ this ->objectManager ->create (
123
128
\Magento \Framework \Mview \View \ChangelogBatchWalkerFactory::class // @phpstan-ignore-line
124
129
);
125
- return $ changelogWalkerFactory ->create (
126
- \Magento \Framework \Mview \View \ChangelogBatchWalker::class // @phpstan-ignore-line
127
- );
130
+ }
131
+
132
+ /**
133
+ * Returns true if the version is lower than the expected version
134
+ *
135
+ * @param $version
136
+ * @return bool
137
+ */
138
+ private function isMagentoVersionLessThan ($ version )
139
+ {
140
+ return version_compare ($ this ->productMetadataInterface ->getVersion (), $ version , '< ' ) === true ;
128
141
}
129
142
130
143
/**
0 commit comments