]> _ Git - odl.git/commitdiff
wip #5108 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 7 Mar 2022 10:28:36 +0000 (11:28 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 7 Mar 2022 10:28:36 +0000 (11:28 +0100)
app/Http/Controllers/Admin/ToolsController.php
app/Models/Asset.php

index 3663350255f4506aeee73ef644842aabba95ffdf..60adc1d996ec74bcb89bf2ca4506516efcf12595 100644 (file)
@@ -34,17 +34,26 @@ class ToolsController
 
 
             $u = new \DateTime($item->updated_at);
-            $res[$item->id] = ['update' => $u->getTimestamp()];
+            $res[$item->id] = ['title' => $item->getAttribute('title'), 'type' => $item->getAttribute('type'), 'update' => $u->getTimestamp(),];
             $mtime = $fsize = 0;
             $paths = $item->getMediaPathsByCollection($item->getAttribute('file_upload'));
             foreach ($paths as $path) {
                 if (file_exists($path)) {
                     $mtime = max($mtime, filemtime($path));
                     $fsize += filesize($path);
+                    if (!isset($filename)) {
+                        $spl = new \SplFileInfo($path);
+                        $filename = $spl->getFilename();
+                    }
                 }
             }
+            if (!isset($filename)) {
+                $filename = '';
+            }
             $res[$item->id]['filesize'] = $fsize;
             $res[$item->id]['filemtime'] = $mtime;
+            $res[$item->id]['filename'] = $filename;
+
         }
         return response()->json($res);
     }
index 118fd94ab09b0df8dda2fb68755149cbef47dcbc..45f9d9c09175752652c28bd5020a34caf06d7eb7 100644 (file)
@@ -25,7 +25,7 @@ class Asset extends CubistMagicAbstractModel
 
     protected $_operations = [ImportAssetsOperation::class];
 
-    protected $_enableClone=false;
+    protected $_enableClone = false;
 
     /**
      * @throws \Exception
@@ -38,6 +38,7 @@ class Asset extends CubistMagicAbstractModel
         $this->addField('created_at', Datetime::class, 'Ajouté', ['column' => true, 'hidden' => true]);
         $this->addField('updated_at', Datetime::class, 'Mis à jour', ['column' => true, 'hidden' => true]);
         $this->addField('filesize', Hidden::class, 'Taille des fichiers', ['column' => true, 'column_type' => 'model_function', 'column_function_name' => 'getFilesize']);
+        $this->addField('filemtime', Hidden::class, 'Fichier modifié le', ['column' => true, 'column_type' => 'model_function', 'column_function_name' => 'getFilemtime']);
         $this->addField('type', SelectFromArray::class, 'Type',
             [
                 'options' =>
@@ -70,6 +71,18 @@ class Asset extends CubistMagicAbstractModel
         return $res;
     }
 
+    public function getFilemtime()
+    {
+        $res = 0;
+        foreach ($this->getMediaInField($this->getAttributeValue('file_upload')) as $item) {
+            /** @var $item Media */
+            if (file_exists($item->getPath())) {
+                $res = max(filemtime($item->getPath()), $res);
+            }
+        }
+        return date($res, 'Y-m-d H:i');
+    }
+
     /**
      * @throws \Spatie\Image\Exceptions\InvalidManipulation
      */