From 71708e349c64a756f9869ce23ee1ee8498030581 Mon Sep 17 00:00:00 2001 From: snipe Date: Sun, 29 Apr 2018 06:10:49 -0700 Subject: [PATCH] PHP7.2 count fixes (#5427) * PHP 7.2 count() fixes * Re-enable php travis 7.2 --- .travis.yml | 2 +- app/Console/Commands/SendExpirationAlerts.php | 2 +- .../Api/CustomFieldsController.php | 4 +- .../Api/CustomFieldsetsController.php | 4 +- app/Http/Controllers/UsersController.php | 45 +++++++++---------- app/Http/Transformers/AssetsTransformer.php | 2 +- app/Http/Transformers/UsersTransformer.php | 2 +- resources/views/hardware/qr-view.blade.php | 4 +- resources/views/hardware/view.blade.php | 6 +-- resources/views/licenses/view.blade.php | 2 +- 10 files changed, 33 insertions(+), 40 deletions(-) diff --git a/.travis.yml b/.travis.yml index dbbc2f502d..c88afb86f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ services: php: - 5.6 - 7.0 - # - 7.2 DISABLE Temporarily until we fix the count(null) bugs + - 7.2 - 7.1.4 # execute any number of scripts before the test run, custom env's are available as variables diff --git a/app/Console/Commands/SendExpirationAlerts.php b/app/Console/Commands/SendExpirationAlerts.php index f8dfc8f0a4..759341477d 100644 --- a/app/Console/Commands/SendExpirationAlerts.php +++ b/app/Console/Commands/SendExpirationAlerts.php @@ -77,7 +77,7 @@ class SendExpirationAlerts extends Command $this->info(count($expiring_licenses).' expiring licenses'); - $license_data['count'] = count($expiring_licenses); + $license_data['count'] = $expiring_licenses->count(); $license_data['email_content'] = ''; foreach ($expiring_licenses as $license) { diff --git a/app/Http/Controllers/Api/CustomFieldsController.php b/app/Http/Controllers/Api/CustomFieldsController.php index da27ba02d2..e00ab10c66 100644 --- a/app/Http/Controllers/Api/CustomFieldsController.php +++ b/app/Http/Controllers/Api/CustomFieldsController.php @@ -26,9 +26,7 @@ class CustomFieldsController extends Controller { $this->authorize('index', CustomFields::class); $fields = CustomField::get(); - - $total = count($fields); - return (new CustomFieldsTransformer)->transformCustomFields($fields, $total); + return (new CustomFieldsTransformer)->transformCustomFields($fields, $fields->count()); } /** diff --git a/app/Http/Controllers/Api/CustomFieldsetsController.php b/app/Http/Controllers/Api/CustomFieldsetsController.php index 3855e826a0..7c21766969 100644 --- a/app/Http/Controllers/Api/CustomFieldsetsController.php +++ b/app/Http/Controllers/Api/CustomFieldsetsController.php @@ -44,9 +44,7 @@ class CustomFieldsetsController extends Controller { $this->authorize('index', CustomFieldset::class); $fieldsets = CustomFieldset::withCount(['fields', 'models'])->get(); - - $total = count($fieldsets); - return (new CustomFieldsetsTransformer)->transformCustomFieldsets($fieldsets, $total); + return (new CustomFieldsetsTransformer)->transformCustomFieldsets($fieldsets, $fieldsets->count()); } diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index ee2164f94f..01a87d190a 100755 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -392,9 +392,9 @@ class UsersController extends Controller return redirect()->route('users.index')->with('error', 'This user still has ' . $user->assets()->count() . ' assets associated with them.'); } - if (count($user->assets) > 0) { + if ($user->assets->count() > 0) { // Redirect to the user management page - return redirect()->route('users.index')->with('error', 'This user still has ' . count($user->assets) . ' assets associated with them.'); + return redirect()->route('users.index')->with('error', 'This user still has ' . count($user->assets->count()) . ' assets associated with them.'); } if ($user->licenses()->count() > 0) { @@ -438,23 +438,19 @@ class UsersController extends Controller public function postBulkEdit(Request $request) { $this->authorize('update', User::class); - if ((!Input::has('ids')) || (count(Input::input('ids')) == 0)) { - return redirect()->back()->with('error', 'No users selected'); - } else { + if (($request->has('ids')) && (count($request->input('ids')) > 0)) { $statuslabel_list = Helper::statusLabelList(); $user_raw_array = array_keys(Input::get('ids')); - $licenses = DB::table('license_seats')->whereIn('assigned_to', $user_raw_array)->get(); - $users = User::whereIn('id', $user_raw_array)->with('groups', 'assets', 'licenses', 'accessories')->get(); - if ($request->input('bulk_actions')=='edit') { - + if ($request->input('bulk_actions') == 'edit') { return view('users/bulk-edit', compact('users')) ->with('groups', Group::pluck('name', 'id')); } - return view('users/confirm-bulk-delete', compact('users', 'statuslabel_list')); } + + return redirect()->back()->with('error', 'No users selected'); } @@ -468,15 +464,13 @@ class UsersController extends Controller public function postBulkEditSave(Request $request) { $this->authorize('update', User::class); - if ((!Input::has('ids')) || (count(Input::input('ids')) == 0)) { - return redirect()->back()->with('error', 'No users selected'); - } else { - $user_raw_array = Input::get('ids'); + if (($request->has('ids')) && (count($request->input('ids')) > 0)) { + + $user_raw_array = $request->input('ids'); $update_array = array(); $manager_conflict = false; - - $users = User::whereIn('id', $user_raw_array)->where('id','!=',Auth::user()->id)->get(); + $users = User::whereIn('id', $user_raw_array)->where('id', '!=', Auth::user()->id)->get(); if ($request->has('location_id')) { $update_array['location_id'] = $request->input('location_id'); @@ -492,14 +486,12 @@ class UsersController extends Controller } - if ($request->has('manager_id')) { // Do not allow a manager update if the selected manager is one of the users being // edited. if (!array_key_exists($request->input('manager_id'), $user_raw_array)) { $update_array['manager_id'] = $request->input('manager_id'); - } else { $manager_conflict = true; } @@ -509,8 +501,9 @@ class UsersController extends Controller $update_array['activated'] = $request->input('activated'); } + // Save the updated info if (count($update_array) > 0) { - User::whereIn('id', $user_raw_array)->where('id','!=',Auth::user()->id)->update($update_array); + User::whereIn('id', $user_raw_array)->where('id', '!=', Auth::user()->id)->update($update_array); } // Only sync groups if groups were selected @@ -520,13 +513,17 @@ class UsersController extends Controller } } - } - if ($manager_conflict) { + if ($manager_conflict) { + return redirect()->route('users.index') + ->with('warning', trans('admin/users/message.bulk_manager_warn')); + } + return redirect()->route('users.index') - ->with('warning', trans('admin/users/message.bulk_manager_warn')); + ->with('success', trans('admin/users/message.success.update_bulk')); } - return redirect()->route('users.index') - ->with('success', trans('admin/users/message.success.update_bulk')); + + return redirect()->back()->with('error', 'No users selected'); + } diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index 83448e4836..5664b5fda4 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -84,7 +84,7 @@ class AssetsTransformer ]; - if (($asset->model) && ($asset->model->fieldset) && (count($asset->model->fieldset->fields)> 0)) { + if (($asset->model) && ($asset->model->fieldset) && ($asset->model->fieldset->fields->count() > 0)) { $fields_array = array(); foreach ($asset->model->fieldset->fields as $field) { diff --git a/app/Http/Transformers/UsersTransformer.php b/app/Http/Transformers/UsersTransformer.php index b40dea3cf1..569b3b56af 100644 --- a/app/Http/Transformers/UsersTransformer.php +++ b/app/Http/Transformers/UsersTransformer.php @@ -73,7 +73,7 @@ class UsersTransformer $array += $permissions_array; - $numGroups = count($user->groups); + $numGroups = $user->groups->count(); if($numGroups > 0) { $groups["total"] = $numGroups; diff --git a/resources/views/hardware/qr-view.blade.php b/resources/views/hardware/qr-view.blade.php index b06e1aa36f..047546ba79 100644 --- a/resources/views/hardware/qr-view.blade.php +++ b/resources/views/hardware/qr-view.blade.php @@ -175,7 +175,7 @@
Software Assigned

- @if (count($asset->licenses) > 0) + @if ($asset->licenses->count()) > 0) @@ -220,7 +220,7 @@ - @if (count($asset->uploads) > 0) + @if ($asset->uploads->count() > 0) @foreach ($asset->uploads as $file)
diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 9cad6abfde..489707968e 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -550,7 +550,7 @@
- @if (count($asset->licenses) > 0) + @if ($asset->licenses->count() > 0) @@ -594,7 +594,7 @@
- @if(count($asset->components) > 0) + @if($asset->components->count() > 0)
@@ -804,7 +804,7 @@ - @if (count($asset->uploads) > 0) + @if ($asset->uploads->count() > 0) @foreach ($asset->uploads as $file) - @if (count($license->uploads) > 0) + @if ($license->uploads->count()> 0) @foreach ($license->uploads as $file)
{{ trans('general.name') }}
diff --git a/resources/views/licenses/view.blade.php b/resources/views/licenses/view.blade.php index 32b16d47d7..43156bbe36 100755 --- a/resources/views/licenses/view.blade.php +++ b/resources/views/licenses/view.blade.php @@ -293,7 +293,7 @@
{{ $file->filename }}