From: Vincent Vanwaelscappel Date: Wed, 20 Oct 2021 08:33:15 +0000 (+0200) Subject: wip #4806 @0.25 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=e7d88ac288139d8e3a3182a554a61fea90913261;p=odl.git wip #4806 @0.25 --- 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';