MDL-24157, clean up page_comments when reseting courses

This commit is contained in:
Dongsheng Cai 2010-09-16 07:38:52 +00:00
parent 27323c97ab
commit c343ddf84e
3 changed files with 27 additions and 5 deletions

View File

@ -520,11 +520,11 @@ EOD;
/**
* delete by context, commentarea and itemid
* @param object $param {
* contextid => int the context in which the comments exist [required]
* commentarea => string the comment area [optional]
* itemid => int comment itemid [optional]
* }
* @param object $param {
* contextid => int the context in which the comments exist [required]
* commentarea => string the comment area [optional]
* itemid => int comment itemid [optional]
* }
* @return boolean
*/
public function delete_comments($param) {
@ -537,6 +537,22 @@ EOD;
return true;
}
/**
* Delete page_comments in whole course, used by course reset
* @param object $context course context
*/
public function reset_course_page_comments($context) {
global $DB;
$contexts = array();
$contexts[] = $context->id;
$children = get_child_contexts($context);
foreach ($children as $c) {
$contexts[] = $c->id;
}
list($ids, $params) = $DB->get_in_or_equal($contexts);
$DB->delete_records_select('comments', "commentarea='page_comments' AND contextid $ids", $params);
}
/**
* Delete a comment
* @param int $commentid

View File

@ -18,6 +18,7 @@ class course_reset_form extends moodleform {
$mform->addElement('checkbox', 'reset_events', get_string('deleteevents', 'calendar'));
$mform->addElement('checkbox', 'reset_logs', get_string('deletelogs'));
$mform->addElement('checkbox', 'reset_notes', get_string('deletenotes', 'notes'));
$mform->addElement('checkbox', 'reset_comments', get_string('deleteallcomments', 'moodle'));
$mform->addElement('checkbox', 'reset_course_completion', get_string('deletecoursecompletiondata', 'completion'));
$mform->addElement('checkbox', 'delete_blog_associations', get_string('deleteblogassociations', 'blog'));
$mform->addHelpButton('delete_blog_associations', 'deleteblogassociations', 'blog');

View File

@ -4441,6 +4441,11 @@ function reset_course_userdata($data) {
grade_course_reset($data->courseid);
$status[] = array('component'=>$componentstr, 'item'=>get_string('removeallcoursegrades', 'grades'), 'error'=>false);
}
// reset comments
if (!empty($data->reset_comments)) {
require_once($CFG->dirroot.'/comment/lib.php');
comment::reset_course_page_comments($context);
}
return $status;
}