WIP Workorder AH download

This commit is contained in:
Frank Schubert
2024-11-08 12:23:07 +01:00
parent 6c0d334bbc
commit 482e1a4989
4 changed files with 111 additions and 5 deletions

View File

@@ -247,7 +247,111 @@ class Rimoapi {
return false;
}
$items = self::getFilenames($rimo_id);
if(!is_object($items)) {
return false;
}
if(!is_array($items->item) || !count($items->item)) {
return false;
}
foreach($items->item as $item) {
if(!$item->name) continue;
if(!preg_match('/_AHA.pdf$/i', $item->name)) continue;
$filename = $item->name;
}
if(!$filename) {
return false;
}
// fetch file
$params = [];
$params['apiKey'] = RIMO_API_JSON_APIKEY;
$params['objectId'] = $rimo_id;
$params['fileNames'] = $filename;
$ctx_opts = [
'http' => [
'method' => 'GET',
]
];
$qs = http_build_query($params);
$getFileEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_GET_FILES;
$get_url = $getFileEp."?".$qs;
$ctx = stream_context_create($ctx_opts);
$log->debug(__METHOD__.": Retrieving file from Rimo: $get_url");
$response = file_get_contents($get_url, false, $ctx);
if(!$response) return false;
/* remove boundary from rimo response
header:
--uuid:b0b72203-db4d-4a85-9d26-b01cd08338c1
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <101DCY_AHA.pdf>
footer:
--uuid:b0b72203-db4d-4a85-9d26-b01cd08338c1--
*/
$finfo = new Finfo(FILEINFO_MIME);
$mimetype = $finfo->buffer($response);
var_dump($mimetype);exit;
if(!stripos($mimetype, "pdf")) {
return false;
}
return $response;
}
public static function getFilenames($rimo_id) {
if(!$rimo_id) return false;
$log = mfLoghandler::singleton();
$params = [];
$params['apiKey'] = RIMO_API_JSON_APIKEY;
$params['objectId'] = $rimo_id;
$ctx_opts = [
'http' => [
'method' => 'GET',
'header' => 'accept: application/json'
]
];
$qs = http_build_query($params);
$getFileEp = RIMO_API_JSON_URL.RIMO_API_JSON_EP_GET_FILENAMES;
$get_url = $getFileEp."?".$qs;
$ctx = stream_context_create($ctx_opts);
$log->debug(__METHOD__.": Getting Filenames from Rimo: $get_url");
$response = file_get_contents($get_url, false, $ctx);
if($response === false) {
$log->error("Error retrieving filenames from RIMO for $rimo_id");
return false;
}
$resp_data = json_decode($response);
return $resp_data;
}