|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Algolia\AlgoliaSearch\Console\Command; |
| 4 | + |
| 5 | +use Magento\Framework\Console\Cli; |
| 6 | +use Magento\Framework\Exception\NoSuchEntityException; |
| 7 | +use Symfony\Component\Console\Input\InputInterface; |
| 8 | +use Symfony\Component\Console\Output\OutputInterface; |
| 9 | + |
| 10 | +class SynonymDeduplicateCommand extends AbstractStoreCommand |
| 11 | +{ |
| 12 | + protected function getCommandPrefix(): string |
| 13 | + { |
| 14 | + return parent::getCommandPrefix() . 'synonyms:'; |
| 15 | + } |
| 16 | + |
| 17 | + protected function getCommandName(): string |
| 18 | + { |
| 19 | + return 'deduplicate'; |
| 20 | + } |
| 21 | + |
| 22 | + protected function getCommandDescription(): string |
| 23 | + { |
| 24 | + return "Identify and remove duplicate synonyms in Algolia"; |
| 25 | + } |
| 26 | + |
| 27 | + protected function getStoreArgumentDescription(): string |
| 28 | + { |
| 29 | + return 'ID(s) for store(s) containing synonyms to deduplicate in Algolia (optional), if not specified, synonyms for all stores will be deduplicated'; |
| 30 | + } |
| 31 | + |
| 32 | + protected function getAdditionalDefinition(): array |
| 33 | + { |
| 34 | + return []; |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @throws NoSuchEntityException |
| 39 | + */ |
| 40 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 41 | + { |
| 42 | + $this->output = $output; |
| 43 | + $this->setAreaCode(); |
| 44 | + |
| 45 | + $storeIds = $this->getStoreIds($input); |
| 46 | + |
| 47 | + $output->writeln($this->decorateOperationAnnouncementMessage('Deduplicating synonyms for {{target}}', $storeIds)); |
| 48 | + |
| 49 | + try { |
| 50 | + $this->dedupeSynonyms($storeIds); |
| 51 | + } catch (\Exception $e) { |
| 52 | + $this->output->writeln('<error>' . $e->getMessage() . '</error>'); |
| 53 | + return CLI::RETURN_FAILURE; |
| 54 | + } |
| 55 | + |
| 56 | + return Cli::RETURN_SUCCESS; |
| 57 | + } |
| 58 | + |
| 59 | + public function dedupeSynonyms(array $storeIds = []): void |
| 60 | + { |
| 61 | + if (count($storeIds)) { |
| 62 | + foreach ($storeIds as $storeId) { |
| 63 | + $this->dedupeSynonymsForStore($storeId); |
| 64 | + } |
| 65 | + } else { |
| 66 | + // handle all |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + public function dedupeSynonymsForStore(int $storeId): void |
| 71 | + { |
| 72 | + $this->output->writeln('<info>Deduplicating synonyms for ' . $this->storeNameFetcher->getStoreName($storeId) . '...</info>'); |
| 73 | + } |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +} |
0 commit comments