6
6
use Algolia \AlgoliaSearch \Exceptions \AlgoliaException ;
7
7
use Algolia \AlgoliaSearch \Exceptions \BadRequestException ;
8
8
use Algolia \AlgoliaSearch \Service \StoreNameFetcher ;
9
+ use Magento \Framework \App \State ;
9
10
use Magento \Framework \Console \Cli ;
10
11
use Magento \Framework \Exception \LocalizedException ;
11
12
use Magento \Framework \Exception \NoSuchEntityException ;
12
13
use Magento \Store \Model \StoreManagerInterface ;
13
- use Symfony \Component \Console \Command \Command ;
14
- use Symfony \Component \Console \Input \InputArgument ;
15
14
use Symfony \Component \Console \Input \InputInterface ;
16
15
use Symfony \Component \Console \Input \InputOption ;
17
16
use Symfony \Component \Console \Output \OutputInterface ;
18
17
use Symfony \Component \Console \Question \ConfirmationQuestion ;
19
18
20
- class ReplicaDeleteCommand extends Command
19
+ class ReplicaDeleteCommand extends AbstractReplicaCommand
21
20
{
22
21
protected const STORE_ARGUMENT = 'store ' ;
23
22
@@ -31,36 +30,41 @@ public function __construct(
31
30
protected ReplicaManagerInterface $ replicaManager ,
32
31
protected StoreManagerInterface $ storeManager ,
33
32
protected StoreNameFetcher $ storeNameFetcher ,
33
+ protected State $ state ,
34
34
?string $ name = null
35
35
)
36
36
{
37
- parent ::__construct ($ name );
37
+ parent ::__construct ($ state , $ name );
38
38
}
39
39
40
- /**
41
- * @inheritDoc
42
- */
43
- protected function configure (): void
40
+ protected function getReplicaCommandName (): string
41
+ {
42
+ return 'delete ' ;
43
+ }
44
+
45
+ protected function getCommandDescription (): string
46
+ {
47
+ return 'Delete associated replica indices in Algolia ' ;
48
+ }
49
+
50
+ protected function getStoreArgumentDescription (): string
51
+ {
52
+ return 'ID(s) for store(s) to delete replicas in Algolia (optional), if not specified, replicas for all stores will be deleted ' ;
53
+ }
54
+
55
+ protected function getAdditionalDefinition (): array
44
56
{
45
- $ this ->setName ('algolia:replicas:delete ' )
46
- ->setDescription ('Delete associated replica indices in Algolia ' )
47
- ->setDefinition ([
48
- new InputArgument (
49
- self ::STORE_ARGUMENT ,
50
- InputArgument::OPTIONAL | InputArgument::IS_ARRAY ,
51
- 'ID(s) for store(s) to delete replicas in Algolia (optional), if not specified, replicas for all stores will be deleted '
52
- ),
53
- new InputOption (
54
- self ::UNUSED_OPTION ,
55
- '- ' . self ::UNUSED_OPTION_SHORTCUT ,
56
- InputOption::VALUE_NONE ,
57
- 'Delete unused replicas only '
58
- )
59
- ]);
60
-
61
- parent ::configure ();
57
+ return [
58
+ new InputOption (
59
+ self ::UNUSED_OPTION ,
60
+ '- ' . self ::UNUSED_OPTION_SHORTCUT ,
61
+ InputOption::VALUE_NONE ,
62
+ 'Delete unused replicas only '
63
+ )
64
+ ];
62
65
}
63
66
67
+
64
68
protected function execute (InputInterface $ input , OutputInterface $ output ): int
65
69
{
66
70
$ this ->output = $ output ;
@@ -69,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
69
73
$ storeIds = (array ) $ input ->getArgument (self ::STORE_ARGUMENT );
70
74
$ unused = $ input ->getOption (self ::UNUSED_OPTION );
71
75
72
- $ msg = 'Deleting ' . ($ unused ? ' unused ' : ' ' ) . 'replicas for ' . ($ storeIds ? count ($ storeIds ) : 'all ' ) . ' store ' . (!$ storeIds || count ($ storeIds ) > 1 ? 's ' : '' );
76
+ $ msg = 'Deleting ' . ($ unused ? ' unused ' : ' ' ) . 'replicas for ' . ($ storeIds ? count ($ storeIds ) : 'all ' ) . ' store ' . (!$ storeIds || count ($ storeIds ) > 1 ? 's ' : '' );
73
77
if ($ storeIds ) {
74
78
$ output ->writeln ("<info> $ msg: " . join (", " , $ this ->storeNameFetcher ->getStoreNames ($ storeIds )) . '</info> ' );
75
79
} else {
@@ -103,7 +107,7 @@ protected function getUnusedReplicas(array $storeIds): array
103
107
{
104
108
return array_reduce (
105
109
$ storeIds ,
106
- function ($ allUnused , $ storeId ) {
110
+ function ($ allUnused , $ storeId ) {
107
111
$ unused = [];
108
112
try {
109
113
$ unused = $ this ->replicaManager ->getUnusedReplicaIndices ($ storeId );
@@ -162,7 +166,7 @@ protected function deleteReplicas(array $storeIds = [], bool $unused = false): v
162
166
*/
163
167
protected function deleteReplicasForStore (int $ storeId , bool $ unused = false ): void
164
168
{
165
- $ this ->output ->writeln ('<info>Deleting ' . ($ unused ? ' unused ' : ' ' ) . 'replicas for ' . $ this ->storeNameFetcher ->getStoreName ($ storeId ) . '...</info> ' );
169
+ $ this ->output ->writeln ('<info>Deleting ' . ($ unused ? ' unused ' : ' ' ) . 'replicas for ' . $ this ->storeNameFetcher ->getStoreName ($ storeId ) . '...</info> ' );
166
170
$ this ->replicaManager ->deleteReplicasFromAlgolia ($ storeId , $ unused );
167
171
}
168
172
0 commit comments