delete elasticsearch index when indexing to clean up properly
authorChristian Weiske <cweiske@cweiske.de>
Tue, 8 May 2012 16:06:22 +0000 (18:06 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 8 May 2012 16:06:22 +0000 (18:06 +0200)
scripts/index.php
src/phorkie/Database/Adapter/Elasticsearch/Setup.php
src/phorkie/Database/Adapter/Null/Setup.php
src/phorkie/Database/ISetup.php
src/phorkie/SetupCheck.php

index 5afbee090d70fad2d35af5a1016444bf6332aa16..4b529d1c7ee10b54997405f96c29fa5a02604145 100644 (file)
@@ -28,13 +28,9 @@ if ($GLOBALS['phorkie']['cfg']['setupcheck']) {
 $db = new Database();
 $idx = $db->getIndexer();
 
-//cleanup
-echo "Deleting all index data\n";
-$idx->deleteAllRepos();
-
 //create mapping
-echo "Index setup\n";
-$db->getSetup()->setup();
+echo "Index reset\n";
+$db->getSetup()->reset();
 
 
 $rs = new Repositories();
index 066a21c2253f7019959388e40192267709fa7030..0df287475051740bdf8b9bf84de692dbb1080f4f 100644 (file)
@@ -10,12 +10,29 @@ class Database_Adapter_Elasticsearch_Setup implements Database_ISetup
 
     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(
index de23d0a0161df97baaf1e66988e2732a0bb30da4..385097877efc2c11cb8424a34a26f6ac57da48ee 100644 (file)
@@ -4,6 +4,7 @@ namespace phorkie;
 class Database_Adapter_Null_Setup
 {
     public function setup() {}
+    public function reset() {}
 }
 
 ?>
index 1ac6b2f04e0047d1ab0a3122dbf4cafb0706fa68..bb7293eb4db227c2f208b31967d772dac943afdd 100644 (file)
@@ -4,6 +4,7 @@ namespace phorkie;
 interface Database_ISetup
 {
     public function setup();
+    public function reset();
 }
 
 ?>
index 39c386e3683c7f72a56a2044164798037108dc9d..8ead33faa2601ec6acea3a5bb5733afb07b1838b 100644 (file)
@@ -72,8 +72,8 @@ class SetupCheck
 
     public function checkDatabase()
     {
-        $dbs = new Database_Setup_Elasticsearch();
-        $dbs->setup();
+        $dbs = new Database();
+        $dbs->getSetup()->setup();
     }
 
     public function fail($msg)