From a14a21fa495f9433e45d988497106ee6f9f23ef8 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sat, 1 Aug 2020 15:10:07 +0200 Subject: [PATCH] * Tracker/Notifications: send mail after response to user and push errors --- api/src/Storage/Tracking.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/api/src/Storage/Tracking.php b/api/src/Storage/Tracking.php index f07d9ec90e..8c82978d48 100644 --- a/api/src/Storage/Tracking.php +++ b/api/src/Storage/Tracking.php @@ -846,10 +846,25 @@ abstract class Tracking { $notification->set_attachments($attachments); } - $notification->send(); + // run immediatly during async service, as sending mail with Horde fails, if PHP is already in shutdown + // (json requests take care of that by calling Egw::__desctruct() explicit before it's regular triggered) + $run = isset($GLOBALS['egw_info']['flags']['async-service']) ? 'call_user_func_array' : Api\Egw::class.'::on_shutdown'; + $run(static function($notification, $sender, $receiver, $subject) + { + $notification->send(); - // Notification can (partially) succeed and still generate errors - $this->errors += $notification->errors(); + // Notification can (partially) succeed and still generate errors + foreach($notification->errors(true) as $error) + { + error_log(__METHOD__."() Error notifying $receiver from $sender: $subject: $error"); + // send notification errors via push to current user (not session, as alarms send via async job have none!) + (new Api\Json\Push($GLOBALS['egw_info']['user']['account_id']))->message( + lang('Error notifying %1', !is_numeric($receiver) ? $receiver : + Api\Accounts::id2name($receiver, 'account_fullname').' <'.Api\Accounts::id2name($receiver, 'account_email').'>'). + "\n".$subject."\n".$error, 'error'); + + } + }, [$notification, $sender, $receiver, $subject]); } catch (Exception $exception) {