Recovery.php 1.8 KB

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