Skip to content

Commit cb042f7

Browse files
committed
MAGE-1113 Prep refactored CLI for inclusion and add confirmation step
1 parent 5e3faec commit cb042f7

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

Console/Command/SynonymDeduplicateCommand.php

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
use Magento\Framework\App\State;
99
use Magento\Framework\Console\Cli;
1010
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Magento\Store\Model\StoreManagerInterface;
1112
use Symfony\Component\Console\Input\InputInterface;
1213
use Symfony\Component\Console\Output\OutputInterface;
1314

1415
class SynonymDeduplicateCommand extends AbstractStoreCommand
1516
{
1617
public function __construct(
17-
protected AlgoliaHelper $algoliaHelper,
18-
protected IndexNameFetcher $indexNameFetcher,
19-
protected State $state,
20-
protected StoreNameFetcher $storeNameFetcher,
21-
?string $name = null
18+
protected AlgoliaHelper $algoliaHelper,
19+
protected IndexNameFetcher $indexNameFetcher,
20+
protected State $state,
21+
protected StoreNameFetcher $storeNameFetcher,
22+
protected StoreManagerInterface $storeManager,
23+
?string $name = null
2224
) {
2325
parent::__construct($state, $storeNameFetcher, $name);
2426
}
@@ -53,9 +55,14 @@ protected function getAdditionalDefinition(): array
5355
*/
5456
protected function execute(InputInterface $input, OutputInterface $output): int
5557
{
58+
$this->input = $input;
5659
$this->output = $output;
5760
$this->setAreaCode();
5861

62+
if (!$this->confirmDedupeOperation()) {
63+
return Cli::RETURN_SUCCESS;
64+
}
65+
5966
$storeIds = $this->getStoreIds($input);
6067

6168
$output->writeln($this->decorateOperationAnnouncementMessage('Deduplicating synonyms for {{target}}', $storeIds));
@@ -70,6 +77,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7077
return Cli::RETURN_SUCCESS;
7178
}
7279

80+
/**
81+
* Due to limitations in PHP API client at the time of this implementation, one way synonyms cannot be processed
82+
* and will be removed completely
83+
* Verify with the end user first!
84+
*
85+
* @return bool
86+
*/
87+
protected function confirmDedupeOperation(): bool
88+
{
89+
$this->output->writeln('<fg=red>This deduplicate process cannot handle one way synonyms and will remove them altogether!</fg=red>');
90+
return $this->confirmOperation();
91+
}
92+
7393
/**
7494
* @throws NoSuchEntityException
7595
*/
@@ -80,7 +100,7 @@ public function dedupeSynonyms(array $storeIds = []): void
80100
$this->dedupeSynonymsForStore($storeId);
81101
}
82102
} else {
83-
// handle all
103+
$this->dedupeSynonymsForAllStores();
84104
}
85105
}
86106

@@ -106,6 +126,17 @@ public function dedupeSynonymsForStore(int $storeId): void
106126
$this->algoliaHelper->waitLastTask($indexName);
107127
}
108128

129+
/**
130+
* @throws NoSuchEntityException
131+
*/
132+
public function dedupeSynonymsForAllStores(): void
133+
{
134+
$storeIds = array_keys($this->storeManager->getStores());
135+
foreach ($storeIds as $storeId) {
136+
$this->dedupeSynonymsForStore($storeId);
137+
}
138+
}
139+
109140
/**
110141
* @param string[] $settingNames
111142
* @param array<string, array> $settings

0 commit comments

Comments
 (0)