From e7d88ac288139d8e3a3182a554a61fea90913261 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 20 Oct 2021 10:33:15 +0200 Subject: [PATCH] wip #4806 @0.25 --- app/Jobs/ProcessFluidbook.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/Jobs/ProcessFluidbook.php b/app/Jobs/ProcessFluidbook.php index 6c01d38..ca6c5aa 100644 --- a/app/Jobs/ProcessFluidbook.php +++ b/app/Jobs/ProcessFluidbook.php @@ -42,9 +42,8 @@ class ProcessFluidbook extends Compiler */ protected function _getAssetFile($id) { - /** @var Asset $asset */ - $asset = Asset::find($id); - $path = $asset->getMediaInField($asset->getAttributeValue('file_upload'))->first()->getPath(); + $collection = $this->_getAssetCollection($id); + $path = $collection->first()->getPath(); $spl = new \SplFileInfo($path); $fname = $spl->getFilename(); if (file_exists($path)) { @@ -53,7 +52,7 @@ class ProcessFluidbook extends Compiler if (stripos($path, '.mp4') !== false) { /** @var Media $posterMedia */ - $posterMedia = $asset->getMediaInField($asset->getAttributeValue('file_upload'))->first(); + $posterMedia = $collection->first(); $poster = $posterMedia->getPath('poster'); if (file_exists($poster)) { $dest = $this->wdir . str_replace('.mp4', '.jpg', $fname); @@ -64,14 +63,26 @@ class ProcessFluidbook extends Compiler return $fname; } + protected function _getAssetCollection($id) + { + /** @var Asset $asset */ + $asset = Asset::find($id); + if (null === $asset) { + throw new \Exception('L\'élement ' . $id . ' n\'existe pas dans la médiathèque'); + } + $collection = $asset->getMediaInField($asset->getAttributeValue('file_upload')); + if ($collection->count() === 0) { + throw new \Exception('L\'élement ' . $id . ' de la médiathèque ne contient aucun fichier'); + } + return $collection; + } + /** * @throws \Exception */ protected function _zipAssets($id) { - /** @var Asset $asset */ - $asset = Asset::find($id); - $collection = $asset->getMediaInField($asset->getAttributeValue('file_upload')); + $collection = $this->_getAssetCollection($id); $tmp = Files::tmpdir(); $zip = Files::tempnam($this->wdir) . '.zip'; -- 2.39.5