From bad89422800c73859ec8648e64e2939e96b0b1fa Mon Sep 17 00:00:00 2001 From: Tim Cortesi Date: Fri, 15 Nov 2024 09:01:09 -0500 Subject: [PATCH] Add additional logging --- app/Observers/ModuleAssignmentObserver.php | 8 +-- app/Observers/WorkshopAttendanceObserver.php | 63 ++++++++------------ 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/app/Observers/ModuleAssignmentObserver.php b/app/Observers/ModuleAssignmentObserver.php index 9258bfe..d2a2fbe 100644 --- a/app/Observers/ModuleAssignmentObserver.php +++ b/app/Observers/ModuleAssignmentObserver.php @@ -35,8 +35,8 @@ public function created(ModuleAssignment $moduleAssignment) ]; try { Mail::to($user)->send(new AssignmentNotification($moduleAssignment,$user,$user_messages)); - } catch (Throwable $e) { - // keep going + } catch (\Exception $e) { + Log::error('Error sending assignment email: '.$e->getMessage()); } } } @@ -62,8 +62,8 @@ public function saved(ModuleAssignment $moduleAssignment){ ]; try { Mail::to($user)->send(new CompletionNotification($moduleAssignment,$user,$user_messages)); - } catch (Throwable $e) { - // keep going + } catch (\Exception $e) { + Log::error('Error sending completion email: '.$e->getMessage()); } } } diff --git a/app/Observers/WorkshopAttendanceObserver.php b/app/Observers/WorkshopAttendanceObserver.php index 3bc49aa..632737e 100644 --- a/app/Observers/WorkshopAttendanceObserver.php +++ b/app/Observers/WorkshopAttendanceObserver.php @@ -27,16 +27,11 @@ public function created(WorkshopAttendance $attendance) $offering = WorkshopOffering::where('id',$attendance->workshop_offering_id)->first(); $workshop = Workshop::where('id',$attendance->workshop_id)->first(); - // $offering = WorkshopOffering::where('id',$attendance)->first(); - // $workshop = $offering->workshop; - // Don't send email if the assignment template is blank if ($workshop->config != '') { $user = User::where('id',$attendance->user_id)->first(); - - // if($user->active && $user->send_email_check()){ - if($user->active ){ + if($user->active ){ $user_messages =[ 'workshop_name'=>$workshop->name, 'offering_date' =>$offering->workshop_date, @@ -44,10 +39,9 @@ public function created(WorkshopAttendance $attendance) ]; try { - Mail::to($user)->send(new WorkshopNotification($attendance,$user,$user_messages)); } catch (\Exception $e) { - dd($e); + Log::error('Error sending workshop notification email: '.$e->getMessage()); } } } @@ -60,34 +54,28 @@ public function created(WorkshopAttendance $attendance) */ public function deleted(WorkshopAttendance $attendance) { - - // if($attendance->deleted_at != NULL){ - $offering = WorkshopOffering::where('id',$attendance->workshop_offering_id)->first(); - $workshop = Workshop::where('id',$attendance->workshop_id)->first(); + $offering = WorkshopOffering::where('id',$attendance->workshop_offering_id)->first(); + $workshop = Workshop::where('id',$attendance->workshop_id)->first(); + + // Don't send email if the assignment template is blank + if ($workshop->config != '') { - // Don't send email if the assignment template is blank - if ($workshop->config != '') { - - $user = User::where('id',$attendance->user_id)->first(); + $user = User::where('id',$attendance->user_id)->first(); - // if($user->active && $user->send_email_check()){ - if($user->active ){ - $user_messages =[ - 'workshop_name'=>$workshop->name, - 'offering_date' =>$offering->workshop_date, - 'notification'=> $workshop->config->unregister - ]; - - try { - - Mail::to($user)->send(new WorkshopNotification($attendance,$user,$user_messages)); - } catch (\Exception $e) { - dd($e); - } + if($user->active ){ + $user_messages =[ + 'workshop_name'=>$workshop->name, + 'offering_date' =>$offering->workshop_date, + 'notification'=> $workshop->config->unregister + ]; + + try { + Mail::to($user)->send(new WorkshopNotification($attendance,$user,$user_messages)); + } catch (\Exception $e) { + Log::error('Error sending workshop notification email: '.$e->getMessage()); } } - // } - + } } /** @@ -98,8 +86,8 @@ public function deleted(WorkshopAttendance $attendance) */ public function updated(WorkshopAttendance $attendance){ - //when user status changes to completed - if($attendance->status == 'completed'){ + //when user status changes to completed + if($attendance->status == 'completed'){ $offering = WorkshopOffering::where('id',$attendance->workshop_offering_id)->first(); $workshop = Workshop::where('id',$attendance->workshop_id)->first(); @@ -107,9 +95,7 @@ public function updated(WorkshopAttendance $attendance){ if ($workshop->config != '') { $user = User::where('id',$attendance->user_id)->first(); - - // if($user->active && $user->send_email_check()){ - if($user->active ){ + if($user->active ){ $user_messages =[ 'workshop_name'=>$workshop->name, 'offering_date' =>$offering->workshop_date, @@ -117,10 +103,9 @@ public function updated(WorkshopAttendance $attendance){ ]; try { - Mail::to($user)->send(new WorkshopNotification($attendance,$user,$user_messages)); } catch (\Exception $e) { - dd($e); + Log::error('Error sending workshop notification email: '.$e->getMessage()); } } }