diff options
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Snapshot.php')
-rw-r--r-- | vendor/ruflin/elastica/lib/Elastica/Snapshot.php | 101 |
1 files changed, 61 insertions, 40 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Snapshot.php b/vendor/ruflin/elastica/lib/Elastica/Snapshot.php index 4b32172c..80924b79 100644 --- a/vendor/ruflin/elastica/lib/Elastica/Snapshot.php +++ b/vendor/ruflin/elastica/lib/Elastica/Snapshot.php @@ -1,14 +1,13 @@ <?php - namespace Elastica; use Elastica\Exception\NotFoundException; use Elastica\Exception\ResponseException; /** - * Class Snapshot - * @package Elastica - * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/modules-snapshots.html + * Class Snapshot. + * + * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html */ class Snapshot { @@ -26,26 +25,32 @@ class Snapshot } /** - * Register a snapshot repository - * @param string $name the name of the repository - * @param string $type the repository type ("fs" for file system) - * @param array $settings Additional repository settings. If type "fs" is used, the "location" setting must be provided. + * Register a snapshot repository. + * + * @param string $name the name of the repository + * @param string $type the repository type ("fs" for file system) + * @param array $settings Additional repository settings. If type "fs" is used, the "location" setting must be provided. + * * @return Response */ public function registerRepository($name, $type, $settings = array()) { $data = array( 'type' => $type, - 'settings' => $settings + 'settings' => $settings, ); + return $this->request($name, Request::PUT, $data); } /** - * Retrieve a repository record by name + * Retrieve a repository record by name. + * * @param string $name the name of the desired repository + * * @throws Exception\ResponseException * @throws Exception\NotFoundException + * * @return array */ public function getRepository($name) @@ -54,102 +59,118 @@ class Snapshot $response = $this->request($name); } catch (ResponseException $e) { if ($e->getResponse()->getStatus() == 404) { - throw new NotFoundException("Repository '" . $name . "' does not exist."); + throw new NotFoundException("Repository '".$name."' does not exist."); } throw $e; } $data = $response->getData(); + return $data[$name]; } /** - * Retrieve all repository records + * Retrieve all repository records. + * * @return array */ public function getAllRepositories() { - return $this->request("_all")->getData(); + return $this->request('_all')->getData(); } /** - * Create a new snapshot - * @param string $repository the name of the repository in which this snapshot should be stored - * @param string $name the name of this snapshot - * @param array $options optional settings for this snapshot - * @param bool $waitForCompletion if true, the request will not return until the snapshot operation is complete + * Create a new snapshot. + * + * @param string $repository the name of the repository in which this snapshot should be stored + * @param string $name the name of this snapshot + * @param array $options optional settings for this snapshot + * @param bool $waitForCompletion if true, the request will not return until the snapshot operation is complete + * * @return Response */ public function createSnapshot($repository, $name, $options = array(), $waitForCompletion = false) { - return $this->request($repository . '/' . $name, Request::PUT, $options, array('wait_for_completion' => $waitForCompletion)); + return $this->request($repository.'/'.$name, Request::PUT, $options, array('wait_for_completion' => $waitForCompletion)); } /** - * Retrieve data regarding a specific snapshot + * Retrieve data regarding a specific snapshot. + * * @param string $repository the name of the repository from which to retrieve the snapshot - * @param string $name the name of the desired snapshot + * @param string $name the name of the desired snapshot + * * @throws Exception\ResponseException * @throws Exception\NotFoundException + * * @return array */ public function getSnapshot($repository, $name) { try { - $response = $this->request($repository . "/" . $name); + $response = $this->request($repository.'/'.$name); } catch (ResponseException $e) { if ($e->getResponse()->getStatus() == 404) { - throw new NotFoundException("Snapshot '" . $name . "' does not exist in repository '" . $repository . "'."); + throw new NotFoundException("Snapshot '".$name."' does not exist in repository '".$repository."'."); } throw $e; } $data = $response->getData(); + return $data['snapshots'][0]; } /** - * Retrieve data regarding all snapshots in the given repository + * Retrieve data regarding all snapshots in the given repository. + * * @param string $repository the repository name + * * @return array */ public function getAllSnapshots($repository) { - return $this->request($repository . "/_all")->getData(); + return $this->request($repository.'/_all')->getData(); } /** - * Delete a snapshot + * Delete a snapshot. + * * @param string $repository the repository in which the snapshot resides - * @param string $name the name of the snapshot to be deleted + * @param string $name the name of the snapshot to be deleted + * * @return Response */ public function deleteSnapshot($repository, $name) { - return $this->request($repository . "/" . $name, Request::DELETE); + return $this->request($repository.'/'.$name, Request::DELETE); } /** - * Restore a snapshot - * @param string $repository the name of the repository - * @param string $name the name of the snapshot - * @param array $options options for the restore operation - * @param bool $waitForCompletion if true, the request will not return until the restore operation is complete + * Restore a snapshot. + * + * @param string $repository the name of the repository + * @param string $name the name of the snapshot + * @param array $options options for the restore operation + * @param bool $waitForCompletion if true, the request will not return until the restore operation is complete + * * @return Response */ public function restoreSnapshot($repository, $name, $options = array(), $waitForCompletion = false) { - return $this->request($repository . "/" . $name . "/_restore", Request::POST, $options, array("wait_for_completion" => $waitForCompletion)); + return $this->request($repository.'/'.$name.'/_restore', Request::POST, $options, array('wait_for_completion' => $waitForCompletion)); } /** - * Perform a snapshot request - * @param string $path the URL + * Perform a snapshot request. + * + * @param string $path the URL * @param string $method the HTTP method - * @param array $data request body data - * @param array $query query string parameters + * @param array $data request body data + * @param array $query query string parameters + * * @return Response */ public function request($path, $method = Request::GET, $data = array(), array $query = array()) { - return $this->_client->request("/_snapshot/" . $path, $method, $data, $query); + return $this->_client->request('/_snapshot/'.$path, $method, $data, $query); } -}
\ No newline at end of file +} |