-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathTypeToNewIndex.php
More file actions
69 lines (55 loc) · 2.19 KB
/
Copy pathTypeToNewIndex.php
File metadata and controls
69 lines (55 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php declare(strict_types = 1);
namespace Spameri\Elastic\Commands;
class TypeToNewIndex extends \Symfony\Component\Console\Command\Command
{
/**
* @var string
*/
protected static $defaultName = 'spameri:elastic:move-type';
public function __construct(
private readonly \Spameri\Elastic\Model\TypeToNewIndex\Migrate $migrate,
)
{
parent::__construct(null);
}
/**
* @example spameri:elastic:move-type oldIndex productType newIndex newIndexAlias -c
*/
protected function configure(): void
{
$this
->setName(self::$defaultName)
->setDescription('Move type to new index to separate data and prepare for deprecation of types is ES.')
->addArgument('indexFrom', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
->addArgument('typeFrom', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
->addArgument('indexTo', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
->addArgument('aliasTo', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
->addArgument('typeTo', \Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Use only on old ElasticSearch', null)
->addOption(
'allowClose', 'c', \Symfony\Component\Console\Input\InputOption::VALUE_OPTIONAL,
'Allows command to close index for data transfer. After data is transferred index is opened and resumes normal operations. When open it needs to check changed files after move and sync remaining.',
true,
)
;
}
/**
* @throws \Elastic\Elasticsearch\Exception\ElasticsearchException
*/
protected function execute(
\Symfony\Component\Console\Input\InputInterface $input,
\Symfony\Component\Console\Output\OutputInterface $output,
): int
{
$output->writeln('Starting');
$indexFrom = $input->getArgument('indexFrom');
$typeFrom = $input->getArgument('typeFrom');
$indexTo = $input->getArgument('indexTo');
$aliasTo = $input->getArgument('aliasTo');
$typeTo = $input->getOption('typeTo');
$allowClose = $input->getOption('allowClose');
$this->migrate->setOutput($output);
$this->migrate->execute((string) $indexFrom, (string) $typeFrom, (string) $indexTo, (string) $aliasTo, (string) $typeTo, (bool) $allowClose);
$output->writeln('Done');
return 0;
}
}