8
8
use Magento \Framework \App \State ;
9
9
use Magento \Framework \Console \Cli ;
10
10
use Magento \Framework \Exception \NoSuchEntityException ;
11
+ use Magento \Store \Model \StoreManagerInterface ;
11
12
use Symfony \Component \Console \Input \InputInterface ;
12
13
use Symfony \Component \Console \Output \OutputInterface ;
13
14
14
15
class SynonymDeduplicateCommand extends AbstractStoreCommand
15
16
{
16
17
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
22
24
) {
23
25
parent ::__construct ($ state , $ storeNameFetcher , $ name );
24
26
}
@@ -53,9 +55,14 @@ protected function getAdditionalDefinition(): array
53
55
*/
54
56
protected function execute (InputInterface $ input , OutputInterface $ output ): int
55
57
{
58
+ $ this ->input = $ input ;
56
59
$ this ->output = $ output ;
57
60
$ this ->setAreaCode ();
58
61
62
+ if (!$ this ->confirmDedupeOperation ()) {
63
+ return Cli::RETURN_SUCCESS ;
64
+ }
65
+
59
66
$ storeIds = $ this ->getStoreIds ($ input );
60
67
61
68
$ output ->writeln ($ this ->decorateOperationAnnouncementMessage ('Deduplicating synonyms for {{target}} ' , $ storeIds ));
@@ -70,6 +77,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
70
77
return Cli::RETURN_SUCCESS ;
71
78
}
72
79
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
+
73
93
/**
74
94
* @throws NoSuchEntityException
75
95
*/
@@ -80,7 +100,7 @@ public function dedupeSynonyms(array $storeIds = []): void
80
100
$ this ->dedupeSynonymsForStore ($ storeId );
81
101
}
82
102
} else {
83
- // handle all
103
+ $ this -> dedupeSynonymsForAllStores ();
84
104
}
85
105
}
86
106
@@ -106,6 +126,17 @@ public function dedupeSynonymsForStore(int $storeId): void
106
126
$ this ->algoliaHelper ->waitLastTask ($ indexName );
107
127
}
108
128
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
+
109
140
/**
110
141
* @param string[] $settingNames
111
142
* @param array<string, array> $settings
0 commit comments