MDL-37082 core_course: create new course_delete_module function that handles the whole deletion process

Instead of repeating code all over the place because the original function delete_course_module only partially deletes data, we now place all the functionality needed to delete a module here.