Avoid using stored binary for conversion, always copy to temp file with original name

parent 7aab5292
Pipeline #6997 canceled with stages
......@@ -672,34 +672,27 @@ class digitalResource
}
$handler = $digitalResource->getHandler();
$metadata = stream_get_meta_data($handler);
if ($metadata['wrapper_type'] == 'plainfile') {
$srcfile = $metadata['uri'];
} else {
$tempdir = str_replace("/", DIRECTORY_SEPARATOR, \laabs\tempdir());
if (isset($digitalResource->fileName)) {
$srcfile = $tempdir.DIRECTORY_SEPARATOR.$digitalResource->fileName;
} else {
$srcfile = $tempdir.DIRECTORY_SEPARATOR.$digitalResource->resId;
}
$tempdir = str_replace("/", DIRECTORY_SEPARATOR, \laabs\tempdir());
$tgtfp = fopen($srcfile, 'w');
stream_copy_to_stream($handler, $tgtfp);
rewind ($handler);
fclose($tgtfp);
if (isset($digitalResource->fileName)) {
$srcfile = $tempdir.DIRECTORY_SEPARATOR.$digitalResource->fileName;
} else {
$srcfile = $tempdir.DIRECTORY_SEPARATOR.$digitalResource->resId;
}
$tgtfp = fopen($srcfile, 'w');
stream_copy_to_stream($handler, $tgtfp);
rewind($handler);
fclose($tgtfp);
$conversionRule = $this->sdoFactory->read("digitalResource/conversionRule", array('puid' => $digitalResource->puid));
$converter = \laabs::newService($conversionRule->conversionService);
$tgtfile = $converter->convert($srcfile, $outputFormats[$conversionRule->targetPuid]);
// Is tempdir was set, delete temp file
if (isset($tempdir)) {
unlink($srcfile);
}
unlink($srcfile);
if (!file_exists($tgtfile)) {
return false;
......
Markdown is supported
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