Completed
Push — master ( d45df9...7fc86e )
by Nicolas
02:28
created

Recovery::refresh()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Elastica\Index;
3
4
use Elastica\Index as BaseIndex;
5
6
/**
7
 * Elastica index recovery object.
8
 *
9
 * @author Federico Panini <[email protected]>
10
 *
11
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-recovery.html
12
 */
13
class Recovery
14
{
15
    /**
16
     * Response.
17
     *
18
     * @var \Elastica\Response Response object
19
     */
20
    protected $_response;
21
22
    /**
23
     * Recovery info.
24
     *
25
     * @var array Recovery info
26
     */
27
    protected $_data = [];
28
29
    /**
30
     * Index.
31
     *
32
     * @var \Elastica\Index Index object
33
     */
34
    protected $_index;
35
36
    /**
37
     * Construct.
38
     *
39
     * @param \Elastica\Index $index Index object
40
     */
41
    public function __construct(BaseIndex $index)
42
    {
43
        $this->_index = $index;
44
        $this->refresh();
45
    }
46
47
    /**
48
     * Returns the index object.
49
     *
50
     * @return \Elastica\Index Index object
51
     */
52
    public function getIndex()
53
    {
54
        return $this->_index;
55
    }
56
57
    /**
58
     * Returns response object.
59
     *
60
     * @return \Elastica\Response Response object
61
     */
62
    public function getResponse()
63
    {
64
        return $this->_response;
65
    }
66
67
    /**
68
     * Returns the raw recovery info.
69
     *
70
     * @return array Recovery info
71
     */
72
    public function getData()
73
    {
74
        return $this->_data;
75
    }
76
77
    /**
78
     * @return mixed
79
     */
80
    protected function getRecoveryData()
81
    {
82
        $endpoint = new \Elasticsearch\Endpoints\Indices\Recovery();
83
84
        $this->_response = $this->getIndex()->requestEndpoint($endpoint);
85
86
        return $this->getResponse()->getData();
87
    }
88
89
    /**
90
     * Retrieve the Recovery data
91
     *
92
     * @return $this
93
     */
94
    public function refresh()
95
    {
96
        $this->_data = $this->getRecoveryData();
97
98
        return $this;
99
    }
100
}