mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 19:50:14 +01:00
Refactor the code for deleting a course from course/delete.php to a function in moodlelib.php.
This commit is contained in:
parent
be58b18f15
commit
b97c41647c
@ -67,17 +67,7 @@
|
||||
|
||||
print_heading($strdeletingcourse);
|
||||
|
||||
if (!remove_course_contents($course->id)) {
|
||||
notify("An error occurred while deleting some of the course contents.");
|
||||
}
|
||||
|
||||
if (!delete_records("course", "id", $course->id)) {
|
||||
notify("An error occurred while deleting the main course record.");
|
||||
}
|
||||
|
||||
if (!fulldelete($CFG->dataroot.'/'.$course->id)) {
|
||||
notify("An error occurred while deleting the course files.");
|
||||
}
|
||||
delete_course($course->id);
|
||||
|
||||
print_heading( get_string("deletedcourse", "", $course->shortname) );
|
||||
|
||||
|
@ -3057,6 +3057,44 @@ function remove_admin($userid) {
|
||||
return delete_records('user_admins', 'userid', $userid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a course, including all related data from the database,
|
||||
* and any associated files from the moodledata folder.
|
||||
*
|
||||
* @param int $courseid The id of the course to delete.
|
||||
* @param bool $showfeedback Whether to display notifications of each action the function performs.
|
||||
* @return bool true if all the removals succeeded. false if there were any failures. If this
|
||||
* method returns false, some of the removals will probably have succeeded, and others
|
||||
* failed, but you have no way of knowing which.
|
||||
*/
|
||||
function delete_course($courseid, $showfeedback = true) {
|
||||
global $CFG;
|
||||
$result = true;
|
||||
|
||||
if (!remove_course_contents($courseid, $showfeedback)) {
|
||||
if ($showfeedback) {
|
||||
notify("An error occurred while deleting some of the course contents.");
|
||||
}
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if (!delete_records("course", "id", $courseid)) {
|
||||
if ($showfeedback) {
|
||||
notify("An error occurred while deleting the main course record.");
|
||||
}
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if (!fulldelete($CFG->dataroot.'/'.$courseid)) {
|
||||
if ($showfeedback) {
|
||||
notify("An error occurred while deleting the course files.");
|
||||
}
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a course out completely, deleting all content
|
||||
* but don't delete the course itself
|
||||
@ -3064,7 +3102,9 @@ function remove_admin($userid) {
|
||||
* @uses $CFG
|
||||
* @param int $courseid The id of the course that is being deleted
|
||||
* @param bool $showfeedback Whether to display notifications of each action the function performs.
|
||||
* @return bool
|
||||
* @return bool true if all the removals succeeded. false if there were any failures. If this
|
||||
* method returns false, some of the removals will probably have succeeded, and others
|
||||
* failed, but you have no way of knowing which.
|
||||
*/
|
||||
function remove_course_contents($courseid, $showfeedback=true) {
|
||||
|
||||
@ -3276,7 +3316,7 @@ function remove_course_contents($courseid, $showfeedback=true) {
|
||||
* @param bool $removegroups Whether to remove matching records from the groups table.
|
||||
* @param bool $removeevents Whether to remove matching records from the event table.
|
||||
* @param bool $removelogs Whether to remove matching records from the log table.
|
||||
* @return bool true if all the removals succeeded. talse if there were any failures. If this
|
||||
* @return bool true if all the removals succeeded. false if there were any failures. If this
|
||||
* method returns false, some of the removals will probably have succeeded, and others
|
||||
* failed, but you have no way of knowing which.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user