From ef6622826a0c0a1132537492698768a250cb1e04 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 8 May 2012 18:06:22 +0200 Subject: [PATCH] delete elasticsearch index when indexing to clean up properly --- scripts/index.php | 8 ++----- .../Database/Adapter/Elasticsearch/Setup.php | 21 +++++++++++++++++-- src/phorkie/Database/Adapter/Null/Setup.php | 1 + src/phorkie/Database/ISetup.php | 1 + src/phorkie/SetupCheck.php | 4 ++-- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/scripts/index.php b/scripts/index.php index 5afbee0..4b529d1 100644 --- a/scripts/index.php +++ b/scripts/index.php @@ -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(); diff --git a/src/phorkie/Database/Adapter/Elasticsearch/Setup.php b/src/phorkie/Database/Adapter/Elasticsearch/Setup.php index 066a21c..0df2874 100644 --- a/src/phorkie/Database/Adapter/Elasticsearch/Setup.php +++ b/src/phorkie/Database/Adapter/Elasticsearch/Setup.php @@ -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( diff --git a/src/phorkie/Database/Adapter/Null/Setup.php b/src/phorkie/Database/Adapter/Null/Setup.php index de23d0a..3850978 100644 --- a/src/phorkie/Database/Adapter/Null/Setup.php +++ b/src/phorkie/Database/Adapter/Null/Setup.php @@ -4,6 +4,7 @@ namespace phorkie; class Database_Adapter_Null_Setup { public function setup() {} + public function reset() {} } ?> diff --git a/src/phorkie/Database/ISetup.php b/src/phorkie/Database/ISetup.php index 1ac6b2f..bb7293e 100644 --- a/src/phorkie/Database/ISetup.php +++ b/src/phorkie/Database/ISetup.php @@ -4,6 +4,7 @@ namespace phorkie; interface Database_ISetup { public function setup(); + public function reset(); } ?> diff --git a/src/phorkie/SetupCheck.php b/src/phorkie/SetupCheck.php index 39c386e..8ead33f 100644 --- a/src/phorkie/SetupCheck.php +++ b/src/phorkie/SetupCheck.php @@ -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) -- 2.30.2