From 7125c336fda80d17c29a4235c7576a3f4e390a00 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 7 Oct 2016 15:08:34 +0200 Subject: [PATCH] If notify settings are not set, use "send upon reception" by default see BT#11805 --- main/inc/lib/message.lib.php | 2 -- main/inc/lib/notification.lib.php | 24 +++++++++++------ main/inc/lib/usermanager.lib.php | 45 +++++++++++++++++-------------- 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/main/inc/lib/message.lib.php b/main/inc/lib/message.lib.php index fd5e759a3b..aab28530d0 100755 --- a/main/inc/lib/message.lib.php +++ b/main/inc/lib/message.lib.php @@ -235,7 +235,6 @@ class MessageManager $now = api_get_utc_datetime(); if (!empty($receiver_user_id) || !empty($group_id)) { - // message for user friend //@todo it's possible to edit a message? yes, only for groups if ($edit_message_id) { @@ -246,7 +245,6 @@ class MessageManager Database::query($query); $inbox_last_id = $edit_message_id; } else { - $params = [ 'user_sender_id' => $user_sender_id, 'user_receiver_id' => $receiver_user_id, diff --git a/main/inc/lib/notification.lib.php b/main/inc/lib/notification.lib.php index 5400a10b84..8e1bf373da 100644 --- a/main/inc/lib/notification.lib.php +++ b/main/inc/lib/notification.lib.php @@ -216,15 +216,16 @@ class Notification extends Model * NOTIFICATION_TYPE_MESSAGE, * NOTIFICATION_TYPE_INVITATION, * NOTIFICATION_TYPE_GROUP - * @param array $user_list recipients: user list of ids + * @param array $userList recipients: user list of ids * @param string $title * @param string $content - * @param array $sender_info - * result of api_get_user_info() or GroupPortalManager:get_group_data() + * @param array $senderInfo result of api_get_user_info() or GroupPortalManager:get_group_data() + * @param array $attachments + * */ public function save_notification( $type, - $user_list, + $userList, $title, $content, $senderInfo = array(), @@ -259,8 +260,8 @@ class Notification extends Model $settingInfo = UserManager::get_extra_field_information_by_name($settingToCheck); - if (!empty($user_list)) { - foreach ($user_list as $user_id) { + if (!empty($userList)) { + foreach ($userList as $user_id) { if ($avoid_my_self) { if ($user_id == api_get_user_id()) { continue; @@ -273,9 +274,16 @@ class Notification extends Model if (!empty($settingInfo)) { $extra_data = UserManager::get_extra_user_data($user_id); - if (isset($extra_data[$settingToCheck]) && !empty($extra_data[$settingToCheck])) { + + if (isset($extra_data[$settingToCheck])) { $userSetting = $extra_data[$settingToCheck]; } + + // Means that user extra was not set + // Then send email now. + if ($userSetting === '') { + $userSetting = NOTIFY_MESSAGE_AT_ONCE; + } } $sendDate = null; @@ -329,7 +337,7 @@ class Notification extends Model $this->save($params); } - self::sendPushNotification($user_list, $title, $content); + self::sendPushNotification($userList, $title, $content); } } diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index aa21241335..c42d59c4ab 100755 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -223,7 +223,7 @@ class UserManager $expirationDate = null, $active = 1, $hr_dept_id = 0, - $extra = null, + $extra = [], $encrypt_method = '', $send_mail = false, $isAdmin = false, @@ -383,12 +383,25 @@ class UserManager } if (api_get_multiple_access_url()) { - UrlManager::add_user_to_url($return, api_get_current_access_url_id()); + UrlManager::add_user_to_url($userId, api_get_current_access_url_id()); } else { //we are adding by default the access_url_user table with access_url_id = 1 - UrlManager::add_user_to_url($return, 1); + UrlManager::add_user_to_url($userId, 1); + } + + if (is_array($extra) && count($extra) > 0) { + foreach ($extra as $fname => $fvalue) { + self::update_extra_field_value($userId, $fname, $fvalue); + } + } else { + // Create notify settings by default + self::update_extra_field_value($userId, 'mail_notify_invitation', '1'); + self::update_extra_field_value($userId, 'mail_notify_message', '1'); + self::update_extra_field_value($userId, 'mail_notify_group_message', '1'); } + self::update_extra_field_value($userId, 'already_logged_in', 'false'); + if (!empty($email) && $send_mail) { $recipient_name = api_get_person_name( $firstName, @@ -483,29 +496,21 @@ class UserManager } /* ENDS MANAGE EVENT WITH MAIL */ } - Event::addEvent(LOG_USER_CREATE, LOG_USER_ID, $return); + + if (!empty($hook)) { + $hook->setEventData(array( + 'return' => $userId, + 'originalPassword' => $original_password + )); + $hook->notifyCreateUser(HOOK_EVENT_TYPE_POST); + } + Event::addEvent(LOG_USER_CREATE, LOG_USER_ID, $userId); } else { Display::addFlash(Display::return_message(get_lang('ErrorContactPlatformAdmin'))); return false; } - if (is_array($extra) && count($extra) > 0) { - $res = true; - foreach ($extra as $fname => $fvalue) { - $res = $res && self::update_extra_field_value($return, $fname, $fvalue); - } - } - self::update_extra_field_value($return, 'already_logged_in', 'false'); - - if (!empty($hook)) { - $hook->setEventData(array( - 'return' => $return, - 'originalPassword' => $original_password - )); - $hook->notifyCreateUser(HOOK_EVENT_TYPE_POST); - } - return $return; }