From 8e60767c00bf749a53d73c87096371f54a19ba4a Mon Sep 17 00:00:00 2001 From: Daniel Meltzer Date: Wed, 12 Oct 2016 14:06:38 -0500 Subject: [PATCH] Guard against null values in the reports generator. May fix #2758 (#2762) --- app/Http/Controllers/ReportsController.php | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index a996f52539..ef896fa9f5 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -367,14 +367,30 @@ class ReportsController extends Controller if (($activity->user) && ($activity->action_type=="uploaded") && ($activity->itemType()=="user")) { $activity_target = ''.$activity->user->fullName().''; - } elseif (($activity->item) && ($activity->target_type === "App\Models\Asset")) { - $activity_target = ''.$activity->target->showAssetName().''; + } elseif ($activity->target_type === "App\Models\Asset") { + if($activity->target) { + $activity_target = ''.$activity->target->showAssetName().''; + } else { + $activity_target = "Unknown Item"; + } } elseif ( $activity->target_type === "App\Models\User") { - $activity_target = ''.$activity->target->fullName().''; + if($activity->target()) { + $activity_target = ''.$activity->target->fullName().''; + } else { + $activity_target = 'Unknown User'; + } } elseif ($activity->action_type=='requested') { - $activity_target = ''.$activity->user->fullName().''; + if ($activity->user) { + $activity_target = ''.$activity->user->fullName().''; + } else { + $activity_target = 'Unknown User'; + } } else { - $activity_target = $activity->target->id; + if($activity->target) { + $activity_target = $activity->target->id; + } else { + $activity_target = "Unknown"; + } }