Commit ea88fd4e authored by Mark Nelson's avatar Mark Nelson
Browse files

MDL-48012 core: added pre_*_delete hooks

parent e8952c59
......@@ -1652,6 +1652,15 @@ function course_delete_module($cmid) {
"Cannot delete this module as the function {$modulename}_delete_instance is missing in mod/$modulename/lib.php.");
}
// Allow plugins to use this course module before we completely delete it.
if ($pluginsfunction = get_plugins_with_function('pre_course_module_delete')) {
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $pluginfunction) {
$pluginfunction($cm);
}
}
}
// Delete activity context questions and question categories.
question_delete_activity($cm);
......
......@@ -2041,6 +2041,15 @@ function blocks_name_allowed_in_format($name, $pageformat) {
function blocks_delete_instance($instance, $nolongerused = false, $skipblockstables = false) {
global $DB;
// Allow plugins to use this block before we completely delete it.
if ($pluginsfunction = get_plugins_with_function('pre_block_delete')) {
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $pluginfunction) {
$pluginfunction($instance);
}
}
}
if ($block = block_instance($instance->blockname, $instance)) {
$block->instance_delete();
}
......
......@@ -1670,6 +1670,16 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
// Make sure we won't timeout when deleting a lot of courses.
$settimeout = core_php_time_limit::raise();
// Allow plugins to use this category before we completely delete it.
if ($pluginsfunction = get_plugins_with_function('pre_course_category_delete')) {
$category = $this->get_db_record();
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $pluginfunction) {
$pluginfunction($category);
}
}
}
$deletedcourses = array();
// Get children. Note, we don't want to use cache here because it would be rebuilt too often.
......
......@@ -3928,6 +3928,15 @@ function delete_user(stdClass $user) {
return false;
}
// Allow plugins to use this user object before we completely delete it.
if ($pluginsfunction = get_plugins_with_function('pre_user_delete')) {
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $pluginfunction) {
$pluginfunction($user);
}
}
}
// Keep user record before updating it, as we have to pass this to user_deleted event.
$olduser = clone $user;
......@@ -4677,6 +4686,15 @@ function delete_course($courseorid, $showfeedback = true) {
return false;
}
// Allow plugins to use this course before we completely delete it.
if ($pluginsfunction = get_plugins_with_function('pre_course_delete')) {
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $pluginfunction) {
$pluginfunction($course);
}
}
}
// Make the course completely empty.
remove_course_contents($courseid, $showfeedback);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment