mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 08:55:15 +02:00
category MDL-18876 replace error notice by exception, move success notice into index.php
This commit is contained in:
parent
653a86489e
commit
a3a1708f63
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
@ -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
|
||||
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,6 +46,8 @@ $string['cannotdeletelangcache'] = 'Language cache cannot be deleted, please fix
|
||||
$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)';
|
||||
|
Loading…
x
Reference in New Issue
Block a user