From d29cb1acaf214b5914e0649892a347c64a808c2c Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 23 Aug 2018 10:00:25 +0200 Subject: [PATCH] Fix: Mail notifications arrive again (#5654) * Fix: Mail notifications arrive again * Ensure that user data is always there --- include/enotify.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/include/enotify.php b/include/enotify.php index 0ef3c56765..70abce5845 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -32,6 +32,20 @@ function notification($params) logger('Missing parameters.' . System::callstack()); } + // Ensure that the important fields are set at any time + $fields = ['notify-flags', 'language', 'username', 'email']; + $user = DBA::selectFirst('user', $fields, ['uid' => $params['uid']]); + + if (!DBA::isResult($user)) { + logger('Unknown user ' . $params['uid']); + return; + } + + $params['notify_flags'] = defaults($params, 'notify_flags', $user['notify-flags']); + $params['language'] = defaults($params, 'language', $user['language']); + $params['to_name'] = defaults($params, 'to_name', $user['username']); + $params['to_email'] = defaults($params, 'to_email', $user['email']); + // from here on everything is in the recipients language L10n::pushLang($params['language']); @@ -510,7 +524,7 @@ function notification($params) } // send email notification if notification preferences permit - if ((!empty($params['notify_flags']) & intval($params['type'])) + if ((intval($params['notify_flags']) & intval($params['type'])) || $params['type'] == NOTIFY_SYSTEM || $params['type'] == SYSTEM_EMAIL) { @@ -661,7 +675,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") { $profiles = $notification_data["profiles"]; - $fields = ['notify-flags', 'language', 'username', 'email', 'nickname']; + $fields = ['nickname']; $user = DBA::selectFirst('user', $fields, ['uid' => $uid]); if (!DBA::isResult($user)) { return false; @@ -724,10 +738,6 @@ function check_item_notification($itemid, $uid, $defaulttype = "") { // Generate the notification array $params = []; $params["uid"] = $uid; - $params["notify_flags"] = $user["notify-flags"]; - $params["language"] = $user["language"]; - $params["to_name"] = $user["username"]; - $params["to_email"] = $user["email"]; $params["item"] = $item; $params["parent"] = $item["parent"]; $params["link"] = System::baseUrl().'/display/'.urlencode($item["guid"]); -- 2.39.5