|
| 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 | +} |
0 commit comments