From d306d292ebeeec6667bd62afa81a0be405be4195 Mon Sep 17 00:00:00 2001 From: aina-esokia Date: Fri, 15 Jun 2018 15:51:10 +0400 Subject: [PATCH 1/2] generate video subdef in temporary path first --- .../Phrasea/Filesystem/FilesystemService.php | 5 +++++ lib/Alchemy/Phrasea/Media/SubdefGenerator.php | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php b/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php index 1a782400ad..6f93b8d516 100644 --- a/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php +++ b/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php @@ -67,6 +67,11 @@ class FilesystemService return $pathdest . $this->generateSubdefFilename($record, $subdef); } + public function generateTemporarySubdefPathname(\record_adapter $record, \databox_subdef $subdef, $tmpDir) + { + return $tmpDir . $this->generateSubdefFilename($record, $subdef); + } + /** * @param RecordInterface $record * @param string|\SplFileInfo $source diff --git a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php index c60c4d3b7b..851349730a 100644 --- a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php +++ b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php @@ -22,6 +22,7 @@ use Alchemy\Phrasea\Filesystem\FilesystemService; use Alchemy\Phrasea\Media\Subdef\Specification\PdfSpecification; use MediaAlchemyst\Alchemyst; use MediaAlchemyst\Specification\Image; +use MediaAlchemyst\Specification\Video; use MediaVorus\MediaVorus; use MediaAlchemyst\Exception\ExceptionInterface as MediaAlchemystException; use Neutron\TemporaryFilesystem\Manager; @@ -173,6 +174,14 @@ class SubdefGenerator return; } + $tmpDir = $this->app['conf']->get(['registry', 'executables', 'ffmpeg-tmp-directory']); + $destFile = null; + + if($subdef_class->getSpecs() instanceof Video && !empty($tmpDir) && is_dir($tmpDir)){ + $destFile = $pathdest; + $pathdest = $this->filesystem->generateTemporarySubdefPathname($record, $subdef_class, $tmpDir); + } + if (isset($this->tmpFilePath) && $subdef_class->getSpecs() instanceof Image) { $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) { $this->logger->error(sprintf('Subdef generation failed for record %d with message %s', $record->getRecordId(), $e->getMessage())); } From 4e1190a156a8b810baba83ad41fd386aaaeab16c Mon Sep 17 00:00:00 2001 From: aina-esokia Date: Tue, 19 Jun 2018 10:58:34 +0400 Subject: [PATCH 2/2] change temporary storage config --- lib/Alchemy/Phrasea/Filesystem/FilesystemService.php | 11 ++++++++++- lib/Alchemy/Phrasea/Media/SubdefGenerator.php | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php b/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php index 6f93b8d516..a3db77e635 100644 --- a/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php +++ b/lib/Alchemy/Phrasea/Filesystem/FilesystemService.php @@ -69,7 +69,16 @@ class FilesystemService public function generateTemporarySubdefPathname(\record_adapter $record, \databox_subdef $subdef, $tmpDir) { - return $tmpDir . $this->generateSubdefFilename($record, $subdef); + $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; } /** diff --git a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php index 851349730a..037b3d8f51 100644 --- a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php +++ b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php @@ -174,10 +174,10 @@ class SubdefGenerator return; } - $tmpDir = $this->app['conf']->get(['registry', 'executables', 'ffmpeg-tmp-directory']); + $tmpDir = $this->app['conf']->get(['main', 'storage', 'tmp_files']); $destFile = null; - if($subdef_class->getSpecs() instanceof Video && !empty($tmpDir) && is_dir($tmpDir)){ + if($subdef_class->getSpecs() instanceof Video && !empty($tmpDir)){ $destFile = $pathdest; $pathdest = $this->filesystem->generateTemporarySubdefPathname($record, $subdef_class, $tmpDir); }