Fixed problem not cleaning orphan questions in CourseRecycler - refs BT#5328

skala
Yannick Warnier 13 years ago
parent d90cd0425f
commit 93a17798d0
  1. 3
      main/coursecopy/classes/CourseBuilder.class.php
  2. 16
      main/coursecopy/classes/CourseRecycler.class.php

@ -462,7 +462,6 @@ class CourseBuilder {
$sql = 'SELECT * FROM '.$table_rel.' WHERE c_id = '.$course_id.' AND exercice_id = '.$obj->id;
$db_result2 = Database::query($sql);
while ($obj2 = Database::fetch_object($db_result2)) {
error_log('Adding question '.$obj2->question_id.' to the pack at '.$obj2->question_order);
$quiz->add_question($obj2->question_id, $obj2->question_order);
}
$this->course->add_resource($quiz);
@ -530,7 +529,7 @@ error_log('Adding question '.$obj2->question_id.' to the pack at '.$obj2->questi
}
if ($build_orphan_questions) {
//$this->course->add_resource(new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0));
$this->course->add_resource(new Quiz(-1, get_lang('OrphanQuestions', ''), '', 0, 0, 1, '', 0));
}
}

@ -30,8 +30,11 @@ class CourseRecycler
* Delete all items from the course.
* This deletes all items in the course-object from the current Chamilo-
* course
* @param string The type of recycling we want (full_backup or select_items)
* @assert (null) === false
*/
function recycle($type) {
if (empty($type)) { return false; }
$this->type = $type;
$table_tool_intro = Database::get_course_table(TABLE_TOOL_INTRO);
@ -306,14 +309,21 @@ class CourseRecycler
$table_qui_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
$table_qui_que_opt = Database :: get_course_table(TABLE_QUIZ_QUESTION_OPTION);
$table_qui_que_cat = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
$table_qui_que_rel_cat = Database :: get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
$ids = array_keys($this->course->resources[RESOURCE_QUIZ]);
// If the value "-1" is in the ids of elements (questions) to
// be deleted, then consider all orphan questions should be deleted
// This value is set in CourseBuilder::quiz_build_questions()
$delete_orphan_questions = in_array(-1, $ids);
$ids = implode(',', $ids);
// Deletion of the normal tests, questions in them are not deleted, they become orphan at this moment.
// 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);
@ -347,6 +357,8 @@ class CourseRecycler
Database::query($sql);
}
}
// Quizzes previously deleted are, in fact, kept with a status
// (active field) of "-1". Delete those, now.
$sql = "DELETE FROM ".$table_qui." WHERE c_id = ".$this->course_id." AND active = -1";
Database::query($sql);
}

Loading…
Cancel
Save