add log class
[phinde.git] / bin / setup.php
index 1e6c66db73ba558fd96eb530086f771f3a66db75..ba97493db4f77812597a871c591d48e170c6da1e 100755 (executable)
@@ -1,9 +1,20 @@
 #!/usr/bin/env php
 <?php
 namespace phinde;
-//configure the elasticsearch index
+/**
+ * Configure the elasticsearch index.
+ * Throws away all data.
+ */
 require_once __DIR__ . '/../src/init.php';
 
+$json = file_get_contents(__DIR__ . '/../data/elasticsearch-mapping.json');
+if (json_decode($json) === null) {
+    Log::error("Error: Schema JSON is broken");
+    chdir(__DIR__ . '/../');
+    passthru('json_pp -t null < data/elasticsearch-mapping.json');
+    exit(1);
+}
+
 //delete old index
 $r = new Elasticsearch_Request(
     $GLOBALS['phinde']['elasticsearch'],
@@ -17,8 +28,6 @@ $r = new Elasticsearch_Request(
     $GLOBALS['phinde']['elasticsearch'],
     \HTTP_Request2::METHOD_PUT
 );
-$r->setBody(
-    file_get_contents(__DIR__ . '/../data/elasticsearch-mapping.json')
-);
+$r->setBody($json);
 $r->send();
 ?>