Refactor the code for deleting a course from course/delete.php to a function in moodlelib.php.

This commit is contained in:
tjhunt 2006-03-02 11:58:43 +00:00
parent be58b18f15
commit b97c41647c
2 changed files with 43 additions and 13 deletions

View File

@ -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) );

View File

@ -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.
*/