Navigation Menu

Skip to content

Commit

Permalink
If notify settings are not set, use "send upon reception" by default …
Browse files Browse the repository at this point in the history
…see BT#11805
  • Loading branch information
jmontoyaa committed Oct 7, 2016
1 parent 0ce2640 commit 7125c33
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
2 changes: 0 additions & 2 deletions main/inc/lib/message.lib.php
Expand Up @@ -235,7 +235,6 @@ public static function send_message(

$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) {
Expand All @@ -246,7 +245,6 @@ public static function send_message(
Database::query($query);
$inbox_last_id = $edit_message_id;
} else {

$params = [
'user_sender_id' => $user_sender_id,
'user_receiver_id' => $receiver_user_id,
Expand Down
24 changes: 16 additions & 8 deletions main/inc/lib/notification.lib.php
Expand Up @@ -216,15 +216,16 @@ public function formatTitle($title, $senderInfo)
* 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(),
Expand Down Expand Up @@ -259,8 +260,8 @@ public function save_notification(

$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;
Expand All @@ -273,9 +274,16 @@ public function save_notification(

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;
Expand Down Expand Up @@ -329,7 +337,7 @@ public function save_notification(
$this->save($params);
}

self::sendPushNotification($user_list, $title, $content);
self::sendPushNotification($userList, $title, $content);
}
}

Expand Down
45 changes: 25 additions & 20 deletions main/inc/lib/usermanager.lib.php
Expand Up @@ -223,7 +223,7 @@ public static function create_user(
$expirationDate = null,
$active = 1,
$hr_dept_id = 0,
$extra = null,
$extra = [],
$encrypt_method = '',
$send_mail = false,
$isAdmin = false,
Expand Down Expand Up @@ -383,12 +383,25 @@ public static function create_user(
}

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,
Expand Down Expand Up @@ -483,29 +496,21 @@ public static function create_user(
}
/* 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;
}

Expand Down

0 comments on commit 7125c33

Please sign in to comment.