diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index d4ff0092ba..bad1947966 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -463,7 +463,7 @@ class AssetsController extends Controller { $this->authorize('view', Asset::class); $this->authorize('view', License::class); - $asset = Asset::where('id', $id)->withTrashed()->first(); + $asset = Asset::where('id', $id)->withTrashed()->firstorfail(); $licenses = $asset->licenses()->get(); return (new LicensesTransformer())->transformLicenses($licenses, $licenses->count()); diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 7f9e812ab4..8cfbec849f 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -49,6 +49,7 @@ class BulkAssetsController extends Controller ->with('settings', Setting::getSettings()) ->with('bulkedit', true) ->with('count', 0); + case 'delete': $assets = Asset::with('assignedTo', 'location')->find($asset_ids); $assets->each(function ($asset) { @@ -56,6 +57,15 @@ class BulkAssetsController extends Controller }); return view('hardware/bulk-delete')->with('assets', $assets); + + case 'restore': + $assets = Asset::withTrashed()->find($asset_ids); + $assets->each(function ($asset) { + $this->authorize('delete', $asset); + }); + + return view('hardware/bulk-restore')->with('assets', $assets); + case 'edit': return view('hardware/bulk') ->with('assets', $asset_ids) @@ -320,5 +330,18 @@ class BulkAssetsController extends Controller } catch (ModelNotFoundException $e) { return redirect()->route('hardware.bulkcheckout.show')->with('error', $e->getErrors()); } + + } + public function restore(Request $request) { + $assetIds = $request->get('ids'); + if (empty($assetIds)) { + return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.restore.nothing_updated')); + } else { + foreach ($assetIds as $key => $assetId) { + $asset = Asset::withTrashed()->find($assetId); + $asset->restore(); + } + return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.restore.success')); + } } } diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index bf47c73608..0fcbf1166c 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -60,7 +60,7 @@ class AssetImporter extends ItemImporter $asset_tag = Asset::autoincrement_asset(); } - $asset = Asset::where(['asset_tag'=> $asset_tag])->first(); + $asset = Asset::where(['asset_tag'=> (string) $asset_tag])->first(); if ($asset) { if (! $this->updating) { $this->log('A matching Asset '.$asset_tag.' already exists'); diff --git a/resources/lang/en/admin/hardware/form.php b/resources/lang/en/admin/hardware/form.php index 22aac61d07..7548983463 100644 --- a/resources/lang/en/admin/hardware/form.php +++ b/resources/lang/en/admin/hardware/form.php @@ -2,8 +2,11 @@ return [ 'bulk_delete' => 'Confirm Bulk Delete Assets', + 'bulk_restore' => 'Confirm Bulk Restore Assets', 'bulk_delete_help' => 'Review the assets for bulk deletion below. Once deleted, these assets can be restored, but they will no longer be associated with any users they are currently assigned to.', + 'bulk_restore_help' => 'Review the assets for bulk restoration below. Once restored, these assets will not be associated with any users they were previously assigned to.', 'bulk_delete_warn' => 'You are about to delete :asset_count assets.', + 'bulk_restore_warn' => 'You are about to restore :asset_count assets.', 'bulk_update' => 'Bulk Update Assets', 'bulk_update_help' => 'This form allows you to update multiple assets at once. Only fill in the fields you need to change. Any fields left blank will remain unchanged. ', 'bulk_update_warn' => 'You are about to edit the properties of a single asset.|You are about to edit the properties of :asset_count assets.', diff --git a/resources/lang/en/admin/hardware/message.php b/resources/lang/en/admin/hardware/message.php index fabbb63243..18f3b3fa24 100644 --- a/resources/lang/en/admin/hardware/message.php +++ b/resources/lang/en/admin/hardware/message.php @@ -23,6 +23,8 @@ return [ 'restore' => [ 'error' => 'Asset was not restored, please try again', 'success' => 'Asset restored successfully.', + 'bulk_success' => 'Asset restored successfully.', + 'nothing_updated' => 'No assets were selected, so nothing was restored.', ], 'audit' => [ diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 99fa3bd304..aa2e85c2fe 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -422,6 +422,8 @@ return [ 'merged_log_this_user_from' => 'Merged user ID :from_id (:from_username) into this user (ID :to_id - :to_username)', 'clear_and_save' => 'Clear & Save', 'update_existing_values' => 'Update Existing Values?', + 'auto_incrementing_asset_tags_disabled_so_tags_required' => 'Generating auto-incrementing asset tags is disabled so all rows need to have the "Asset Tag" column populated.', + 'auto_incrementing_asset_tags_enabled_so_now_assets_will_be_created' => 'Note: Generating auto-incrementing asset tags is enabled so assets will be created for rows that do not have "Asset Tag" populated. Rows that do have "Asset Tag" populated will be updated with the provided information.', 'send_welcome_email_to_users' => ' Send Welcome Email for new Users?', 'back_before_importing' => 'Backup before importing?', 'csv_header_field' => 'CSV Header Field', diff --git a/resources/views/account/accept/index.blade.php b/resources/views/account/accept/index.blade.php index f97c6c5644..f2a9bc56f2 100755 --- a/resources/views/account/accept/index.blade.php +++ b/resources/views/account/accept/index.blade.php @@ -2,7 +2,7 @@ {{-- Page title --}} @section('title') -{{ trans('general.accept_assets', array('name' => $user->present()->fullName())) }} +{{ trans('general.accept_assets', array('name' => empty($user) ? '' : $user->present()->full_name)) }} @parent @stop diff --git a/resources/views/hardware/bulk-restore.blade.php b/resources/views/hardware/bulk-restore.blade.php new file mode 100644 index 0000000000..caabe9fab8 --- /dev/null +++ b/resources/views/hardware/bulk-restore.blade.php @@ -0,0 +1,62 @@ +@extends('layouts/default') + +{{-- Page title --}} +@section('title') +{{ trans('admin/hardware/form.bulk_restore') }} +@parent +@stop + +@section('header_right') + + {{ trans('general.back') }} +@stop + +{{-- Page content --}} +@section('content') +
{{ trans('admin/hardware/form.bulk_restore_help') }}
+ +