Reindex::startMigration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
namespace Triadev\EsMigration\Business\Migration;
3
4
use Elasticsearch\Client;
5
6
class Reindex extends AbstractMigration
7
{
8
    /**
9
     * Get validation rules
10
     *
11
     * @return array
12
     */
13 3
    public function getValidationRules(): array
14
    {
15
        return [
16 3
            'body' => 'required|array',
17
            'body.source.index' => 'required|string',
18
            'body.dest.index' => 'required|string'
19
        ];
20
    }
21
    
22
    /**
23
     * Pre check
24
     *
25
     * @param Client $esClient
26
     * @param array $params
27
     *
28
     * @throws \Exception
29
     */
30 2
    public function preCheck(Client $esClient, array $params)
31
    {
32 2
        $indices = implode(',', [
33 2
            array_get($params, 'body.source.index'),
34 2
            array_get($params, 'body.dest.index')
35
        ]);
36
        
37 2
        if (!$esClient->indices()->exists(['index' => $indices])) {
38 1
            throw new \Exception(sprintf("Index not exist: %s", $indices));
39
        }
40 1
    }
41
    
42
    /**
43
     * Start migration
44
     *
45
     * @param Client $esClient
46
     * @param array $params
47
     */
48 1
    public function startMigration(Client $esClient, array $params)
49
    {
50 1
        $esClient->reindex($params);
51 1
    }
52
    
53
    /**
54
     * Post check
55
     *
56
     * @param Client $esClient
57
     * @param array $params
58
     *
59
     * @throws \Exception
60
     */
61 1
    public function postCheck(Client $esClient, array $params)
62
    {
63
        // TODO: Implement postCheck() method.
64 1
    }
65
}
66