A free open source IT asset/license management system
First pass at better-handling those annoying Rollbars we keep getting
Brady Wetheringtonc71411465a03
diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.phpindex dceaa9b08a..315c86f725 100755--- a/app/Http/Controllers/Assets/AssetsController.php+++ b/app/Http/Controllers/Assets/AssetsController.php@@ -112,8 +112,10 @@ class AssetsController extends Controller$settings = Setting::getSettings();- $success = false;+ $successes = 0;+ $failures = 0;$serials = $request->input('serials');+ $last_succesful_asset = null;for ($a = 1; $a <= count($asset_tags); $a++) {$asset = new Asset();@@ -200,20 +202,36 @@ class AssetsController extends Controller$asset->checkOut($target, auth()->user(), date('Y-m-d H:i:s'), $request->input('expected_checkin', null), 'Checked out on asset creation', $request->get('name'), $location);}- $success = true;-+ $last_succesful_asset = $asset;+ $successes++;++ } else {+ $failures++;}}session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);- if ($success) {+ if ($successes > 0) {+ if ($failures > 0) {+ //some succeeded, some failed+ return redirect()->to(Helper::getRedirectOption($request, $last_succesful_asset->id, 'Assets'))+ ->with('success-unescaped', trans_choice('admin/hardware/message.create.multi_success_linked', $successes, ['link' => route('hardware.show', ['hardware' => $last_succesful_asset->id]), 'id', 'tag' => e($last_succesful_asset->asset_tag)]))+ ->with('warning', trans_choice('admin/hardware/message.create.partial_failure', $failures));+ } else {+ if ($successes == 1) {+ //the most common case, keeping it so we don't have to make every use of that translation string be trans_choice'ed+ //and re-translated+ return redirect()->to(Helper::getRedirectOption($request, $last_succesful_asset->id, 'Assets'))+ ->with('success-unescaped', trans('admin/hardware/message.create.success_linked', ['link' => route('hardware.show', ['hardware' => $last_succesful_asset->id]), 'id', 'tag' => e($last_succesful_asset->asset_tag)]));+ } else {+ //multi-success+ return redirect()->to(Helper::getRedirectOption($request, $last_succesful_asset->id, 'Assets'))+ ->with('success-unescaped', trans_choice('admin/hardware/message.create.multi_success_linked', $successes, ['link' => route('hardware.show', ['hardware' => $last_succesful_asset->id]), 'id', 'tag' => e($last_succesful_asset->asset_tag)]));+ }+ }- return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))- ->with('success-unescaped', trans('admin/hardware/message.create.success_linked', ['link' => route('hardware.show', ['hardware' => $asset->id]), 'id', 'tag' => e($asset->asset_tag)]));--}return redirect()->back()->withInput()->withErrors($asset->getErrors());diff --git a/resources/lang/en-US/admin/hardware/message.php b/resources/lang/en-US/admin/hardware/message.phpindex 041d32f56c..a33aea1813 100644--- a/resources/lang/en-US/admin/hardware/message.php+++ b/resources/lang/en-US/admin/hardware/message.php@@ -14,6 +14,9 @@ return ['error' => 'Asset was not created, please try again. :(','success' => 'Asset created successfully. :)','success_linked' => 'Asset with tag :tag was created successfully. <strong><a href=":link" style="color: white;">Click here to view</a></strong>.',+ 'multi_success_linked' => 'Asset with tag :tag was created successfully. <strong><a href=":link" style="color: white;">Click here to view</a></strong>.|:count assets were created succesfully. The last one was :tag. <strong><a href=":link" style="color: white;">Click here to view</a></strong>.',+ 'partial_success_linked' => 'Asset with tag :tag was created successfully. <strong><a href=":link" style="color: white;">Click here to view</a></strong>.',+ 'partial_failure' => 'An asset was unable to be created.|:count assets were unable to be created.'],'update' => [