From 373885ebd1c957cdecda94d60ae2e0c665b735d5 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Jul 2018 11:57:49 -0700 Subject: [PATCH] Use Storage for file uploads (not model images) --- .../Controllers/Assets/AssetFilesController.php | 13 +++++-------- .../Licenses/LicenseFilesController.php | 16 ++++++++-------- composer.json | 6 ++++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/Assets/AssetFilesController.php b/app/Http/Controllers/Assets/AssetFilesController.php index 19ed4538ff..9f31b80dc8 100644 --- a/app/Http/Controllers/Assets/AssetFilesController.php +++ b/app/Http/Controllers/Assets/AssetFilesController.php @@ -107,21 +107,18 @@ class AssetFilesController extends Controller { $asset = Asset::find($assetId); $this->authorize('update', $asset); - $destinationPath = config('app.private_uploads').'/imports/assets'; + $rel_path = 'storage/private_uploads/assets'; // the asset is valid if (isset($asset->id)) { $this->authorize('update', $asset); - $log = Actionlog::find($fileId); - $full_filename = $destinationPath.'/'.$log->filename; - if (file_exists($full_filename)) { - \Log::debug('Trying to delete '.$full_filename); - Storage::delete($full_filename); - //unlink($destinationPath.'/'.$log->filename); + if (file_exists(base_path().'/'.$rel_path.'/'.$log->filename)) { + Storage::delete($rel_path.'/'.$log->filename); } $log->delete(); - return redirect()->back()->with('success', trans('admin/hardware/message.deletefile.success')); + return redirect()->back() + ->with('success', trans('admin/hardware/message.deletefile.success')); } // Redirect to the hardware management page diff --git a/app/Http/Controllers/Licenses/LicenseFilesController.php b/app/Http/Controllers/Licenses/LicenseFilesController.php index e17f281a9e..a25b15ada2 100644 --- a/app/Http/Controllers/Licenses/LicenseFilesController.php +++ b/app/Http/Controllers/Licenses/LicenseFilesController.php @@ -75,19 +75,19 @@ class LicenseFilesController extends Controller public function destroy($licenseId = null, $fileId = null) { $license = License::find($licenseId); - $destinationPath = config('app.private_uploads').'/licenses'; - // the license is valid + $rel_path = 'storage/private_uploads/licenses'; + + // the asset is valid if (isset($license->id)) { - $this->authorize('edit', $license); + $this->authorize('update', $license); $log = Actionlog::find($fileId); - $full_filename = $destinationPath.'/'.$log->filename; - if (file_exists($full_filename)) { - Storage::delete($full_filename); - // unlink($destinationPath.'/'.$log->filename); + if (file_exists(base_path().'/'.$rel_path.'/'.$log->filename)) { + Storage::delete($rel_path.'/'.$log->filename); } $log->delete(); - return redirect()->back()->with('success', trans('admin/licenses/message.deletefile.success')); + return redirect()->back() + ->with('success', trans('admin/hardware/message.deletefile.success')); } // Redirect to the licence management page diff --git a/composer.json b/composer.json index ab1a0d0a1d..9d2b87d204 100644 --- a/composer.json +++ b/composer.json @@ -42,6 +42,7 @@ "watson/validating": "^3.0" }, "require-dev": { + "barryvdh/laravel-ide-helper": "^2.4", "codeception/codeception": "^2.4", "filp/whoops": "~2.0", "fzaninotto/faker": "~1.4", @@ -72,6 +73,11 @@ ] }, "scripts": { + "post-update-cmd": [ + "Illuminate\\Foundation\\ComposerScripts::postUpdate", + "php artisan ide-helper:generate", + "php artisan ide-helper:meta" + ], "post-autoload-dump": [ "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", "@php artisan package:discover"