From 562385c69e04c89b349aa613b07b6080350da32d Mon Sep 17 00:00:00 2001 From: SinergiaCRM Date: Tue, 28 Jan 2025 16:26:51 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20salesagility#10630=20-=20Scheduled=20task?= =?UTF-8?q?=20=E2=80=9CRun=20Email=20Reminder=20Notifications=E2=80=9D=20d?= =?UTF-8?q?oes=20not=20run=20when=20deleting=20a=20person?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/Reminders/Reminder.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/modules/Reminders/Reminder.php b/modules/Reminders/Reminder.php index 0b945c2568b..ecc6e16b7fa 100644 --- a/modules/Reminders/Reminder.php +++ b/modules/Reminders/Reminder.php @@ -239,14 +239,19 @@ private static function getEmailReminderInviteesRecipients($reminderId, $checkDe $inviteeModuleId = $invitee->related_invitee_module_id; $personBean = BeanFactory::getBean($inviteeModule, $inviteeModuleId); // The original email reminders check the accept_status field in related users/leads/contacts etc. and filtered these users who not decline this event. - if ($checkDecline && !self::isDecline($event, $personBean)) { - if (!empty($personBean->email1)) { - $arr = array( - 'type' => $inviteeModule, - 'name' => $personBean->full_name, - 'email' => $personBean->email1, - ); - $emails[] = $arr; + + // Avoid sending the reminder to any guest if the guest does not already exist in the CRM, as it causes an error that prevents the “Run Email Reminder Notifications” task from finishing correctly + // Prevent a deleted contact, user, etc. from being deleted in order for the task to run + if($personBean != false) { + if ($checkDecline && !self::isDecline($event, $personBean)) { + if (!empty($personBean->email1)) { + $arr = array( + 'type' => $inviteeModule, + 'name' => $personBean->full_name, + 'email' => $personBean->email1, + ); + $emails[] = $arr; + } } } } @@ -265,7 +270,9 @@ private static function getUnsentEmailReminders() if ($eventBean) { $remind_ts = $timedate->fromUser($eventBean->date_start)->modify("-{$reminderBean->timer_email} seconds")->ts; $now_ts = $timedate->getNow()->ts; - if ($now_ts >= $remind_ts) { + // Do not send a reminder if the meeting has already taken place + $event_ts = $timedate->fromUser($eventBean->date_start)->ts; + if ($now_ts >= $remind_ts && $now_ts <= $event_ts) { $reminders[$reminderBean->id] = $reminderBean; } } else {