mirror of
https://github.com/moodle/moodle.git
synced 2025-05-02 22:45:03 +02:00
MDL-38314 repository: Delete repository instances on context deletion
This commit is contained in:
parent
4aa4d88da8
commit
d802435e00
@ -5357,6 +5357,10 @@ abstract class context extends stdClass implements IteratorAggregate {
|
||||
$fs = get_file_storage();
|
||||
$fs->delete_area_files($this->_id);
|
||||
|
||||
// Delete all repository instances attached to this context.
|
||||
require_once($CFG->dirroot . '/repository/lib.php');
|
||||
repository::delete_all_for_context($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);
|
||||
|
@ -2077,6 +2077,32 @@ abstract class repository implements cacheable_object {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the instances associated to a context.
|
||||
*
|
||||
* This method is intended to be a callback when deleting
|
||||
* a course or a user to delete all the instances associated
|
||||
* to their context. The usual way to delete a single instance
|
||||
* is to use {@link self::delete()}.
|
||||
*
|
||||
* @param int $contextid context ID.
|
||||
* @param boolean $downloadcontents true to convert references to hard copies.
|
||||
* @return void
|
||||
*/
|
||||
final public static function delete_all_for_context($contextid, $downloadcontents = true) {
|
||||
global $DB;
|
||||
$repoids = $DB->get_fieldset_select('repository_instances', 'id', 'contextid = :contextid', array('contextid' => $contextid));
|
||||
if ($downloadcontents) {
|
||||
foreach ($repoids as $repoid) {
|
||||
$repo = repository::get_repository_by_id($repoid, $contextid);
|
||||
$repo->convert_references_to_local();
|
||||
}
|
||||
}
|
||||
cache::make('core', 'repositories')->purge();
|
||||
$DB->delete_records_list('repository_instances', 'id', $repoids);
|
||||
$DB->delete_records_list('repository_instance_config', 'instanceid', $repoids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide/Show a repository
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user