Newer
Older
require_once('../bin/smartdata/SmartAPI.php');
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require_once('../bin/smartdata/Logger.php');
http_response_code(HttpStatusCode::BAD_REQUEST);
$compl = array();
if(isset($_GET['version'])) $compl = array_merge($compl, array('version' => $_GET['version']));
if(isset($_GET['unit'])) $compl = array_merge($compl, array('unit' => $_GET['unit']));
//if(isset($_GET['value'])) $compl = array_merge($compl, array('value' => $_GET['value']));
if(isset($_GET['error'])) $compl = array_merge($compl, array('error' => $_GET['error']));
if(isset($_GET['confidence'])) $compl = array_merge($compl, array('confidence' => $_GET['confidence']));
if(isset($_GET['x'])) $compl = array_merge($compl, array('x' => $_GET['x']));
if(isset($_GET['y'])) $compl = array_merge($compl, array('y' => $_GET['y']));
if(isset($_GET['z'])) $compl = array_merge($compl, array('z' => $_GET['z']));
//if(isset($_GET['t'])) $compl = array_merge($compl, array('t' => $_GET['t']));
if(isset($_GET['dev'])) $compl = array_merge($compl, array('dev' => $_GET['dev']));
//Logger::print_r($compl, true);
try {
$content = file_get_contents('php://input');
if(is_array(json_decode($content, true))) {
// Is JSON
throw new Exception\NotImplementedException("JSON-based import in batch has not been implemented yet");
} else {
// Is Binary
if(!REQUEST_CERT){
throw new Exception\BadRequestException("!CERT > For batch import, the user must use a valid certificate");
}
$series = Series::unpack($content);
Logger::debug($series, true);
$smartdata_array = array();
while($content) {
$data = SmartData::unpack($content, $compl);
if($data instanceof SmartData)
array_push($smartdata_array, $data);
}
$db = new Backend();
if(!$db->insertBatch($series, ...$smartdata_array)) {
throw new Exception\InsertionFailedException("Insertion Failed");
}
}
}catch(Exception\CustomException $e){
http_response_code($e->getHTTPCodeError());
Logger::exception($e);
return false;
}catch(\Exception $e){
http_response_code(HttpStatusCode::BAD_REQUEST);
Logger::exception($e);
return false;
}
http_response_code(HttpStatusCode::NO_CONTENT);