]> _ Git - odl.git/commitdiff
wait #4876 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 8 Mar 2022 16:49:29 +0000 (17:49 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 8 Mar 2022 16:49:29 +0000 (17:49 +0100)
app/Http/Controllers/Admin/Operations/ImportAssetsOperation.php

index 93947e7e2ea1cc0aa74f81e102dab7c44b8ba864..412be00bb26e57053ae36c72f67b8f8470838bf9 100644 (file)
@@ -4,6 +4,8 @@ namespace App\Http\Controllers\Admin\Operations;
 
 
 use App\Models\Asset;
+use Cubist\Util\Files\Files;
+use Cubist\Util\Str;
 use Illuminate\Support\Facades\Route;
 use Prologue\Alerts\Facades\Alert;
 use Symfony\Component\HttpFoundation\File\UploadedFile;
@@ -25,7 +27,6 @@ trait ImportAssetsOperation
         /** @var UploadedFile[] $files */
         $files = request()->files->get('file');
 
-
         if (!count($files)) {
             Alert::warning('Aucun fichier chargĂ©')->flash();
             return;
@@ -35,13 +36,14 @@ trait ImportAssetsOperation
 
         $j = 0;
         foreach ($files as $i => $file) {
-            $name = $file->getClientOriginalName();
-            $e = explode('.', $name);
-            $ext = mb_strtolower(array_pop($e));
+            $ext = mb_strtolower($file->getClientOriginalExtension());
             if (!in_array($ext, $exts)) {
                 continue;
             }
+            $name = $file->getClientOriginalName();
             $e = explode('-', $name, 2);
+
+            $f = $file->move(sys_get_temp_dir(), Str::slug($file->getBasename('.' . $ext)) . '.' . $ext);
             $assetId = trim($e[0]);
             if (!preg_match("/\d+/", $assetId, $matches)) {
                 continue;
@@ -51,7 +53,7 @@ trait ImportAssetsOperation
             if (null === $asset) {
                 continue;
             }
-            $asset->replaceMediaInField('file_upload', $file);
+            $asset->replaceMediaInField('file_upload', $f);
             $j++;
         }