Skip to content

Commit

Permalink
category MDL-18876 replace error notice by exception, move success no…
Browse files Browse the repository at this point in the history
…tice into index.php
  • Loading branch information
jerome committed Apr 16, 2009
1 parent 653a864 commit a3a1708
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
8 changes: 7 additions & 1 deletion course/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@
print_heading($heading);

if ($data->fulldelete) {
category_delete_full($deletecat, true);
$deletedcourses = category_delete_full($deletecat, true);

foreach($deletedcourses as $course) {
notify(get_string('coursedeleted', '', $course->shortname), 'notifysuccess');
}
notify(get_string('coursecategorydeleted', '', format_string($deletecat->name)), 'notifysuccess');

} else {
category_delete_move($deletecat, $data->newparent, true);
}
Expand Down
23 changes: 9 additions & 14 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3239,8 +3239,9 @@ function course_allowed_module($course,$mod) {

/**
* Recursively delete category including all subcategories and courses.
* @param object $ccategory
* @return bool status
* @param object $category
* @param boolean $showfeedback display some notices
* @return array return deleted courses
*/
function category_delete_full($category, $showfeedback=true) {
global $CFG, $DB;
Expand All @@ -3249,28 +3250,24 @@ function category_delete_full($category, $showfeedback=true) {

if ($children = $DB->get_records('course_categories', array('parent'=>$category->id), 'sortorder ASC')) {
foreach ($children as $childcat) {
if (!category_delete_full($childcat, $showfeedback)) {
notify("Error deleting category $childcat->name");
return false;
}
category_delete_full($childcat, $showfeedback);
}
}

$deletedcourses = array();
if ($courses = $DB->get_records('course', array('category'=>$category->id), 'sortorder ASC')) {
foreach ($courses as $course) {
if (!delete_course($course, false)) {
notify("Error deleting course $course->shortname");
return false;
throw new moodle_exception('cannotdeletecategorycourse','','',$course->shortname);
}
notify(get_string('coursedeleted', '', $course->shortname), 'notifysuccess');
$deletedcourses[] = $course;
}
}

// now delete anything that may depend on course category context
grade_course_category_delete($category->id, 0, $showfeedback);
if (!question_delete_course_category($category, 0, $showfeedback)) {
notify(get_string('errordeletingquestionsfromcategory', 'question', $category), 'notifysuccess');
return false;
throw new moodle_exception('cannotdeletecategoryquestions','','',$category->name);
}

// finally delete the category and it's context
Expand All @@ -3279,9 +3276,7 @@ function category_delete_full($category, $showfeedback=true) {

events_trigger('course_category_deleted', $category);

notify(get_string('coursecategorydeleted', '', format_string($category->name)), 'notifysuccess');

return true;
return $deletedcourses;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions lang/en_utf8/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
$string['cannotdeletebackupids'] = 'Couldn\'t delete previous backup ids';
$string['cannotdeletecap'] = 'Could not delete deprecated capability $a';
$string['cannotdeletecate'] = 'Error while deleting category';
$string['cannotdeletecategorycourse'] = 'Course \'$a\' failed to be deleted.';
$string['cannotdeletecategoryquestions'] = 'Could not delete questions from category \'$a\'';
$string['cannotdeletecourse'] = 'You do not have the permission to delete this course';
$string['cannotdeletecustomfield'] = 'Error deleting custom field data';
$string['cannotdeletedir'] = 'Cannot delete ($a)';
Expand Down

0 comments on commit a3a1708

Please sign in to comment.