public static function log($message, $type) { if (claro_debug_mode()) { pushClaroMessage($message, $type); } Claroline::log($type, $message); }
/** * delete a course of the plateform * * TODO detect failure with claro_failure * * @param string $cid * * @return boolean TRUE if suceed * boolean FALSE otherwise. */ function delete_course($code, $sourceCourseId) { global $eventNotifier; // Declare needed tables $tbl_mdb_names = claro_sql_get_main_tbl(); $tbl_course = $tbl_mdb_names['course']; $tbl_rel_course_user = $tbl_mdb_names['rel_course_user']; $tbl_course_class = $tbl_mdb_names['rel_course_class']; $tbl_rel_course_category = $tbl_mdb_names['rel_course_category']; $tbl_rel_course_portlet = $tbl_mdb_names['rel_course_portlet']; $this_course = claro_get_course_data($code); if (!$this_course) { // This is bad ! throw new Exception("Course not found"); } $currentCourseId = trim($this_course['sysCode']); if (empty($currentCourseId)) { // This is bad ! throw new Exception("Missing course id"); } // Delete user registrations into this course $sql = 'DELETE FROM `' . $tbl_rel_course_user . '` WHERE code_cours="' . $currentCourseId . '"'; claro_sql_query($sql); // Remove any recording in rel_cours_class $sql = "DELETE FROM `" . $tbl_course_class . "`\n WHERE courseId ='" . claro_sql_escape($currentCourseId) . "'"; claro_sql_query($sql); // Remove links between this course and categories $sql = "DELETE FROM `" . $tbl_rel_course_category . "`\n WHERE courseId ='" . $this_course['id'] . "'"; claro_sql_query($sql); // Remove links between this course and portlets $sql = "DELETE FROM `" . $tbl_rel_course_portlet . "`\n WHERE courseId ='" . $this_course['id'] . "'"; claro_sql_query($sql); // Delete the course inside the platform course registery $sql = 'DELETE FROM `' . $tbl_course . '` WHERE code= "' . claro_sql_escape($currentCourseId) . '"'; claro_sql_query($sql); // Is it a session course ? if (!is_null($sourceCourseId)) { // Does the source course still have session courses ? $sql = "SELECT COUNT(cours_id) AS nbSessionCourses\n FROM `" . $tbl_course . "`\n WHERE sourceCourseId = " . (int) $sourceCourseId; $result = claro_sql_query_get_single_row($sql); if ($result['nbSessionCourses'] == 0) { $sql = "UPDATE `" . $tbl_course . "`\n SET isSourceCourse = 0\n WHERE cours_id = " . (int) $sourceCourseId; claro_sql_query($sql); } } // Delete course right RightCourseProfileToolRight::resetAllRightProfile($currentCourseId); // Delete course module tables // FIXME handle errors list($success, $log) = delete_all_modules_from_course($currentCourseId); // Notify the course deletion event $args['cid'] = $this_course['sysCode']; $args['tid'] = null; $args['rid'] = null; $args['gid'] = null; $args['uid'] = $GLOBALS['_uid']; $eventNotifier->notifyEvent("course_deleted", $args); if ($currentCourseId == $code) { $currentCourseDbName = trim($this_course['dbName']); $currentCourseDbNameGlu = trim($this_course['dbNameGlu']); $currentCoursePath = trim($this_course['path']); if (empty($currentCourseDbName)) { // This is bad ! throw new Exception("Missing db name"); } if (empty($currentCourseDbNameGlu)) { // This is bad ! throw new Exception("Missing db name glu"); } if (get_conf('singleDbEnabled')) { // SEARCH ALL TABLES RELATED TO THE CURRENT COURSE claro_sql_query("use " . get_conf('mainDbName')); $tbl_to_delete = claro_sql_get_course_tbl(claro_get_course_db_name_glued($currentCourseId)); foreach ($tbl_to_delete as $tbl_name) { $sql = 'DROP TABLE IF EXISTS `' . $tbl_name . '`'; claro_sql_query($sql); } // Underscores must be replaced because they are used as wildcards in LIKE sql statement $cleanCourseDbNameGlu = str_replace("_", "\\_", $currentCourseDbNameGlu); $sql = 'SHOW TABLES LIKE "' . $cleanCourseDbNameGlu . '%"'; $result = claro_sql_query($sql); // DELETE ALL TABLES OF THE CURRENT COURSE $tblSurvivor = array(); while (false !== ($courseTable = mysql_fetch_array($result, MYSQL_NUM))) { $tblSurvivor[] = $courseTable[0]; //$tblSurvivor[$courseTable]='not deleted'; } if (sizeof($tblSurvivor) > 0) { Claroline::getInstance()->log('DELETE_COURSE', array_merge(array('DELETED_COURSE_CODE' => $code, 'UNDELETED_TABLE_COUNTER' => sizeof($tblSurvivor)), $tblSurvivor)); } } else { $sql = "DROP DATABASE `" . $currentCourseDbName . "`"; claro_sql_query($sql); } // MOVE THE COURSE DIRECTORY INTO THE COURSE GARBAGE COLLECTOR if (!empty($currentCoursePath)) { if (file_exists(get_conf('coursesRepositorySys') . $currentCoursePath . '/')) { claro_mkdir(get_conf('garbageRepositorySys'), CLARO_FILE_PERMISSIONS, true); rename(get_conf('coursesRepositorySys') . $currentCoursePath . '/', get_conf('garbageRepositorySys', 'garbage') . '/' . $currentCoursePath . '_' . date('YmdHis')); } else { Console::warning("DELETE_COURSE : Course directory not found {$currentCoursePath} for course {$currentCourseId}"); } Claroline::log('COURSE_DELETED', array('courseCode' => $currentCourseId, 'courseDbName' => $currentCourseDbName, 'courseDbNameGlu' => $currentCourseDbNameGlu, 'coursePath' => $currentCoursePath)); return true; } else { Console::error("DELETE_COURSE : Try to delete a course repository with no folder name {$currentCourseId} !"); return true; } } else { return false; } }
/** * Delete user form claroline platform. * * @author Mathieu Laurent <*****@*****.**> * @param int $userId * @return boolean 'true' if it succeeds, 'false' otherwise */ function user_delete($userId) { require_once dirname(__FILE__) . '/course_user.lib.php'; if (claro_get_current_user_id() == $userId) { return claro_failure::set_failure('user_cannot_remove_himself'); } // main tables name $tbl = claro_sql_get_main_tbl(); // get the list of course code where the user is subscribed $sql = "SELECT c.code AS code\n FROM `" . $tbl['rel_course_user'] . "` AS cu,\n `" . $tbl['course'] . "` AS c\n WHERE cu.code_cours = c.code\n AND cu.user_id = " . $userId; $courseList = claro_sql_query_fetch_all_cols($sql); $log = array(); if (user_remove_from_course($userId, $courseList['code'], true, true) == false) { return false; } else { foreach ($courseList['code'] as $k => $courseCode) { $log['course_' . $k] = $courseCode; } Claroline::log('UNROL_USER_COURS', array_merge(array('USER' => $userId), $log)); } $sqlList = array("DELETE FROM `" . $tbl['user'] . "` WHERE user_id = " . (int) $userId, "DELETE FROM `" . $tbl['tracking_event'] . "` WHERE user_id = " . (int) $userId, "DELETE FROM `" . $tbl['rel_class_user'] . "` WHERE user_id = " . (int) $userId, "DELETE FROM `" . $tbl['sso'] . "` WHERE user_id = " . (int) $userId, "UPDATE `" . $tbl['user'] . "` SET `creatorId` = NULL WHERE `creatorId` = " . (int) $userId); Claroline::log('USER_DELETED', array_merge(array('USER' => $userId))); foreach ($sqlList as $thisSql) { if (claro_sql_query($thisSql) == false) { return false; } else { continue; } } return true; }