Talk about WebSub
[phinde.git] / bin / setup.php
1 #!/usr/bin/env php
2 <?php
3 namespace phinde;
4 /**
5  * Configure the elasticsearch index.
6  * Throws away all data.
7  */
8 require_once __DIR__ . '/../src/init.php';
9
10 $json = file_get_contents(__DIR__ . '/../data/elasticsearch-mapping.json');
11 if (json_decode($json) === null) {
12     Log::error("Error: Schema JSON is broken");
13     chdir(__DIR__ . '/../');
14     passthru('json_pp -t null < data/elasticsearch-mapping.json');
15     exit(1);
16 }
17
18 //delete old index
19 $r = new Elasticsearch_Request(
20     $GLOBALS['phinde']['elasticsearch'],
21     \HTTP_Request2::METHOD_DELETE
22 );
23 $r->allow404 = true;
24 $r->send();
25
26 //recreate it
27 $r = new Elasticsearch_Request(
28     $GLOBALS['phinde']['elasticsearch'],
29     \HTTP_Request2::METHOD_PUT
30 );
31 $r->setBody($json);
32 $r->send();
33 ?>