Verified Commit 534e4dab authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

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