Skip to content

Commit 68bdc43

Browse files
committed
MAGE-938 Updates per code review
1 parent 99dcf69 commit 68bdc43

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

Console/Command/ReplicaDeleteCommand.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7575
$output->writeln("<info>$msg</info>");
7676
}
7777

78-
7978
if ($unused) {
8079
$unusedReplicas = $this->getUnusedReplicas($storeIds);
8180
if (!$unusedReplicas) {
@@ -85,6 +84,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8584
if (!$this->confirmDeleteUnused($unusedReplicas)) {
8685
return Cli::RETURN_SUCCESS;
8786
}
87+
} else if (!$this->confirmDelete()) {
88+
return Cli::RETURN_SUCCESS;
8889
}
8990

9091
try {
@@ -98,6 +99,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9899
return Cli::RETURN_SUCCESS;
99100
}
100101

102+
/**
103+
* @param int[] $storeIds
104+
* @return string[]
105+
*/
101106
protected function getUnusedReplicas(array $storeIds): array
102107
{
103108
return array_reduce(
@@ -119,7 +124,7 @@ function ($allUnused, $storeId) {
119124
* Deleting unused replica indices is potentially risky, especially if they have enabled query suggestions on their index
120125
* Verify with the end user first!
121126
*
122-
* @param array $unusedReplicas
127+
* @param string[] $unusedReplicas
123128
* @return bool
124129
*/
125130
protected function confirmDeleteUnused(array $unusedReplicas): bool
@@ -138,4 +143,18 @@ protected function confirmDeleteUnused(array $unusedReplicas): bool
138143
return true;
139144
}
140145

146+
147+
protected function confirmDelete(): bool
148+
{
149+
$helper = $this->getHelper('question');
150+
$question = new ConfirmationQuestion('<question>Are you sure wish to proceed? (y/n)</question> ', false);
151+
if (!$helper->ask($this->input, $this->output, $question)) {
152+
$this->output->writeln('<comment>Operation cancelled.</comment>');
153+
return false;
154+
}
155+
156+
$this->output->writeln('<comment>Please note that you can restore these deleted replicas by running "algolia:replicas:sync".</comment>');
157+
return true;
158+
}
159+
141160
}

Console/Command/ReplicaRebuildCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function getReplicaCommandName(): string
4141

4242
protected function getCommandDescription(): string
4343
{
44-
return 'Rebuild replica configuration for Magento sorting attributes';
44+
return "Delete and rebuild replica configuration for Magento sorting attributes (only run this operation if errors are encountered during regular sync)";
4545
}
4646

4747
protected function getStoreArgumentDescription(): string

Service/Product/ReplicaManager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ protected function isReplicaConfigurationValid(int $storeId): bool
302302
return true;
303303
}
304304

305+
/**
306+
* In the event of an invalid replica configuration, this provides the means to revert the
307+
* configuration settings to the previous state (provided the ReplicaState has been utilized to track the change)
308+
* @param int $storeId
309+
* @return bool True if settings were reverted as a result of this function call
310+
*/
305311
protected function revertReplicaConfig(int $storeId): bool
306312
{
307313
if ($ogConfig = $this->replicaState->getOriginalSortConfiguration($storeId)) {

0 commit comments

Comments
 (0)