diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 5abb137f87..24fd99d256 100644 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -2245,11 +2245,13 @@ class SessionManager { * @params int new session id * @params int see SessionManager::get_session_change_user_reasons() */ - static function change_user_session($user_id, $old_session_id, $new_session_id, $reason_id) { - if (!empty($user_id) && !empty($old_session_id) && !empty($new_session_id)) { + static function change_user_session($user_id, $old_session_id, $new_session_id=null, $reason_id) { + if (!empty($user_id) && !empty($old_session_id)) { $user_id = intval($user_id); $old_session_id = intval($old_session_id); - $new_session_id = intval($new_session_id); + if (!empty($new_session_id)) { + $new_session_id = intval($new_session_id); + } $reason_id = intval($reason_id); //self::unsubscribe_user_from_session($old_session_id, $user_id, $reason_id); @@ -2282,7 +2284,7 @@ class SessionManager { switch ($reason_id) { case self::SESSION_CHANGE_USER_REASON_SCHEDULE: case self::SESSION_CHANGE_USER_REASON_CLASSROOM: - case self::SESSION_CHANGE_USER_REASON_LOCATION: + case self::SESSION_CHANGE_USER_REASON_LOCATION: //Adding to the new session self::suscribe_users_to_session($new_session_id, array($user_id), null, false); @@ -2298,8 +2300,8 @@ class SessionManager { $now = api_get_utc_datetime(); //Setting the moved_status - $sql = "UPDATE $tbl_session_rel_user SET moved_status = $reason_id, moved_at = '$now' - WHERE id_session = '$old_session_id' AND id_user ='$user_id'"; + $sql = "UPDATE $tbl_session_rel_user SET moved_status = $reason_id, moved_at = '$now' ". + "WHERE id_session = '$old_session_id' AND id_user ='$user_id'"; Database::query($sql); return true; @@ -2687,4 +2689,4 @@ class SessionManager { ); return $return_array; } -} \ No newline at end of file +} diff --git a/tests/migrate/migration.custom.class.php b/tests/migrate/migration.custom.class.php index b11a54d486..9dd5e55c8b 100644 --- a/tests/migrate/migration.custom.class.php +++ b/tests/migrate/migration.custom.class.php @@ -889,8 +889,9 @@ class MigrationCustom { if (!empty($session_id)) { $before = SessionManager::get_user_status_in_session($session_id, $user_id); //SessionManager::suscribe_users_to_session($session_id, array($user_id), SESSION_VISIBLE_READ_ONLY, false, false); - SessionManager::unsubscribe_user_from_session($session_id, $user_id); - $message = "Move Session to empty"; + //SessionManager::unsubscribe_user_from_session($session_id, $user_id); + SessionManager::change_user_session($user_id, $session_id, null, 4); + $message = "Move Session to empty (cancelled subscription)"; return self::check_if_user_is_subscribe_to_session($user_id, $session_id, $message, $before); } else { return array(