Skip to content

Commit 733a460

Browse files
committed
MAGE-848 Centralize standard confirm operation prompt
1 parent 57f8ab7 commit 733a460

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

Console/Command/AbstractReplicaCommand.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Symfony\Component\Console\Input\InputArgument;
1111
use Symfony\Component\Console\Input\InputInterface;
1212
use Symfony\Component\Console\Output\OutputInterface;
13+
use Symfony\Component\Console\Question\ConfirmationQuestion;
1314

1415
abstract class AbstractReplicaCommand extends Command
1516
{
@@ -103,4 +104,21 @@ protected function decorateOperationAnnouncementMessage(string $msg, array $stor
103104
? "<info>$msg: " . join(", ", $this->storeNameFetcher->getStoreNames($storeIds)) . '</info>'
104105
: "<info>$msg</info>";
105106
}
107+
108+
protected function confirmOperation(string $okMessage = '', string $cancelMessage = 'Operation cancelled'): bool
109+
{
110+
$helper = $this->getHelper('question');
111+
$question = new ConfirmationQuestion('<question>Are you sure wish to proceed? (y/n)</question> ', false);
112+
if (!$helper->ask($this->input, $this->output, $question)) {
113+
if ($cancelMessage) {
114+
$this->output->writeln("<comment>$cancelMessage</comment>");
115+
}
116+
return false;
117+
}
118+
119+
if ($okMessage) {
120+
$this->output->writeln("<comment>$okMessage</comment>");
121+
}
122+
return true;
123+
}
106124
}

Console/Command/ReplicaDeleteCommand.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,10 @@ protected function confirmDeleteUnused(array $unusedReplicas): bool
143143
return true;
144144
}
145145

146-
147146
protected function confirmDelete(): bool
148147
{
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;
148+
$okMsg = 'Please note that you can restore these deleted replicas by running "algolia:replicas:sync".';
149+
return $this->confirmOperation($okMsg);
158150
}
159151

160152
}

Console/Command/ReplicaDisableVirtualCommand.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4343

4444
$output->writeln($this->decorateOperationAnnouncementMessage('Disabling virtual replicas for {{target}}', $storeIds));
4545

46-
if (!$this->confirmOperation()) {
46+
$okMsg = 'Configure virtual replicas by attribute under: Stores > Configuration > Algolia Search > InstantSearch Results Page > Sorting';
47+
if (!$this->confirmOperation($okMsg)) {
4748
return CLI::RETURN_SUCCESS;
4849
}
4950

5051
return Cli::RETURN_SUCCESS;
5152
}
5253

53-
protected function confirmOperation(): bool
54-
{
55-
$helper = $this->getHelper('question');
56-
$question = new ConfirmationQuestion('<question>Are you sure wish to proceed? (y/n)</question> ', false);
57-
if (!$helper->ask($this->input, $this->output, $question)) {
58-
$this->output->writeln('<comment>Operation cancelled.</comment>');
59-
return false;
60-
}
61-
62-
$this->output->writeln('<comment>Configure virtual replicas by attribute under: Stores > Configuration > Algolia Search > InstantSearch Results Page > Sorting</comment>');
63-
return true;
64-
}
6554
}

0 commit comments

Comments
 (0)