|
@@ -15,15 +15,15 @@ class CourseRecycler
|
|
*/
|
|
*/
|
|
public $course;
|
|
public $course;
|
|
public $type;
|
|
public $type;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Create a new CourseRecycler
|
|
* Create a new CourseRecycler
|
|
* @param course $course The course-object which contains the items to
|
|
* @param course $course The course-object which contains the items to
|
|
* delete
|
|
* delete
|
|
*/
|
|
*/
|
|
function CourseRecycler($course) {
|
|
function CourseRecycler($course) {
|
|
- $this->course = $course;
|
|
|
|
- $this->course_info = api_get_course_info($this->course->code);
|
|
|
|
|
|
+ $this->course = $course;
|
|
|
|
+ $this->course_info = api_get_course_info($this->course->code);
|
|
$this->course_id = $this->course_info['real_id'];
|
|
$this->course_id = $this->course_info['real_id'];
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
@@ -36,7 +36,7 @@ class CourseRecycler
|
|
function recycle($type) {
|
|
function recycle($type) {
|
|
if (empty($type)) { return false; }
|
|
if (empty($type)) { return false; }
|
|
$this->type = $type;
|
|
$this->type = $type;
|
|
-
|
|
|
|
|
|
+
|
|
$table_tool_intro = Database::get_course_table(TABLE_TOOL_INTRO);
|
|
$table_tool_intro = Database::get_course_table(TABLE_TOOL_INTRO);
|
|
$table_linked_resources = Database::get_course_table(TABLE_LINKED_RESOURCES);
|
|
$table_linked_resources = Database::get_course_table(TABLE_LINKED_RESOURCES);
|
|
$table_item_properties = Database::get_course_table(TABLE_ITEM_PROPERTY);
|
|
$table_item_properties = Database::get_course_table(TABLE_ITEM_PROPERTY);
|
|
@@ -78,7 +78,7 @@ class CourseRecycler
|
|
function recycle_documents() {
|
|
function recycle_documents() {
|
|
if ($this->course->has_resources(RESOURCE_DOCUMENT)) {
|
|
if ($this->course->has_resources(RESOURCE_DOCUMENT)) {
|
|
$table = Database :: get_course_table(TABLE_DOCUMENT);
|
|
$table = Database :: get_course_table(TABLE_DOCUMENT);
|
|
- foreach ($this->course->resources[RESOURCE_DOCUMENT] as $id => $document) {
|
|
|
|
|
|
+ foreach ($this->course->resources[RESOURCE_DOCUMENT] as $id => $document) {
|
|
rmdirr($this->course->backup_path.'/'.$document->path);
|
|
rmdirr($this->course->backup_path.'/'.$document->path);
|
|
}
|
|
}
|
|
$ids = implode(',', (array_keys($this->course->resources[RESOURCE_DOCUMENT])));
|
|
$ids = implode(',', (array_keys($this->course->resources[RESOURCE_DOCUMENT])));
|
|
@@ -134,12 +134,12 @@ class CourseRecycler
|
|
Database::query($sql);
|
|
Database::query($sql);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Delete forums
|
|
* Delete forums
|
|
*/
|
|
*/
|
|
function recycle_forums() {
|
|
function recycle_forums() {
|
|
-
|
|
|
|
|
|
+
|
|
$table_category = Database :: get_course_table(TABLE_FORUM_CATEGORY);
|
|
$table_category = Database :: get_course_table(TABLE_FORUM_CATEGORY);
|
|
$table_forum = Database :: get_course_table(TABLE_FORUM);
|
|
$table_forum = Database :: get_course_table(TABLE_FORUM);
|
|
$table_thread = Database :: get_course_table(TABLE_FORUM_THREAD);
|
|
$table_thread = Database :: get_course_table(TABLE_FORUM_THREAD);
|
|
@@ -149,9 +149,9 @@ class CourseRecycler
|
|
$table_mail_queue = Database::get_course_table(TABLE_FORUM_MAIL_QUEUE);
|
|
$table_mail_queue = Database::get_course_table(TABLE_FORUM_MAIL_QUEUE);
|
|
$table_thread_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY);
|
|
$table_thread_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY);
|
|
$table_thread_qualify_log = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY_LOG);
|
|
$table_thread_qualify_log = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY_LOG);
|
|
-
|
|
|
|
|
|
+
|
|
if ($this->type == 'full_backup') {
|
|
if ($this->type == 'full_backup') {
|
|
- $sql = "DELETE FROM ".$table_category." WHERE c_id = ".$this->course_id;
|
|
|
|
|
|
+ $sql = "DELETE FROM ".$table_category." WHERE c_id = ".$this->course_id;
|
|
Database::query($sql);
|
|
Database::query($sql);
|
|
$sql = "DELETE FROM ".$table_forum." WHERE c_id = ".$this->course_id;
|
|
$sql = "DELETE FROM ".$table_forum." WHERE c_id = ".$this->course_id;
|
|
Database::query($sql);
|
|
Database::query($sql);
|
|
@@ -166,29 +166,29 @@ class CourseRecycler
|
|
$sql = "DELETE FROM ".$table_mail_queue." WHERE c_id = ".$this->course_id;
|
|
$sql = "DELETE FROM ".$table_mail_queue." WHERE c_id = ".$this->course_id;
|
|
Database::query($sql);
|
|
Database::query($sql);
|
|
$sql = "DELETE FROM ".$table_thread_qualify." WHERE c_id = ".$this->course_id;
|
|
$sql = "DELETE FROM ".$table_thread_qualify." WHERE c_id = ".$this->course_id;
|
|
- Database::query($sql);
|
|
|
|
|
|
+ Database::query($sql);
|
|
$sql = "DELETE FROM ".$table_thread_qualify_log." WHERE c_id = ".$this->course_id;
|
|
$sql = "DELETE FROM ".$table_thread_qualify_log." WHERE c_id = ".$this->course_id;
|
|
Database::query($sql);
|
|
Database::query($sql);
|
|
-
|
|
|
|
|
|
+
|
|
$sql = "DELETE FROM ".$table_thread_qualify_log." WHERE c_id = ".$this->course_id;
|
|
$sql = "DELETE FROM ".$table_thread_qualify_log." WHERE c_id = ".$this->course_id;
|
|
Database::query($sql);
|
|
Database::query($sql);
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
- if ($this->course->has_resources(RESOURCE_FORUMCATEGORY)) {
|
|
|
|
|
|
+
|
|
|
|
+ if ($this->course->has_resources(RESOURCE_FORUMCATEGORY)) {
|
|
$forum_ids = implode(',', (array_keys($this->course->resources[RESOURCE_FORUMCATEGORY])));
|
|
$forum_ids = implode(',', (array_keys($this->course->resources[RESOURCE_FORUMCATEGORY])));
|
|
$sql = "DELETE FROM ".$table_category." WHERE c_id = ".$this->course_id." AND cat_id IN(".$forum_ids.");";
|
|
$sql = "DELETE FROM ".$table_category." WHERE c_id = ".$this->course_id." AND cat_id IN(".$forum_ids.");";
|
|
- Database::query($sql);
|
|
|
|
|
|
+ Database::query($sql);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if ($this->course->has_resources(RESOURCE_FORUM)) {
|
|
if ($this->course->has_resources(RESOURCE_FORUM)) {
|
|
-
|
|
|
|
|
|
+
|
|
$forum_ids = implode(',', (array_keys($this->course->resources[RESOURCE_FORUM])));
|
|
$forum_ids = implode(',', (array_keys($this->course->resources[RESOURCE_FORUM])));
|
|
|
|
|
|
$sql = "DELETE FROM $table_attachment USING $table_attachment
|
|
$sql = "DELETE FROM $table_attachment USING $table_attachment
|
|
- INNER JOIN $table_post
|
|
|
|
- WHERE ".$table_post.".c_id = ".$this->course_id." AND
|
|
|
|
- ".$table_attachment.".c_id = ".$this->course_id." AND
|
|
|
|
|
|
+ INNER JOIN $table_post
|
|
|
|
+ WHERE ".$table_post.".c_id = ".$this->course_id." AND
|
|
|
|
+ ".$table_attachment.".c_id = ".$this->course_id." AND
|
|
".$table_attachment.".post_id = ".$table_post.".post_id".
|
|
".$table_attachment.".post_id = ".$table_post.".post_id".
|
|
" AND ".$table_post.".forum_id IN(".$forum_ids.");";
|
|
" AND ".$table_post.".forum_id IN(".$forum_ids.");";
|
|
Database::query($sql);
|
|
Database::query($sql);
|
|
@@ -229,9 +229,9 @@ class CourseRecycler
|
|
$sql = "DELETE FROM ".$table_forum." WHERE c_id = ".$this->course_id." AND forum_id IN(".$forum_ids.")";
|
|
$sql = "DELETE FROM ".$table_forum." WHERE c_id = ".$this->course_id." AND forum_id IN(".$forum_ids.")";
|
|
Database::query($sql);
|
|
Database::query($sql);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Delete forum-categories
|
|
* Delete forum-categories
|
|
* Deletes all forum-categories from current course without forums
|
|
* Deletes all forum-categories from current course without forums
|
|
@@ -239,16 +239,16 @@ class CourseRecycler
|
|
function recycle_forum_categories() {
|
|
function recycle_forum_categories() {
|
|
$table_forum = Database :: get_course_table(TABLE_FORUM);
|
|
$table_forum = Database :: get_course_table(TABLE_FORUM);
|
|
$table_forumcat = Database :: get_course_table(TABLE_FORUM_CATEGORY);
|
|
$table_forumcat = Database :: get_course_table(TABLE_FORUM_CATEGORY);
|
|
- $sql = "SELECT fc.cat_id FROM ".$table_forumcat." fc
|
|
|
|
- LEFT JOIN ".$table_forum." f ON fc.cat_id=f.forum_category AND fc.c_id = ".$this->course_id." AND f.c_id = ".$this->course_id."
|
|
|
|
- WHERE f.forum_id IS NULL";
|
|
|
|
|
|
+ $sql = "SELECT fc.cat_id FROM ".$table_forumcat." fc
|
|
|
|
+ LEFT JOIN ".$table_forum." f ON fc.cat_id=f.forum_category AND fc.c_id = ".$this->course_id." AND f.c_id = ".$this->course_id."
|
|
|
|
+ WHERE f.forum_id IS NULL";
|
|
$res = Database::query($sql);
|
|
$res = Database::query($sql);
|
|
while ($obj = Database::fetch_object($res)) {
|
|
while ($obj = Database::fetch_object($res)) {
|
|
$sql = "DELETE FROM ".$table_forumcat." WHERE c_id = ".$this->course_id." AND cat_id = ".$obj->cat_id;
|
|
$sql = "DELETE FROM ".$table_forumcat." WHERE c_id = ".$this->course_id." AND cat_id = ".$obj->cat_id;
|
|
Database::query($sql);
|
|
Database::query($sql);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Delete link-categories
|
|
* Delete link-categories
|
|
* Deletes all empty link-categories (=without links) from current course
|
|
* Deletes all empty link-categories (=without links) from current course
|
|
@@ -256,9 +256,9 @@ class CourseRecycler
|
|
function recycle_link_categories() {
|
|
function recycle_link_categories() {
|
|
$link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY);
|
|
$link_cat_table = Database :: get_course_table(TABLE_LINK_CATEGORY);
|
|
$link_table = Database :: get_course_table(TABLE_LINK);
|
|
$link_table = Database :: get_course_table(TABLE_LINK);
|
|
- $sql = "SELECT lc.id FROM ".$link_cat_table." lc
|
|
|
|
- LEFT JOIN ".$link_table." l
|
|
|
|
- ON lc.id=l.category_id AND lc.c_id = ".$this->course_id." AND l.c_id = ".$this->course_id."
|
|
|
|
|
|
+ $sql = "SELECT lc.id FROM ".$link_cat_table." lc
|
|
|
|
+ LEFT JOIN ".$link_table." l
|
|
|
|
+ ON lc.id=l.category_id AND lc.c_id = ".$this->course_id." AND l.c_id = ".$this->course_id."
|
|
WHERE l.id IS NULL";
|
|
WHERE l.id IS NULL";
|
|
$res = Database::query($sql);
|
|
$res = Database::query($sql);
|
|
while ($obj = Database::fetch_object($res)) {
|
|
while ($obj = Database::fetch_object($res)) {
|
|
@@ -266,7 +266,7 @@ class CourseRecycler
|
|
Database::query($sql);
|
|
Database::query($sql);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Delete events
|
|
* Delete events
|
|
*/
|
|
*/
|
|
@@ -299,7 +299,7 @@ class CourseRecycler
|
|
Database::query($sql);
|
|
Database::query($sql);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Recycle quizzes - doesn't remove the questions and their answers, as they might still be used later
|
|
* Recycle quizzes - doesn't remove the questions and their answers, as they might still be used later
|
|
*/
|
|
*/
|
|
@@ -319,13 +319,15 @@ class CourseRecycler
|
|
// This value is set in CourseBuilder::quiz_build_questions()
|
|
// This value is set in CourseBuilder::quiz_build_questions()
|
|
$delete_orphan_questions = in_array(-1, $ids);
|
|
$delete_orphan_questions = in_array(-1, $ids);
|
|
$ids = implode(',', $ids);
|
|
$ids = implode(',', $ids);
|
|
-
|
|
|
|
- // Deletion of the tests first. Questions in these tests are
|
|
|
|
- // not deleted and become orphan at this point
|
|
|
|
- $sql = "DELETE FROM ".$table_qui." WHERE c_id = ".$this->course_id." AND id IN(".$ids.")";
|
|
|
|
- Database::query($sql);
|
|
|
|
- $sql = "DELETE FROM ".$table_rel." WHERE c_id = ".$this->course_id." AND exercice_id IN(".$ids.")";
|
|
|
|
- Database::query($sql);
|
|
|
|
|
|
+
|
|
|
|
+ if (!empty($ids)) {
|
|
|
|
+ // Deletion of the tests first. Questions in these tests are
|
|
|
|
+ // not deleted and become orphan at this point
|
|
|
|
+ $sql = "DELETE FROM ".$table_qui." WHERE c_id = ".$this->course_id." AND id IN(".$ids.")";
|
|
|
|
+ Database::query($sql);
|
|
|
|
+ $sql = "DELETE FROM ".$table_rel." WHERE c_id = ".$this->course_id." AND exercice_id IN(".$ids.")";
|
|
|
|
+ Database::query($sql);
|
|
|
|
+ }
|
|
|
|
|
|
// Identifying again and deletion of the orphan questions, if it was desired.
|
|
// Identifying again and deletion of the orphan questions, if it was desired.
|
|
if ($delete_orphan_questions) {
|
|
if ($delete_orphan_questions) {
|
|
@@ -340,7 +342,7 @@ class CourseRecycler
|
|
' quizz_questions.c_id = '.$this->course_id.' AND '.
|
|
' quizz_questions.c_id = '.$this->course_id.' AND '.
|
|
' exercices.c_id = '.$this->course_id.' AND '.
|
|
' exercices.c_id = '.$this->course_id.' AND '.
|
|
' quizz_questions.exercice_id IS NULL OR '.
|
|
' quizz_questions.exercice_id IS NULL OR '.
|
|
- ' exercices.active = -1';
|
|
|
|
|
|
+ ' exercices.active = -1';
|
|
// active = -1 means "deleted" test.
|
|
// active = -1 means "deleted" test.
|
|
$db_result = Database::query($sql);
|
|
$db_result = Database::query($sql);
|
|
if (Database::num_rows($db_result) > 0) {
|
|
if (Database::num_rows($db_result) > 0) {
|
|
@@ -367,10 +369,10 @@ class CourseRecycler
|
|
// Quizzes previously deleted are, in fact, kept with a status
|
|
// Quizzes previously deleted are, in fact, kept with a status
|
|
// (active field) of "-1". Delete those, now.
|
|
// (active field) of "-1". Delete those, now.
|
|
$sql = "DELETE FROM ".$table_qui." WHERE c_id = ".$this->course_id." AND active = -1";
|
|
$sql = "DELETE FROM ".$table_qui." WHERE c_id = ".$this->course_id." AND active = -1";
|
|
- Database::query($sql);
|
|
|
|
|
|
+ Database::query($sql);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Recycle surveys - removes everything
|
|
* Recycle surveys - removes everything
|
|
*/
|
|
*/
|
|
@@ -405,7 +407,7 @@ class CourseRecycler
|
|
$table_iv = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
|
|
$table_iv = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
|
|
$table_iv_int = Database::get_course_table(TABLE_LP_IV_INTERACTION);
|
|
$table_iv_int = Database::get_course_table(TABLE_LP_IV_INTERACTION);
|
|
$table_tool = Database::get_course_table(TABLE_TOOL_LIST);
|
|
$table_tool = Database::get_course_table(TABLE_TOOL_LIST);
|
|
-
|
|
|
|
|
|
+
|
|
foreach($this->course->resources[RESOURCE_LEARNPATH] as $id => $learnpath) {
|
|
foreach($this->course->resources[RESOURCE_LEARNPATH] as $id => $learnpath) {
|
|
// See task #875.
|
|
// See task #875.
|
|
if ($learnpath->lp_type == 2) {
|
|
if ($learnpath->lp_type == 2) {
|
|
@@ -469,17 +471,17 @@ class CourseRecycler
|
|
$table_thematic = Database :: get_course_table(TABLE_THEMATIC);
|
|
$table_thematic = Database :: get_course_table(TABLE_THEMATIC);
|
|
$table_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE);
|
|
$table_thematic_advance = Database :: get_course_table(TABLE_THEMATIC_ADVANCE);
|
|
$table_thematic_plan = Database :: get_course_table(TABLE_THEMATIC_PLAN);
|
|
$table_thematic_plan = Database :: get_course_table(TABLE_THEMATIC_PLAN);
|
|
-
|
|
|
|
|
|
+
|
|
$resources = $this->course->resources;
|
|
$resources = $this->course->resources;
|
|
foreach ($resources[RESOURCE_THEMATIC] as $last_id => $thematic) {
|
|
foreach ($resources[RESOURCE_THEMATIC] as $last_id => $thematic) {
|
|
if (is_numeric($last_id)) {
|
|
if (is_numeric($last_id)) {
|
|
-
|
|
|
|
|
|
+
|
|
foreach($thematic->thematic_advance_list as $thematic_advance) {
|
|
foreach($thematic->thematic_advance_list as $thematic_advance) {
|
|
$cond = array('id = ? AND c_id = ?'=>array($thematic_advance['id'], $this->course_id));
|
|
$cond = array('id = ? AND c_id = ?'=>array($thematic_advance['id'], $this->course_id));
|
|
api_item_property_update($this->course_info, 'thematic_advance', $thematic_advance['id'],'ThematicAdvanceDeleted', api_get_user_id());
|
|
api_item_property_update($this->course_info, 'thematic_advance', $thematic_advance['id'],'ThematicAdvanceDeleted', api_get_user_id());
|
|
Database::delete($table_thematic_advance, $cond);
|
|
Database::delete($table_thematic_advance, $cond);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
foreach($thematic->thematic_plan_list as $thematic_plan) {
|
|
foreach($thematic->thematic_plan_list as $thematic_plan) {
|
|
$cond = array('id = ? AND c_id = ?'=>array($thematic_plan['id'], $this->course_id));
|
|
$cond = array('id = ? AND c_id = ?'=>array($thematic_plan['id'], $this->course_id));
|
|
api_item_property_update($this->course_info, 'thematic_plan', $thematic_advance['id'], 'ThematicPlanDeleted', api_get_user_id());
|
|
api_item_property_update($this->course_info, 'thematic_plan', $thematic_advance['id'], 'ThematicPlanDeleted', api_get_user_id());
|
|
@@ -489,21 +491,21 @@ class CourseRecycler
|
|
api_item_property_update($this->course_info, 'thematic', $last_id,'ThematicDeleted', api_get_user_id());
|
|
api_item_property_update($this->course_info, 'thematic', $last_id,'ThematicDeleted', api_get_user_id());
|
|
Database::delete($table_thematic,$cond);
|
|
Database::delete($table_thematic,$cond);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Recycle Attendances
|
|
* Recycle Attendances
|
|
*/
|
|
*/
|
|
function recycle_attendance($session_id = 0) {
|
|
function recycle_attendance($session_id = 0) {
|
|
if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
|
|
if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
|
|
- $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
|
|
|
|
|
|
+ $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
|
|
$table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
|
|
$table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
|
|
-
|
|
|
|
|
|
+
|
|
$resources = $this->course->resources;
|
|
$resources = $this->course->resources;
|
|
- foreach ($resources[RESOURCE_ATTENDANCE] as $last_id => $obj) {
|
|
|
|
- if (is_numeric($last_id)) {
|
|
|
|
|
|
+ foreach ($resources[RESOURCE_ATTENDANCE] as $last_id => $obj) {
|
|
|
|
+ if (is_numeric($last_id)) {
|
|
foreach($obj->attendance_calendar as $attendance_calendar) {
|
|
foreach($obj->attendance_calendar as $attendance_calendar) {
|
|
$cond = array('id = ? AND c_id = ? '=>array($attendance_calendar['id'], $this->course_id));
|
|
$cond = array('id = ? AND c_id = ? '=>array($attendance_calendar['id'], $this->course_id));
|
|
Database::delete($table_attendance_calendar, $cond);
|
|
Database::delete($table_attendance_calendar, $cond);
|