PHP7.2 count fixes (#5427)

* PHP 7.2 count() fixes

* Re-enable php travis 7.2
This commit is contained in:
snipe 2018-04-29 06:10:49 -07:00 committed by GitHub
parent 6ad3d40216
commit 71708e349c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 33 additions and 40 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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());
}
/**

View file

@ -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());
}

View file

@ -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');
}

View file

@ -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) {

View file

@ -73,7 +73,7 @@ class UsersTransformer
$array += $permissions_array;
$numGroups = count($user->groups);
$numGroups = $user->groups->count();
if($numGroups > 0)
{
$groups["total"] = $numGroups;

View file

@ -175,7 +175,7 @@
<h6>Software Assigned </h6>
<br>
<!-- checked out assets table -->
@if (count($asset->licenses) > 0)
@if ($asset->licenses->count()) > 0)
<table class="table table-hover">
<thead>
<tr>
@ -220,7 +220,7 @@
</tr>
</thead>
<tbody>
@if (count($asset->uploads) > 0)
@if ($asset->uploads->count() > 0)
@foreach ($asset->uploads as $file)
<tr>
<td>

View file

@ -550,7 +550,7 @@
<div class="row">
<div class="col-md-12">
<!-- Licenses assets table -->
@if (count($asset->licenses) > 0)
@if ($asset->licenses->count() > 0)
<table class="table">
<thead>
<tr>
@ -594,7 +594,7 @@
<!-- checked out assets table -->
<div class="row">
<div class="col-md-12">
@if(count($asset->components) > 0)
@if($asset->components->count() > 0)
<table class="table table-striped">
<thead>
<th>{{ trans('general.name') }}</th>
@ -804,7 +804,7 @@
</tr>
</thead>
<tbody>
@if (count($asset->uploads) > 0)
@if ($asset->uploads->count() > 0)
@foreach ($asset->uploads as $file)
<tr>
<td>

View file

@ -293,7 +293,7 @@
</tr>
</thead>
<tbody>
@if (count($license->uploads) > 0)
@if ($license->uploads->count()> 0)
@foreach ($license->uploads as $file)
<tr>
<td>{{ $file->filename }}</td>