From 77d30bf9a8aa51b7dde777b95d62d29850fd958c Mon Sep 17 00:00:00 2001 From: marcio1002 Date: Wed, 25 Oct 2023 17:25:00 -0300 Subject: [PATCH 1/2] Change import users --- app/Http/Controllers/UserController.php | 13 +------------ app/Imports/UsersWithSmartUsersImport.php | 6 ++++-- composer.json | 2 +- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 60d74be..69a5faf 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -16,7 +16,6 @@ use Illuminate\Http\Response; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Storage; -// use Maatwebsite\Excel\Excel as ExcelType; use Maatwebsite\Excel\Facades\Excel; class UserController extends Controller @@ -143,21 +142,11 @@ class UserController extends Controller $disk = 'imports'; $filename = $file_users->store(path: "", options: $disk); - - // $mimeType = $file_users->getMimeType(); - // $type = match($mimeType) { - // "text/csv" => ExcelType::CSV, - // "application/vnd.oasis.opendocument.spreadsheet" => ExcelType::ODS, - // "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" => ExcelType::XLSX, - // "application/vnd.ms-excel" => ExcelType::XLS, - // default => ExcelType::XLSX, - // }; Excel::import( import: new UsersWithSmartUsersImport($file_logos), filePath: $filename, disk: $disk, - // readerType: $type ); return response() @@ -166,7 +155,7 @@ class UserController extends Controller } catch (\Throwable $th) { throw $th; } finally { - Storage::disk($driver)->delete($filename); + Storage::disk($disk)->delete($filename); } } } diff --git a/app/Imports/UsersWithSmartUsersImport.php b/app/Imports/UsersWithSmartUsersImport.php index a0cf1e4..39af0d4 100644 --- a/app/Imports/UsersWithSmartUsersImport.php +++ b/app/Imports/UsersWithSmartUsersImport.php @@ -4,12 +4,14 @@ namespace App\Imports; use App\Models\DadosCadastrais; use App\Models\User; + use Illuminate\Http\File; use Illuminate\Support\Str; use Illuminate\Http\UploadedFile; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Storage; + use Maatwebsite\Excel\Concerns\ToCollection; use ZanySoft\Zip\Facades\Zip; @@ -113,11 +115,11 @@ class UsersWithSmartUsersImport implements ToCollection $picture = new File($temp_file_path); $pathS3 = "avatars/{$picture->hashName()}"; - Storage::disk('s3')->put($pathS3, $picture->getContent()); + Storage::disk('s3')->missing($pathS3) && Storage::disk('s3')->put($pathS3, $picture->getContent()); $filename = \preg_replace("/\.[^\.]+$/", "", $filename); - $this->files_paths[$filename] = url('/images/test.png') ?? Storage::disk('s3')->url($pathS3); + $this->files_paths[$filename] = Storage::disk('s3')->url($pathS3); \unlink($temp_file_path); }); diff --git a/composer.json b/composer.json index b45b128..a73d701 100644 --- a/composer.json +++ b/composer.json @@ -74,7 +74,7 @@ "@php artisan config:clear --ansi", "@php artisan schedule:clear-cache --ansi" ], - "authorized-files": "sudo chown -R www-data:www-data storage/ storage/framework/cache storage/framework/cache/data bootstrap/cache/ public/", + "authorized-files": "sudo chown -R www-data:www-data storage/ bootstrap/cache/ public/ && sudo chown -R :www-data storage/", "dev": "@php artisan serve --host=0.0.0.0 --port=8080 --ansi" }, "extra": { From f4734a92d3c55653308b843ef6968f1db33839b4 Mon Sep 17 00:00:00 2001 From: marcio1002 Date: Wed, 25 Oct 2023 17:26:25 -0300 Subject: [PATCH 2/2] change --- app/Imports/UsersWithSmartUsersImport.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Imports/UsersWithSmartUsersImport.php b/app/Imports/UsersWithSmartUsersImport.php index 39af0d4..51b6699 100644 --- a/app/Imports/UsersWithSmartUsersImport.php +++ b/app/Imports/UsersWithSmartUsersImport.php @@ -115,7 +115,8 @@ class UsersWithSmartUsersImport implements ToCollection $picture = new File($temp_file_path); $pathS3 = "avatars/{$picture->hashName()}"; - Storage::disk('s3')->missing($pathS3) && Storage::disk('s3')->put($pathS3, $picture->getContent()); + Storage::disk('s3')->missing($pathS3) && + Storage::disk('s3')->put($pathS3, $picture->getContent()); $filename = \preg_replace("/\.[^\.]+$/", "", $filename);