]> _ Git - odl.git/commitdiff
wip #4806 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 20 Oct 2021 08:33:15 +0000 (10:33 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 20 Oct 2021 08:33:15 +0000 (10:33 +0200)
app/Jobs/ProcessFluidbook.php

index 6c01d3896d71b0c4b97bd61b96f5e902efc13ed4..ca6c5aad766626ec9d3ade285bac6090146e5fcb 100644 (file)
@@ -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';