diff --git a/main/admin/dashboard_add_sessions_to_user.php b/main/admin/dashboard_add_sessions_to_user.php index 0a3ac96dbf..269855f887 100755 --- a/main/admin/dashboard_add_sessions_to_user.php +++ b/main/admin/dashboard_add_sessions_to_user.php @@ -155,7 +155,7 @@ $UserList = array(); if (isset($_POST['formSent']) && intval($_POST['formSent']) == 1) { $sessions_list = $_POST['SessionsList']; $userInfo = api_get_user_info($user_id); - $affected_rows = SessionManager::suscribe_sessions_to_hr_manager( + $affected_rows = SessionManager::subscribeSessionsToDrh( $userInfo, $sessions_list ); diff --git a/main/cron/import_csv.php b/main/cron/import_csv.php index 0aa54e9a94..b9d4d89f9e 100755 --- a/main/cron/import_csv.php +++ b/main/cron/import_csv.php @@ -1225,7 +1225,8 @@ class ImportCsv break; case 'drh': $userInfo = api_get_user_info($userId); - SessionManager::suscribe_sessions_to_hr_manager( + SessionManager::removeAllDrhFromSession($chamiloSessionId); + SessionManager::subscribeSessionsToDrh( $userInfo, [$chamiloSessionId], false, diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index f89e487b82..acbe00fe29 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -2922,6 +2922,29 @@ class SessionManager } } + /** + * @param int $sessionId + * @return bool + */ + public static function removeAllDrhFromSession($sessionId) + { + $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); + + $sessionId = (int) $sessionId; + + if (empty($sessionId)) { + return false; + } + + $sql = "DELETE FROM $tbl_session_rel_user + WHERE + session_id = $sessionId AND + relation_type =" . SESSION_RELATION_TYPE_RRHH; + Database::query($sql); + + return true; + } + /** * Subscribes sessions to human resource manager (Dashboard feature) * @param array $userInfo Human Resource Manager info @@ -2930,7 +2953,7 @@ class SessionManager * @param bool $removeOldConnections * @return int * */ - public static function suscribe_sessions_to_hr_manager( + public static function subscribeSessionsToDrh( $userInfo, $sessions_list, $sendEmail = false, @@ -2971,12 +2994,12 @@ class SessionManager ON (a.session_id = s.session_id) WHERE s.user_id = $userId AND - relation_type=" . SESSION_RELATION_TYPE_RRHH . " AND - access_url_id = " . api_get_current_access_url_id() . ""; + relation_type = " . SESSION_RELATION_TYPE_RRHH . " AND + access_url_id = " . api_get_current_access_url_id(); } else { $sql = "SELECT s.session_id FROM $tbl_session_rel_user s - WHERE user_id = $userId AND relation_type=" . SESSION_RELATION_TYPE_RRHH . ""; + WHERE user_id = $userId AND relation_type=" . SESSION_RELATION_TYPE_RRHH; } $result = Database::query($sql); @@ -2986,14 +3009,13 @@ class SessionManager WHERE session_id = {$row['session_id']} AND user_id = $userId AND - relation_type=" . SESSION_RELATION_TYPE_RRHH . " "; + relation_type =" . SESSION_RELATION_TYPE_RRHH; Database::query($sql); } } } // Inserting new sessions list. if (!empty($sessions_list) && is_array($sessions_list)) { - foreach ($sessions_list as $session_id) { $session_id = intval($session_id); $sql = "INSERT IGNORE INTO $tbl_session_rel_user (session_id, user_id, relation_type, registered_at) @@ -3003,7 +3025,6 @@ class SessionManager '" . SESSION_RELATION_TYPE_RRHH . "', '" . api_get_utc_datetime() . "' )"; - Database::query($sql); $affected_rows++; } @@ -5675,7 +5696,7 @@ class SessionManager $sessionList[] = $sessionInfo['session_id']; } $userInfo = $data['user_info']; - self::suscribe_sessions_to_hr_manager( + self::subscribeSessionsToDrh( $userInfo, $sessionList, $sendEmail,