diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2012-09-28 12:59:52 +0200 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2012-09-28 12:59:52 +0200 |
| commit | 5f72df7e3f83ae30890a7996da025e68f6c70526 (patch) | |
| tree | a21b85a28f6635f612e78a91079a0e6c63d4faff /src | |
| parent | f259471294440e9c7463c8bf506f5967b2d67ec2 (diff) | |
| download | phorkie-5f72df7e3f83ae30890a7996da025e68f6c70526.tar.gz phorkie-5f72df7e3f83ae30890a7996da025e68f6c70526.zip | |
accept 404 errors when deleting repositories from elasticsearch
Diffstat (limited to 'src')
| -rw-r--r-- | src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php | 30 | ||||
| -rw-r--r-- | src/phorkie/Database/Adapter/Elasticsearch/Indexer.php | 4 |
2 files changed, 23 insertions, 11 deletions
diff --git a/src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php b/src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php index 2d74a4e..4cc02d6 100644 --- a/src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php +++ b/src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php @@ -3,22 +3,30 @@ namespace phorkie; class Database_Adapter_Elasticsearch_HTTPRequest extends \HTTP_Request2 { + public $allow404 = false; + public function send() { $res = parent::send(); $mainCode = intval($res->getStatus() / 100); - if ($mainCode != 2) { - $js = json_decode($res->getBody()); - if (isset($js->error)) { - $error = $js->error; - } else { - $error = $res->getBody(); - } - throw new Exception( - 'Error in elasticsearch communication: ' . $error - ); + if ($mainCode === 2) { + return $res; + } + + if ($this->allow404 && $res->getStatus() == 404) { + return $res; + } + $js = json_decode($res->getBody()); + if (isset($js->error)) { + $error = $js->error; + } else { + $error = $res->getBody(); } - return $res; + throw new Exception( + 'Error in elasticsearch communication' + . '(status code ' . $res->getStatus() . '): ' + . $error + ); } } diff --git a/src/phorkie/Database/Adapter/Elasticsearch/Indexer.php b/src/phorkie/Database/Adapter/Elasticsearch/Indexer.php index dbe769e..cf50bbe 100644 --- a/src/phorkie/Database/Adapter/Elasticsearch/Indexer.php +++ b/src/phorkie/Database/Adapter/Elasticsearch/Indexer.php @@ -89,6 +89,7 @@ class Database_Adapter_Elasticsearch_Indexer implements Database_IIndexer $this->searchInstance . 'repo/_query', \HTTP_Request2::METHOD_DELETE ); + $r->allow404 = true; $r->setBody( json_encode( (object)array( @@ -101,6 +102,7 @@ class Database_Adapter_Elasticsearch_Indexer implements Database_IIndexer $this->searchInstance . 'file/_query', \HTTP_Request2::METHOD_DELETE ); + $r->allow404 = true; $r->setBody( json_encode( (object)array( @@ -118,6 +120,7 @@ class Database_Adapter_Elasticsearch_Indexer implements Database_IIndexer $this->searchInstance . 'repo/' . $repo->id, \HTTP_Request2::METHOD_DELETE ); + $r->allow404 = true; $r->send(); $this->deleteRepoFiles($repo); @@ -130,6 +133,7 @@ class Database_Adapter_Elasticsearch_Indexer implements Database_IIndexer $this->searchInstance . 'file/_query', \HTTP_Request2::METHOD_DELETE ); + $r->allow404 = true; $r->setBody( json_encode( (object)array( |
