Restore.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace Elasticsearch\Endpoints\Snapshot;
  3. use Elasticsearch\Endpoints\AbstractEndpoint;
  4. use Elasticsearch\Common\Exceptions;
  5. /**
  6. * Class Restore
  7. *
  8. * @category Elasticsearch
  9. * @package Elasticsearch\Endpoints\Snapshot
  10. * @author Zachary Tong <zach@elastic.co>
  11. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
  12. * @link http://elastic.co
  13. */
  14. class Restore extends AbstractEndpoint
  15. {
  16. // A repository name
  17. private $repository;
  18. // A snapshot name
  19. private $snapshot;
  20. /**
  21. * @param array $body
  22. *
  23. * @return $this
  24. */
  25. public function setBody($body)
  26. {
  27. if (isset($body) !== true) {
  28. return $this;
  29. }
  30. $this->body = $body;
  31. return $this;
  32. }
  33. /**
  34. * @param $repository
  35. *
  36. * @return $this
  37. */
  38. public function setRepository($repository)
  39. {
  40. if (isset($repository) !== true) {
  41. return $this;
  42. }
  43. $this->repository = $repository;
  44. return $this;
  45. }
  46. /**
  47. * @param $snapshot
  48. *
  49. * @return $this
  50. */
  51. public function setSnapshot($snapshot)
  52. {
  53. if (isset($snapshot) !== true) {
  54. return $this;
  55. }
  56. $this->snapshot = $snapshot;
  57. return $this;
  58. }
  59. /**
  60. * @throws \Elasticsearch\Common\Exceptions\RuntimeException
  61. * @return string
  62. */
  63. public function getURI()
  64. {
  65. if (isset($this->repository) !== true) {
  66. throw new Exceptions\RuntimeException(
  67. 'repository is required for Restore'
  68. );
  69. }
  70. if (isset($this->snapshot) !== true) {
  71. throw new Exceptions\RuntimeException(
  72. 'snapshot is required for Restore'
  73. );
  74. }
  75. $repository = $this->repository;
  76. $snapshot = $this->snapshot;
  77. $uri = "/_snapshot/$repository/$snapshot/_restore";
  78. if (isset($repository) === true && isset($snapshot) === true) {
  79. $uri = "/_snapshot/$repository/$snapshot/_restore";
  80. }
  81. return $uri;
  82. }
  83. /**
  84. * @return string[]
  85. */
  86. public function getParamWhitelist()
  87. {
  88. return array(
  89. 'master_timeout',
  90. 'wait_for_completion',
  91. );
  92. }
  93. /**
  94. * @return string
  95. */
  96. public function getMethod()
  97. {
  98. return 'POST';
  99. }
  100. }