Skip to content

Commit

Permalink
MDL-29108 Remove all associated grading areas when the context is bei…
Browse files Browse the repository at this point in the history
…ng deleted
  • Loading branch information
mudrd8mz committed Nov 13, 2011
1 parent c15b933 commit 9e32368
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions grade/grading/lib.php
Expand Up @@ -564,6 +564,30 @@ public function create_shared_area($method) {
return $DB->insert_record('grading_areas', $area);
}

/**
* Removes all data associated with the given context
*
* This is called by {@link context::delete_content()}
*
* @param int $contextid context id
*/
public static function delete_all_for_context($contextid) {
global $DB;

$areaids = $DB->get_fieldset_select('grading_areas', 'id', 'contextid = ?', array($contextid));
$methods = array_keys(self::available_methods(false));

foreach($areaids as $areaid) {
$manager = get_grading_manager($areaid);
foreach ($methods as $method) {
$controller = $manager->get_controller($method);
$controller->delete_definition();
}
}

$DB->delete_records_list('grading_areas', 'id', $areaids);
}

/**
* Helper method to tokenize the given string
*
Expand Down
4 changes: 4 additions & 0 deletions lib/accesslib.php
Expand Up @@ -4919,6 +4919,10 @@ public function delete_content() {
$fs = get_file_storage();
$fs->delete_area_files($this->_id);

// delete all advanced grading data attached to this context
require_once($CFG->dirroot.'/grade/grading/lib.php');
grading_manager::delete_all_for_context($this->_id);

// now delete stuff from role related tables, role_unassign_all
// and unenrol should be called earlier to do proper cleanup
$DB->delete_records('role_assignments', array('contextid'=>$this->_id));
Expand Down

0 comments on commit 9e32368

Please sign in to comment.