@@ -26,12 +26,6 @@ class ReplicaSyncCommand extends Command
26
26
27
27
protected ?OutputInterface $ output = null ;
28
28
29
- /**
30
- * @param ProductHelper $productHelper
31
- * @param ReplicaManagerInterface $replicaManager
32
- * @param StoreManagerInterface $storeManager
33
- * @param string|null $name
34
- */
35
29
public function __construct (
36
30
protected State $ state ,
37
31
protected ProductHelper $ productHelper ,
@@ -74,6 +68,9 @@ protected function configure(): void
74
68
*/
75
69
protected function execute (InputInterface $ input , OutputInterface $ output ): int
76
70
{
71
+ $ this ->output = $ output ;
72
+ $ this ->setAreaCode ();
73
+
77
74
$ storeIds = (array ) $ input ->getArgument (self ::STORE_ARGUMENT );
78
75
79
76
$ msg = 'Syncing replicas for ' . ($ storeIds ? count ($ storeIds ) : 'all ' ) . ' store ' . (!$ storeIds || count ($ storeIds ) > 1 ? 's ' : '' );
@@ -83,11 +80,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
83
80
$ output ->writeln ("<info> $ msg</info> " );
84
81
}
85
82
86
- $ this ->output = $ output ;
87
- $ this ->state ->setAreaCode (Area::AREA_ADMINHTML );
83
+
88
84
try {
89
85
$ this ->syncReplicas ($ storeIds );
90
- } catch (BadRequestException $ e ) {
86
+ } catch (BadRequestException ) {
91
87
$ this ->output ->writeln ('<comment>You appear to have a corrupted replica configuration in Algolia for your Magento instance.</comment> ' );
92
88
$ this ->output ->writeln ('<comment>Run the "algolia:replicas:rebuild" command to correct this.</comment> ' );
93
89
return CLI ::RETURN_FAILURE ;
@@ -100,6 +96,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
100
96
return Cli::RETURN_SUCCESS ;
101
97
}
102
98
99
+ protected function setAreaCode (): void {
100
+ try {
101
+ $ this ->state ->setAreaCode (Area::AREA_CRONTAB );
102
+ } catch (LocalizedException ) {
103
+ // Area code is already set - nothing to do
104
+ }
105
+ }
106
+
103
107
/**
104
108
* @param int[] $storeIds
105
109
* @return void
0 commit comments