From 8eea2bc020b303e56dc8deec5b19826497ea3985 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 7 Mar 2022 11:28:36 +0100 Subject: [PATCH] wip #5108 @1 --- app/Http/Controllers/Admin/ToolsController.php | 11 ++++++++++- app/Models/Asset.php | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Admin/ToolsController.php b/app/Http/Controllers/Admin/ToolsController.php index 3663350..60adc1d 100644 --- a/app/Http/Controllers/Admin/ToolsController.php +++ b/app/Http/Controllers/Admin/ToolsController.php @@ -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); } diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 118fd94..45f9d9c 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -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 */ -- 2.39.5