Completed
Pull Request — develop (#128)
by Sam
07:13
created

getPrefixedTargetVersionName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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
        $configuration = $this->getTargetConfiguration();
85
86
        return IndexNamePrefixer::getPrefixedIndexParameters($configuration);
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getTargetVersionName()
93
    {
94
        return $this->getTargetConfiguration()['index'];
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function getPrefixedTargetVersionName(): string
101
    {
102
        return IndexNamePrefixer::getPrefixedIndexName($this->getTargetVersionName());
103
    }
104
105
    /**
106
     * @return int
107
     */
108
    public function getBatchSize()
109
    {
110
        return $this->batchSize;
111
    }
112
113
    /**
114
     * @return int
115
     */
116
    public function getNumberOfReplicas()
117
    {
118
        return $this->numberOfReplicas;
119
    }
120
121
    /**
122
     * @param int $numberOfReplicas
123
     */
124
    public function setNumberOfReplicas($numberOfReplicas)
125
    {
126
        $this->numberOfReplicas = $numberOfReplicas;
127
    }
128
}
129