|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nord\Lumen\Elasticsearch\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use League\Pipeline\Pipeline; |
|
7
|
|
|
use Nord\Lumen\Elasticsearch\Contracts\ElasticsearchServiceContract; |
|
8
|
|
|
use Nord\Lumen\Elasticsearch\Exceptions\IndexExistsException; |
|
9
|
|
|
use Nord\Lumen\Elasticsearch\Pipelines\Payloads\ApplyMigrationPayload; |
|
10
|
|
|
use Nord\Lumen\Elasticsearch\Pipelines\Stages\CheckIndexExistsStage; |
|
11
|
|
|
use Nord\Lumen\Elasticsearch\Pipelines\Stages\CreateIndexStage; |
|
12
|
|
|
use Nord\Lumen\Elasticsearch\Pipelines\Stages\DetermineTargetVersionStage; |
|
13
|
|
|
use Nord\Lumen\Elasticsearch\Pipelines\Stages\UpdateIndexAliasStage; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class ApplyMigrationCommand |
|
17
|
|
|
* @package Nord\Lumen\Elasticsearch\Commands\Migrations |
|
18
|
|
|
*/ |
|
19
|
|
|
class ApplyMigrationCommand extends Command |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $signature = 'search:migrations:migrate {config : The path to the index configuration file}'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The console command description. |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $description = 'Migrates the specified index to a new index using the newest configuration version'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var ElasticsearchServiceContract |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $elasticsearchService; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* AbstractMigrationCommand constructor. |
|
41
|
|
|
* |
|
42
|
|
|
* @param ElasticsearchServiceContract $elasticsearchService |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct(ElasticsearchServiceContract $elasticsearchService) |
|
45
|
|
|
{ |
|
46
|
|
|
parent::__construct(); |
|
47
|
|
|
|
|
48
|
|
|
$this->elasticsearchService = $elasticsearchService; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @inheritDoc |
|
53
|
|
|
*/ |
|
54
|
|
|
public function handle() |
|
55
|
|
|
{ |
|
56
|
|
|
$configurationPath = $this->argument('config'); |
|
57
|
|
|
|
|
58
|
|
|
$pipeline = new Pipeline([ |
|
59
|
|
|
new DetermineTargetVersionStage(), |
|
60
|
|
|
new CheckIndexExistsStage($this->elasticsearchService), |
|
61
|
|
|
new CreateIndexStage($this->elasticsearchService), |
|
62
|
|
|
new UpdateIndexAliasStage($this->elasticsearchService), |
|
63
|
|
|
]); |
|
64
|
|
|
|
|
65
|
|
|
$payload = new ApplyMigrationPayload($configurationPath); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
try { |
|
68
|
|
|
$pipeline->process($payload); |
|
69
|
|
|
|
|
70
|
|
|
$this->output->writeln(sprintf('Migrated %s to %s', $payload->getIndexName(), |
|
71
|
|
|
$payload->getTargetVersionName())); |
|
72
|
|
|
} catch (IndexExistsException $e) { |
|
73
|
|
|
$this->output->writeln('No migration required'); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|