From a3a1708f6365f487f23851e9b023c9202b28b8ad Mon Sep 17 00:00:00 2001 From: jerome Date: Thu, 16 Apr 2009 07:48:34 +0000 Subject: [PATCH] category MDL-18876 replace error notice by exception, move success notice into index.php --- course/index.php | 8 +++++++- course/lib.php | 23 +++++++++-------------- lang/en_utf8/error.php | 2 ++ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/course/index.php b/course/index.php index a1c1427aba..6ea66f7baf 100644 --- a/course/index.php +++ b/course/index.php @@ -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); } diff --git a/course/lib.php b/course/lib.php index 1810a5a18d..f1797b79ab 100644 --- a/course/lib.php +++ b/course/lib.php @@ -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; } /** diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index 52f7d899f6..49f1cc8933 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -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)'; -- 2.39.5