@@ -1971,31 +1971,31 @@ public static function edit_session(
1971
1971
*
1972
1972
* @author Carlos Vargas from existing code
1973
1973
*
1974
- * @param array $id_checked an array to delete sessions
1975
- * @param bool $from_ws optional, true if the function is called
1974
+ * @param array $idChecked an array to delete sessions
1975
+ * @param bool $fromWs optional, true if the function is called
1976
1976
* by a webservice, false otherwise
1977
1977
*
1978
1978
* @return bool
1979
1979
* */
1980
- public static function delete ($ id_checked , $ from_ws = false )
1980
+ public static function delete ($ idChecked , $ fromWs = false )
1981
1981
{
1982
1982
$ sessionId = null ;
1983
- if (is_array ($ id_checked )) {
1984
- foreach ($ id_checked as $ sessionId ) {
1983
+ if (is_array ($ idChecked )) {
1984
+ foreach ($ idChecked as $ sessionId ) {
1985
1985
self ::delete ($ sessionId );
1986
1986
}
1987
1987
} else {
1988
- $ sessionId = (int ) $ id_checked ;
1988
+ $ sessionId = (int ) $ idChecked ;
1989
1989
}
1990
1990
1991
1991
if (empty ($ sessionId )) {
1992
1992
return false ;
1993
1993
}
1994
1994
1995
- $ tbl_session_rel_course = Database::get_main_table (TABLE_MAIN_SESSION_COURSE );
1996
- $ tbl_session_rel_course_rel_user = Database::get_main_table (TABLE_MAIN_SESSION_COURSE_USER );
1997
- $ tbl_session_rel_user = Database::get_main_table (TABLE_MAIN_SESSION_USER );
1998
- $ tbl_url_session = Database::get_main_table (TABLE_MAIN_ACCESS_URL_REL_SESSION );
1995
+ $ tblSessionRelCourse = Database::get_main_table (TABLE_MAIN_SESSION_COURSE );
1996
+ $ tblSessionRelCourseRelUser = Database::get_main_table (TABLE_MAIN_SESSION_COURSE_USER );
1997
+ $ tblSessionRelUser = Database::get_main_table (TABLE_MAIN_SESSION_USER );
1998
+ $ tblUrlSession = Database::get_main_table (TABLE_MAIN_ACCESS_URL_REL_SESSION );
1999
1999
$ userGroupSessionTable = Database::get_main_table (TABLE_USERGROUP_REL_SESSION );
2000
2000
$ trackCourseAccess = Database::get_main_table (TABLE_STATISTIC_TRACK_E_COURSE_ACCESS );
2001
2001
$ trackAccess = Database::get_main_table (TABLE_STATISTIC_TRACK_E_ACCESS );
@@ -2027,7 +2027,7 @@ public static function delete($id_checked, $from_ws = false)
2027
2027
return false ;
2028
2028
}
2029
2029
2030
- if (self ::allowed ($ sessionEntity ) && !$ from_ws ) {
2030
+ if (self ::allowed ($ sessionEntity ) && !$ fromWs ) {
2031
2031
if (!$ sessionEntity ->hasUserAsSessionAdmin ($ user ) && !api_is_platform_admin ()) {
2032
2032
api_not_allowed (true );
2033
2033
}
@@ -2036,47 +2036,45 @@ public static function delete($id_checked, $from_ws = false)
2036
2036
// Delete Picture Session
2037
2037
SessionManager::deleteAsset ($ sessionId );
2038
2038
2039
- // Delete documents inside a session
2040
- $ courses = self ::getCoursesInSession ($ sessionId );
2041
- foreach ($ courses as $ courseId ) {
2042
- $ courseInfo = api_get_course_info_by_id ($ courseId );
2043
- /*DocumentManager::deleteDocumentsFromSession($courseInfo, $sessionId);
2044
- $works = Database::select(
2045
- '*',
2046
- $tbl_student_publication,
2047
- [
2048
- 'where' => ['session_id = ? AND c_id = ?' => [$sessionId, $courseId]],
2049
- ]
2050
- );
2051
-
2052
- $currentCourseRepositorySys = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/';
2053
- foreach ($works as $index => $work) {
2054
- if ($work['filetype'] = 'folder') {
2055
- Database::query("DELETE FROM $tbl_student_publication_assignment WHERE publication_id = $index");
2056
- }
2057
- my_delete($currentCourseRepositorySys.'/'.$work['url']);
2058
- }*/
2059
- }
2060
-
2061
2039
$ sessionName = $ sessionEntity ->getTitle ();
2062
2040
$ em ->remove ($ sessionEntity );
2063
2041
$ em ->flush ();
2064
2042
2065
- // Class
2066
- $ sql = "DELETE FROM $ userGroupSessionTable
2067
- WHERE session_id = $ sessionId " ;
2068
- Database::query ($ sql );
2043
+ // Delete explicitly from tables not directly related to 'session'
2044
+ $ tables = [
2045
+ 'track_e_lastaccess ' ,
2046
+ 'track_e_default ' ,
2047
+ 'track_e_exercise_confirmation ' ,
2048
+ 'track_e_links ' ,
2049
+ 'track_e_online ' ,
2050
+ 'track_e_attempt_qualify ' ,
2051
+ 'track_e_access_complete ' ,
2052
+ 'track_e_uploads ' ,
2053
+ 'track_course_ranking ' ,
2054
+ 'c_dropbox_file ' ,
2055
+ 'c_forum_thread_qualify_log ' ,
2056
+ 'c_dropbox_post ' ,
2057
+ 'c_survey_answer ' ,
2058
+ 'c_wiki_mailcue ' ,
2059
+ 'c_dropbox_category ' ,
2060
+ 'skill_rel_item ' ,
2061
+ 'scheduled_announcements ' ,
2062
+ 'sequence_row_entity ' ,
2063
+ ];
2069
2064
2070
- //Database::query("DELETE FROM $tbl_student_publication WHERE session_id = $sessionId");
2071
- Database::query ("DELETE FROM $ tbl_session_rel_course WHERE session_id = $ sessionId " );
2072
- Database::query ("DELETE FROM $ tbl_session_rel_course_rel_user WHERE session_id = $ sessionId " );
2073
- Database::query ("DELETE FROM $ tbl_session_rel_user WHERE session_id = $ sessionId " );
2074
- //Database::query("DELETE FROM $tbl_item_properties WHERE session_id = $sessionId");
2075
- Database::query ("DELETE FROM $ tbl_url_session WHERE session_id = $ sessionId " );
2076
- Database::query ("DELETE FROM $ trackCourseAccess WHERE session_id = $ sessionId " );
2077
- Database::query ("DELETE FROM $ trackAccess WHERE session_id = $ sessionId " );
2078
- $ sql = "UPDATE $ ticket SET session_id = NULL WHERE session_id = $ sessionId " ;
2079
- Database::query ($ sql );
2065
+ foreach ($ tables as $ table ) {
2066
+ Database::delete ($ table , ['session_id = ? ' => $ sessionId ]);
2067
+ }
2068
+
2069
+ // Delete other related tables
2070
+ Database::delete ($ userGroupSessionTable , ['session_id = ? ' => $ sessionId ]);
2071
+ Database::delete ($ tblSessionRelCourse , ['session_id = ? ' => $ sessionId ]);
2072
+ Database::delete ($ tblSessionRelCourseRelUser , ['session_id = ? ' => $ sessionId ]);
2073
+ Database::delete ($ tblSessionRelUser , ['session_id = ? ' => $ sessionId ]);
2074
+ Database::delete ($ tblUrlSession , ['session_id = ? ' => $ sessionId ]);
2075
+ Database::delete ($ trackCourseAccess , ['session_id = ? ' => $ sessionId ]);
2076
+ Database::delete ($ trackAccess , ['session_id = ? ' => $ sessionId ]);
2077
+ Database::update ($ ticket , ['session_id ' => null ], ['session_id = ? ' => $ sessionId ]);
2080
2078
2081
2079
$ extraFieldValue = new ExtraFieldValue ('session ' );
2082
2080
$ extraFieldValue ->deleteValuesByItem ($ sessionId );
0 commit comments