Skip to content

Commit 5cc9377

Browse files
committed
MAGE-1153 Stub synonym command class
1 parent 621fdfd commit 5cc9377

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
}

etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
<item name="replica_delete_command" xsi:type="object">Algolia\AlgoliaSearch\Console\Command\ReplicaDeleteCommand</item>
153153
<item name="replica_rebuild_command" xsi:type="object">Algolia\AlgoliaSearch\Console\Command\ReplicaRebuildCommand</item>
154154
<item name="replica_disable_virtual_command" xsi:type="object">Algolia\AlgoliaSearch\Console\Command\ReplicaDisableVirtualCommand</item>
155+
<item name="synonym_deduplicate_command" xsi:type="object">Algolia\AlgoliaSearch\Console\Command\SynonymDeduplicateCommand</item>
155156
</argument>
156157
</arguments>
157158
</type>

0 commit comments

Comments
 (0)