Unverified Commit c6534c86 authored by Jerome Boucher's avatar Jerome Boucher
Browse files

merge conflict

parents 98459358 aa950991
......@@ -87,7 +87,31 @@ class digitalSafe
$account = $this->accountController->get($accountToken->accountId);
$replyMessage->accountName = $account->accountName;
foreach ($archive->digitalResources as $resource) {
if ((isset($resource->hash) && !is_null($resource->hash))
&& (isset($resource->hashAlgorithm)
&& !is_null($resource->hashAlgorithm))
) {
try {
$this->checkHash($resource->handler, $resource->hash, $resource->hashAlgorithm);
} catch (\Exception $e) {
throw $this->getThrowable($e->getMessage(), 400, $replyMessage);
}
$this->getHash($resource);
continue;
}
if (!isset($resource->hash) && !isset($resource->hashAlgorithm)) {
$this->getHash($resource);
continue;
}
throw $this->getThrowable("Hash or hash algorithm missing", 401, $replyMessage);
}
try {
$archive = \laabs::castMessage($archive, 'recordsManagement/archive');
$archiveId = $this->archiveController->receive($archive, false);
$archive = $this->sdoFactory->read('recordsManagement/archive', $archiveId);
} catch (\Exception $e) {
......@@ -655,6 +679,32 @@ class digitalSafe
}
}
/**
* Calculate hash if necessary
*
* @param object $resource
*/
protected function getHash($resource)
{
$hashAlgorithm = \laabs::configuration('recordsManagement')['hashAlgorithm'];
if ($resource->hashAlgorithm == $hashAlgorithm) {
return;
}
$resource->hashAlgorithm = $hashAlgorithm;
if (is_string($resource->handler)) {
$resource->hash = strtolower(hash($hashAlgorithm, base64_decode($resource->handler)));
} else {
$tmpfile = \laabs::getTmpDir().DIRECTORY_SEPARATOR.rand();
file_put_contents($tmpfile, base64_decode(stream_get_contents($resource->handler)));
rewind($resource->handler);
$resource->hash = strtolower(hash_file($hashAlgorithm, $tmpfile));
unlink($tmpfile);
}
}
/**
* log event in lifecycle journal
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment