From fdb67c74d9a1bdd3a9602ec7a5dbe60294dc5769 Mon Sep 17 00:00:00 2001 From: aynsix Date: Wed, 17 Jul 2019 17:16:29 +0400 Subject: [PATCH] fix port to 4.1 extract xmp:PageImage indesign --- composer.lock | 12 ++++----- lib/Alchemy/Phrasea/Media/SubdefGenerator.php | 26 ++++++++++++++----- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/composer.lock b/composer.lock index 5721974b41..194fd91634 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "64830cb4d53b32b47e02d4a19df9cef2", + "content-hash": "6341722edcd5bfa22e933f5411225144", "packages": [ { "name": "alchemy-fr/tcpdf-clone", @@ -383,16 +383,16 @@ }, { "name": "alchemy/phpexiftool", - "version": "0.7.0", + "version": "0.7.2", "source": { "type": "git", "url": "https://github.com/alchemy-fr/PHPExiftool.git", - "reference": "7372ca4e43473328bf06bca810558fbad7bb2f95" + "reference": "ba1cb51eceb6562d7996023478977a8739de188b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/alchemy-fr/PHPExiftool/zipball/7372ca4e43473328bf06bca810558fbad7bb2f95", - "reference": "7372ca4e43473328bf06bca810558fbad7bb2f95", + "url": "https://api.github.com/repos/alchemy-fr/PHPExiftool/zipball/ba1cb51eceb6562d7996023478977a8739de188b", + "reference": "ba1cb51eceb6562d7996023478977a8739de188b", "shasum": "" }, "require": { @@ -452,7 +452,7 @@ "exiftool", "metadata" ], - "time": "2017-05-18T19:04:04+00:00" + "time": "2019-02-13T13:06:43+00:00" }, { "name": "alchemy/queue-bundle", diff --git a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php index 2dede228c5..88867551a1 100644 --- a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php +++ b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php @@ -61,7 +61,7 @@ class SubdefGenerator public function generateSubdefs(\record_adapter $record, array $wanted_subdefs = null) { - if ($record->get_hd_file() !== null) { + if ($record->get_hd_file() !== null && $record->get_hd_file()->getMimeType() == "application/x-indesign") { $mediaSource = $this->mediavorus->guess($record->get_hd_file()->getPathname()); $metadatas = $mediaSource->getMetadatas(); @@ -69,15 +69,27 @@ class SubdefGenerator if(!isset($this->tmpFilesystem)){ $this->tmpFilesystem = Manager::create(); } - $tmpDir = $this->tmpFilesystem->createTemporaryDirectory(); + $tmpDir = $this->tmpFilesystem->createTemporaryDirectory(0777, 500); - try { - $this->app['filesystem']->dumpFile($tmpDir.'/file.jpg', $metadatas->get('XMP-xmp:PageImage')->getValue()->asString()); - $this->tmpFilePath = $tmpDir.'/file.jpg'; - } catch (\Exception $e) { - $this->logger->error(sprintf('Unable to write temporary file : %s', $e->getMessage())); + $files = $this->app['exiftool.preview-extractor']->extract($record->get_hd_file()->getPathname(), $tmpDir); + + $selected = null; + $size = null; + + foreach ($files as $file) { + if ($file->isDir() || $file->isDot()) { + continue; + } + + if (is_null($selected) || $file->getSize() > $size) { + $selected = $file->getPathname(); + $size = $file->getSize(); + } } + if ($selected) { + $this->tmpFilePath = $selected; + } } }