Completed
Push — develop ( bdcd74...c796db )
by Sam
13s
created

StoreIndexSettingsStage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace Nord\Lumen\Elasticsearch\Pipelines\Stages;
4
5
use League\Pipeline\StageInterface;
6
use Nord\Lumen\Elasticsearch\Contracts\ElasticsearchServiceContract;
7
use Nord\Lumen\Elasticsearch\Pipelines\Payloads\ApplyMigrationPayload;
8
9
/**
10
 * Class StoreIndexSettingsStage
11
 * @package Nord\Lumen\Elasticsearch\Pipelines\Stages
12
 */
13
class StoreIndexSettingsStage implements StageInterface
14
{
15
16
    /**
17
     * @var ElasticsearchServiceContract
18
     */
19
    private $elasticsearchService;
20
21
    /**
22
     * CheckIndexExistsStage constructor.
23
     *
24
     * @param ElasticsearchServiceContract $elasticsearchService
25
     */
26
    public function __construct(ElasticsearchServiceContract $elasticsearchService)
27
    {
28
        $this->elasticsearchService = $elasticsearchService;
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function __invoke($payload)
35
    {
36
        /** @var ApplyMigrationPayload $payload */
37
38
        // Store the current number_of_replicas setting value in the payload
39
        $settings = $this->elasticsearchService->indices()->getSettings([
40
            'index' => $payload->getTargetVersionName(),
41
        ]);
42
43
        $indexSettings = $settings[$payload->getTargetVersionName()]['settings']['index'];
44
        $payload->setNumberOfReplicas($indexSettings['number_of_replicas']);
45
46
        return $payload;
47
    }
48
}
49