Skip to content

Commit 57f8ab7

Browse files
committed
MAGE-848 Add stub for disable virtual replica CLI
1 parent c1fd8ab commit 57f8ab7

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Console\Command;
4+
5+
use Algolia\AlgoliaSearch\Api\Console\ReplicaSyncCommandInterface;
6+
use Algolia\AlgoliaSearch\Console\Traits\ReplicaSyncCommandTrait;
7+
use Magento\Framework\Console\Cli;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
use Symfony\Component\Console\Question\ConfirmationQuestion;
11+
12+
class ReplicaDisableVirtualCommand extends AbstractReplicaCommand implements ReplicaSyncCommandInterface
13+
{
14+
use ReplicaSyncCommandTrait;
15+
16+
protected function getReplicaCommandName(): string
17+
{
18+
return 'disable-virtual-replicas';
19+
}
20+
21+
protected function getCommandDescription(): string
22+
{
23+
return 'Disable virtual replicas for all product sorting attributes and revert to standard replicas';
24+
}
25+
26+
protected function getStoreArgumentDescription(): string
27+
{
28+
return 'ID(s) for store(s) to disable virtual replicas (optional), if not specified disable virtual replicas for all stores';
29+
}
30+
31+
protected function getAdditionalDefinition(): array
32+
{
33+
return [];
34+
}
35+
36+
protected function execute(InputInterface $input, OutputInterface $output): int
37+
{
38+
$this->output = $output;
39+
$this->input = $input;
40+
$this->setAreaCode();
41+
42+
$storeIds = $this->getStoreIds($input);
43+
44+
$output->writeln($this->decorateOperationAnnouncementMessage('Disabling virtual replicas for {{target}}', $storeIds));
45+
46+
if (!$this->confirmOperation()) {
47+
return CLI::RETURN_SUCCESS;
48+
}
49+
50+
return Cli::RETURN_SUCCESS;
51+
}
52+
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+
}
65+
}

etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
<item name="replica_sync_command" xsi:type="object">Algolia\AlgoliaSearch\Console\Command\ReplicaSyncCommand</item>
151151
<item name="replica_delete_command" xsi:type="object">Algolia\AlgoliaSearch\Console\Command\ReplicaDeleteCommand</item>
152152
<item name="replica_rebuild_command" xsi:type="object">Algolia\AlgoliaSearch\Console\Command\ReplicaRebuildCommand</item>
153+
<item name="replica_disable_virtual_command" xsi:type="object">Algolia\AlgoliaSearch\Console\Command\ReplicaDisableVirtualCommand</item>
153154
</argument>
154155
</arguments>
155156
</type>

0 commit comments

Comments
 (0)