Merge pull request #2645 from aynsix/PHRAS-2112-video-subdef-in-specified-path

PHRAS-2112 generate video subdef in temporary path first
This commit is contained in:
Nicolas Maillat
2018-06-19 19:18:32 +00:00
committed by GitHub
2 changed files with 28 additions and 0 deletions

View File

@@ -67,6 +67,20 @@ class FilesystemService
return $pathdest . $this->generateSubdefFilename($record, $subdef); return $pathdest . $this->generateSubdefFilename($record, $subdef);
} }
public function generateTemporarySubdefPathname(\record_adapter $record, \databox_subdef $subdef, $tmpDir)
{
$tmpDir = \p4string::addEndSlash($tmpDir);
$ffmpegDir = $tmpDir."ffmpeg/";
if(!is_dir($ffmpegDir)){
$this->filesystem->mkdir($ffmpegDir);
}
$filenameSufix = $this->generateSubdefFilename($record, $subdef);
return $ffmpegDir . hash('sha256', $filenameSufix) . $filenameSufix;
}
/** /**
* @param RecordInterface $record * @param RecordInterface $record
* @param string|\SplFileInfo $source * @param string|\SplFileInfo $source

View File

@@ -22,6 +22,7 @@ use Alchemy\Phrasea\Filesystem\FilesystemService;
use Alchemy\Phrasea\Media\Subdef\Specification\PdfSpecification; use Alchemy\Phrasea\Media\Subdef\Specification\PdfSpecification;
use MediaAlchemyst\Alchemyst; use MediaAlchemyst\Alchemyst;
use MediaAlchemyst\Specification\Image; use MediaAlchemyst\Specification\Image;
use MediaAlchemyst\Specification\Video;
use MediaVorus\MediaVorus; use MediaVorus\MediaVorus;
use MediaAlchemyst\Exception\ExceptionInterface as MediaAlchemystException; use MediaAlchemyst\Exception\ExceptionInterface as MediaAlchemystException;
use Neutron\TemporaryFilesystem\Manager; use Neutron\TemporaryFilesystem\Manager;
@@ -173,6 +174,14 @@ class SubdefGenerator
return; return;
} }
$tmpDir = $this->app['conf']->get(['main', 'storage', 'tmp_files']);
$destFile = null;
if($subdef_class->getSpecs() instanceof Video && !empty($tmpDir)){
$destFile = $pathdest;
$pathdest = $this->filesystem->generateTemporarySubdefPathname($record, $subdef_class, $tmpDir);
}
if (isset($this->tmpFilePath) && $subdef_class->getSpecs() instanceof Image) { if (isset($this->tmpFilePath) && $subdef_class->getSpecs() instanceof Image) {
$this->alchemyst->turnInto($this->tmpFilePath, $pathdest, $subdef_class->getSpecs()); $this->alchemyst->turnInto($this->tmpFilePath, $pathdest, $subdef_class->getSpecs());
@@ -187,6 +196,11 @@ class SubdefGenerator
} }
if($destFile){
$this->filesystem->copy($pathdest, $destFile);
$this->app['filesystem']->remove($pathdest);
}
} catch (MediaAlchemystException $e) { } catch (MediaAlchemystException $e) {
$this->logger->error(sprintf('Subdef generation failed for record %d with message %s', $record->getRecordId(), $e->getMessage())); $this->logger->error(sprintf('Subdef generation failed for record %d with message %s', $record->getRecordId(), $e->getMessage()));
} }