1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nord\Lumen\Elasticsearch\Pipelines\Payloads; |
4
|
|
|
|
5
|
|
|
use Nord\Lumen\Elasticsearch\IndexNamePrefixer; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class ApplyMigrationPayload |
9
|
|
|
* @package Nord\Lumen\Elasticsearch\Pipelines\Payloads |
10
|
|
|
*/ |
11
|
|
|
class ApplyMigrationPayload extends MigrationPayload |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $targetVersionFile; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var int |
21
|
|
|
*/ |
22
|
|
|
private $batchSize; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
private $updateAllTypes; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var int |
31
|
|
|
*/ |
32
|
|
|
private $numberOfReplicas; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* ApplyMigrationPayload constructor. |
36
|
|
|
* |
37
|
|
|
* @param string $configurationPath |
38
|
|
|
* @param int $batchSize |
39
|
|
|
* @param bool $updateAllTypes |
40
|
|
|
*/ |
41
|
|
|
public function __construct($configurationPath, $batchSize, $updateAllTypes = false) |
42
|
|
|
{ |
43
|
|
|
parent::__construct($configurationPath); |
44
|
|
|
|
45
|
|
|
$this->batchSize = $batchSize; |
46
|
|
|
$this->updateAllTypes = $updateAllTypes; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $targetVersionFile |
51
|
|
|
*/ |
52
|
|
|
public function setTargetVersionFile($targetVersionFile) |
53
|
|
|
{ |
54
|
|
|
$this->targetVersionFile = $targetVersionFile; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getTargetVersionPath() |
61
|
|
|
{ |
62
|
|
|
return sprintf('%s/%s', $this->getIndexVersionsPath(), $this->targetVersionFile); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
public function getTargetConfiguration() |
69
|
|
|
{ |
70
|
|
|
$config = include $this->getTargetVersionPath(); |
71
|
|
|
|
72
|
|
|
if ($this->updateAllTypes) { |
73
|
|
|
$config['update_all_types'] = true; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $config; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return array |
81
|
|
|
*/ |
82
|
|
|
public function getPrefixedTargetConfiguration(): array |
83
|
|
|
{ |
84
|
|
|
return IndexNamePrefixer::getPrefixedIndexParameters($this->getTargetConfiguration()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function getTargetVersionName() |
91
|
|
|
{ |
92
|
|
|
return $this->getTargetConfiguration()['index']; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function getPrefixedTargetVersionName(): string |
99
|
|
|
{ |
100
|
|
|
return IndexNamePrefixer::getPrefixedIndexName($this->getTargetVersionName()); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return int |
105
|
|
|
*/ |
106
|
|
|
public function getBatchSize() |
107
|
|
|
{ |
108
|
|
|
return $this->batchSize; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return int |
113
|
|
|
*/ |
114
|
|
|
public function getNumberOfReplicas() |
115
|
|
|
{ |
116
|
|
|
return $this->numberOfReplicas; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param int $numberOfReplicas |
121
|
|
|
*/ |
122
|
|
|
public function setNumberOfReplicas($numberOfReplicas) |
123
|
|
|
{ |
124
|
|
|
$this->numberOfReplicas = $numberOfReplicas; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|