Skip to content

Commit a87e3dd

Browse files
pradeepkanakaPradeep KanakaPradeep Kanaka
authored
Fix magento version compatibility issue (#779)
* Fix magento version compatibility issue * Initialize ObjectManager * Fix static test warnings * Add line break --------- Co-authored-by: Pradeep Kanaka <[email protected]> Co-authored-by: Pradeep Kanaka <[email protected]>
1 parent 2796781 commit a87e3dd

File tree

2 files changed

+74
-20
lines changed

2 files changed

+74
-20
lines changed

app/code/Meta/BusinessExtension/Model/System/Message/ConflictingModulesNotification.php

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,94 @@
99

1010
class ConflictingModulesNotification implements MessageInterface
1111
{
12-
1312
/**
1413
* @var MetaIssueNotification
1514
*/
1615
private MetaIssueNotification $metaIssueNotification;
16+
1717
/**
1818
* @var ModuleManager
1919
*/
2020
private ModuleManager $moduleManager;
2121

22+
/**
23+
* @var array
24+
*/
2225
private static array $conflictingModules = ['Apptrian_MetaPixelApi'];
26+
27+
/**
28+
* @var string
29+
*/
2330
private static string $meta_business_extension = 'Meta_BusinessExtension';
31+
32+
/**
33+
* @var string
34+
*/
2435
private string $conflictingModulesFound = '';
2536

37+
/**
38+
* ConflictingModulesNotification constructor.
39+
*
40+
* @param MetaIssueNotification $metaIssueNotification
41+
* @param ModuleManager $moduleManager
42+
*/
2643
public function __construct(
2744
MetaIssueNotification $metaIssueNotification,
2845
ModuleManager $moduleManager
2946
) {
3047
$this->metaIssueNotification = $metaIssueNotification;
3148
$this->moduleManager = $moduleManager;
3249
}
50+
51+
/**
52+
* Get identity
53+
*
54+
* @return string
55+
*/
3356
public function getIdentity()
3457
{
3558
$notification = $this->metaIssueNotification->loadVersionNotification();
3659
return $notification['notification_id'] ?? '';
3760
}
3861

62+
/**
63+
* Validate if any conflicting modules are found
64+
*
65+
* @return bool
66+
*/
3967
public function isDisplayed()
4068
{
41-
4269
//find out if the user enabled the Meta Business Extension
4370
$has_Meta_BusinessExtension = $this->moduleManager->isEnabled(self::$meta_business_extension);
4471

4572
//iterate through the user's module manager to see if they have any conflicting modules
46-
foreach(self::$conflictingModules as $conflictingModule) {
47-
if ($this->moduleManager->isEnabled($conflictingModule) && $has_Meta_BusinessExtension)
48-
{
73+
foreach (self::$conflictingModules as $conflictingModule) {
74+
if ($this->moduleManager->isEnabled($conflictingModule) && $has_Meta_BusinessExtension) {
4975
$this->conflictingModulesFound = $conflictingModule;
5076
return true;
5177
}
5278
}
5379
return false;
5480
}
5581

56-
82+
/**
83+
* Get text
84+
*
85+
* @return string
86+
*/
5787
public function getText()
5888
{
59-
return sprintf( 'The following module conflicts with the Facebook & Instagram Extension: [%s] . Please disable the conflicting module.',
60-
$this->conflictingModulesFound);
89+
return sprintf('The following module conflicts with the Facebook & Instagram Extension: [%s].
90+
Please disable the conflicting module.', $this->conflictingModulesFound);
6191
}
6292

93+
/**
94+
* Get severity
95+
*
96+
* @return int
97+
*/
6398
public function getSeverity()
6499
{
65100
return self::SEVERITY_CRITICAL;
66101
}
67-
68-
}
102+
}

app/code/Meta/Catalog/Plugin/FacebookCatalogUpdateFullReindexPlugin.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222

2323
use Meta\Catalog\Model\ResourceModel\FacebookCatalogUpdate as FBCatalogUpdateResourceModel;
2424
use Magento\Indexer\Model\Indexer;
25-
use Magento\Framework\Mview\View\ChangelogBatchWalker;
26-
use Magento\Framework\Mview\View\ChangelogBatchWalkerFactory;
2725
use Magento\Framework\Mview\View;
2826
use Magento\Indexer\Model\WorkingStateProvider;
27+
use Magento\Framework\ObjectManagerInterface;
2928

3029
class FacebookCatalogUpdateFullReindexPlugin
3130
{
@@ -40,30 +39,30 @@ class FacebookCatalogUpdateFullReindexPlugin
4039
private $fbCatalogUpdateResourceModel;
4140

4241
/**
43-
* @var ChangelogBatchWalkerFactory
42+
* @var WorkingStateProvider
4443
*/
45-
private $changelogBatchWalkerFactory;
44+
private $workingStateProvider;
4645

4746
/**
48-
* @var WorkingStateProvider
47+
* @var ObjectManagerInterface
4948
*/
50-
private $workingStateProvider;
49+
private $objectManager;
5150

5251
/**
5352
* FacebookCatalogUpdateOnIndexerPlugin constructor
5453
*
5554
* @param WorkingStateProvider $workingStateProvider
5655
* @param FBCatalogUpdateResourceModel $fbCatalogUpdateResourceModel
57-
* @param ChangelogBatchWalkerFactory $changelogBatchWalkerFactory
56+
* @param ObjectManagerInterface $objectManager
5857
*/
5958
public function __construct(
6059
WorkingStateProvider $workingStateProvider,
6160
FBCatalogUpdateResourceModel $fbCatalogUpdateResourceModel,
62-
ChangelogBatchWalkerFactory $changelogBatchWalkerFactory
61+
ObjectManagerInterface $objectManager
6362
) {
6463
$this->workingStateProvider = $workingStateProvider;
6564
$this->fbCatalogUpdateResourceModel = $fbCatalogUpdateResourceModel;
66-
$this->changelogBatchWalkerFactory = $changelogBatchWalkerFactory;
65+
$this->objectManager = $objectManager;
6766
}
6867

6968
/**
@@ -85,7 +84,7 @@ public function beforeReindexAll(Indexer $subject)
8584
$nextVersionId = $cl->getVersion();
8685

8786
while ($currentVersionId < $nextVersionId) {
88-
$walker = $this->changelogBatchWalkerFactory->create(ChangelogBatchWalker::class);
87+
$walker = $this->getChangelogBatchWalkerInstance();
8988
$batches = $walker->walk($cl, $currentVersionId, $nextVersionId, $batchSize);
9089

9190
foreach ($batches as $ids) {
@@ -98,6 +97,27 @@ public function beforeReindexAll(Indexer $subject)
9897
}
9998
}
10099

100+
/**
101+
* Get class object
102+
*/
103+
public function getChangelogBatchWalkerInstance()
104+
{
105+
if (class_exists(\Magento\Framework\Mview\View\ChangeLogBatchWalkerFactory::class)) { // @phpstan-ignore-line
106+
$changeLogWalkerFactory = $this->objectManager->create(
107+
\Magento\Framework\Mview\View\ChangeLogBatchWalkerFactory::class // @phpstan-ignore-line
108+
);
109+
return $changeLogWalkerFactory->create(
110+
\Magento\Framework\Mview\View\ChangeLogBatchWalker::class // @phpstan-ignore-line
111+
);
112+
}
113+
$changelogWalkerFactory = $this->objectManager->create(
114+
\Magento\Framework\Mview\View\ChangelogBatchWalkerFactory::class // @phpstan-ignore-line
115+
);
116+
return $changelogWalkerFactory->create(
117+
\Magento\Framework\Mview\View\ChangelogBatchWalker::class // @phpstan-ignore-line
118+
);
119+
}
120+
101121
/**
102122
* Checks to run the catalog update plugin
103123
*

0 commit comments

Comments
 (0)