Fix bug #22: Edited pastes not in "recently created"
[phorkie.git] / src / phorkie / Database / Adapter / Elasticsearch / Setup.php
index acbe77c977f5de38c7b64977dc5831ab53cbf91b..0df287475051740bdf8b9bf84de692dbb1080f4f 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 namespace phorkie;
 
-class Database_Adapter_Elasticsearch_Setup
+class Database_Adapter_Elasticsearch_Setup implements Database_ISetup
 {
     public function __construct()
     {
@@ -10,12 +10,29 @@ class Database_Adapter_Elasticsearch_Setup
 
     public function setup()
     {
-        $r = new Database_Adapter_Elasticsearch_HTTPRequest(
-            $this->searchInstance . 'repo/_mapping',
+        $r = new \HTTP_Request2(
+            $this->searchInstance . '/_mapping', \HTTP_Request2::METHOD_GET
+        );
+        $res = $r->send();
+        if ($res->getStatus() == 404) {
+            $this->reset();
+        }
+    }
+
+    public function reset()
+    {
+        $r = new \HTTP_Request2(
+            $this->searchInstance,
             \HTTP_Request2::METHOD_DELETE
         );
         $r->send();
 
+        $r = new Database_Adapter_Elasticsearch_HTTPRequest(
+            $this->searchInstance,
+            \HTTP_Request2::METHOD_PUT
+        );
+        $r->send();
+
         //create mapping
         //mapping for repositories
         $r = new Database_Adapter_Elasticsearch_HTTPRequest(