setup: check json before dropping current index
authorChristian Weiske <cweiske@cweiske.de>
Sun, 6 Nov 2016 16:16:15 +0000 (17:16 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Sun, 6 Nov 2016 16:16:15 +0000 (17:16 +0100)
bin/setup.php

index ca71aed..27c5c46 100755 (executable)
@@ -7,6 +7,14 @@ namespace phinde;
  */
 require_once __DIR__ . '/../src/init.php';
 
+$json = file_get_contents(__DIR__ . '/../data/elasticsearch-mapping.json');
+if (json_decode($json) === null) {
+    echo "Error: Schema JSON is broken\n";
+    chdir(__DIR__ . '/../');
+    passthru('json_pp -t null < data/elasticsearch-mapping.json');
+    exit(1);
+}
+
 //delete old index
 $r = new Elasticsearch_Request(
     $GLOBALS['phinde']['elasticsearch'],
@@ -20,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();
 ?>