aboutsummaryrefslogtreecommitdiff
path: root/src/phorkie/Database
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2012-05-07 20:36:13 +0200
committerChristian Weiske <cweiske@cweiske.de>2012-05-07 20:36:13 +0200
commit3c83676016bce1727f0046f4aad7865be8a71fd4 (patch)
tree28a95cdfa56776e454b42ba3126ab54db9806b49 /src/phorkie/Database
parent637ede8759615e1aac86af232f5c053389eb37b7 (diff)
downloadphorkie-3c83676016bce1727f0046f4aad7865be8a71fd4.tar.gz
phorkie-3c83676016bce1727f0046f4aad7865be8a71fd4.zip
use httprequest wrapper to automatically check for errors
Diffstat (limited to 'src/phorkie/Database')
-rw-r--r--src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php25
-rw-r--r--src/phorkie/Database/Setup/Elasticsearch.php22
2 files changed, 45 insertions, 2 deletions
diff --git a/src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php b/src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php
new file mode 100644
index 0000000..2d74a4e
--- /dev/null
+++ b/src/phorkie/Database/Adapter/Elasticsearch/HTTPRequest.php
@@ -0,0 +1,25 @@
+<?php
+namespace phorkie;
+
+class Database_Adapter_Elasticsearch_HTTPRequest extends \HTTP_Request2
+{
+ 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
+ );
+ }
+ return $res;
+ }
+}
+
+?>
diff --git a/src/phorkie/Database/Setup/Elasticsearch.php b/src/phorkie/Database/Setup/Elasticsearch.php
index acf4bfc..b5e2005 100644
--- a/src/phorkie/Database/Setup/Elasticsearch.php
+++ b/src/phorkie/Database/Setup/Elasticsearch.php
@@ -10,9 +10,15 @@ class Database_Setup_Elasticsearch
public function setup()
{
+ $r = new Database_Adapter_Elasticsearch_HTTPRequest(
+ $this->searchInstance . 'repo/_mapping',
+ \HTTP_Request2::METHOD_DELETE
+ );
+ $r->send();
+
//create mapping
//mapping for repositories
- $r = new \HTTP_Request2(
+ $r = new Database_Adapter_Elasticsearch_HTTPRequest(
$this->searchInstance . 'repo/_mapping',
\HTTP_Request2::METHOD_PUT
);
@@ -20,6 +26,10 @@ class Database_Setup_Elasticsearch
json_encode(
(object)array(
'repo' => (object)array(
+ '_timestamp' => (object)array(
+ 'enabled' => true,
+ 'path' => 'tstamp',
+ ),
'properties' => (object)array(
'id' => (object)array(
'type' => 'long'
@@ -27,6 +37,14 @@ class Database_Setup_Elasticsearch
'description' => (object)array(
'type' => 'string',
'boost' => 2.0
+ ),
+ 'crdate' => (object)array(
+ //creation date
+ 'type' => 'date',
+ ),
+ 'tstamp' => (object)array(
+ //modification date
+ 'type' => 'date',
)
)
)
@@ -36,7 +54,7 @@ class Database_Setup_Elasticsearch
$r->send();
//mapping for files
- $r = new \HTTP_Request2(
+ $r = new Database_Adapter_Elasticsearch_HTTPRequest(
$this->searchInstance . 'file/_mapping',
\HTTP_Request2::METHOD_PUT
);