mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 22:07:29 -08:00
First pass at better-handling those annoying Rollbars we keep getting
This commit is contained in:
parent
ab0c009c0d
commit
c71411465a
|
@ -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());
|
||||
|
|
|
@ -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' => [
|
||||
|
|
Loading…
Reference in a new issue