Skip to content

Commit

Permalink
Refactor the code for deleting a course from course/delete.php to a f…
Browse files Browse the repository at this point in the history
…unction in moodlelib.php.
  • Loading branch information
tjhunt committed Mar 2, 2006
1 parent be58b18 commit b97c416
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
12 changes: 1 addition & 11 deletions course/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) );

Expand Down
44 changes: 42 additions & 2 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3057,14 +3057,54 @@ 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
*
* @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) {

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

0 comments on commit b97c416

Please sign in to comment.