@@ -229,11 +229,11 @@ function hsuforum_update_instance($forum, $mform) {
229229 hsuforum_add_discussion ($ discussion , null , $ message );
230230
231231 if (! $ discussion = $ DB ->get_record ('hsuforum_discussions ' , array ('forum ' =>$ forum ->id ))) {
232- print_error ('cannotadd ' , 'hsuforum ' );
232+ throw new \ moodle_exception ('cannotadd ' , 'hsuforum ' );
233233 }
234234 }
235235 if (! $ post = $ DB ->get_record ('hsuforum_posts ' , array ('id ' =>$ discussion ->firstpost ))) {
236- print_error ('cannotfindfirstpost ' , 'hsuforum ' );
236+ throw new \ moodle_exception ('cannotfindfirstpost ' , 'hsuforum ' );
237237 }
238238
239239 $ cm = get_coursemodule_from_instance ('hsuforum ' , $ forum ->id );
@@ -1305,7 +1305,7 @@ function hsuforum_user_complete($course, $user, $mod, $forum) {
13051305 if ($ posts = hsuforum_get_user_posts ($ forum ->id , $ user ->id )) {
13061306
13071307 if (!$ cm = get_coursemodule_from_instance ('hsuforum ' , $ forum ->id , $ course ->id )) {
1308- print_error ('invalidcoursemodule ' );
1308+ throw new \ moodle_exception ('invalidcoursemodule ' );
13091309 }
13101310 $ discussions = hsuforum_get_user_involved_discussions ($ forum ->id , $ user ->id );
13111311
@@ -2056,7 +2056,7 @@ function hsuforum_get_readable_forums($userid, $courseid=0, $excludeanonymous =
20562056 require_once ($ CFG ->dirroot .'/course/lib.php ' );
20572057
20582058 if (!$ forummod = $ DB ->get_record ('modules ' , array ('name ' => 'hsuforum ' ))) {
2059- print_error ('notinstalled ' , 'hsuforum ' );
2059+ throw new \ moodle_exception ('notinstalled ' , 'hsuforum ' );
20602060 }
20612061
20622062 $ config = get_config ('hsuforum ' );
@@ -4480,20 +4480,20 @@ function hsuforum_verify_and_delete_post($course, $cm, $forum, $modcontext, $dis
44804480 // Check user capability to delete post.
44814481 $ timepassed = time () - $ post ->created ;
44824482 if (($ timepassed > $ CFG ->maxeditingtime ) && !has_capability ('mod/hsuforum:deleteanypost ' , $ modcontext )) {
4483- print_error ("cannotdeletepost " , "hsuforum " ,
4483+ throw new \ moodle_exception ("cannotdeletepost " , "hsuforum " ,
44844484 hsuforum_go_back_to ("discuss.php?d= $ post ->discussion " ));
44854485 }
44864486 if ($ post ->totalscore ) {
4487- print_error ('couldnotdeleteratings ' , 'rating ' ,
4487+ throw new \ moodle_exception ('couldnotdeleteratings ' , 'rating ' ,
44884488 hsuforum_go_back_to ("discuss.php?d= $ post ->discussion " ));
44894489 }
44904490 if (hsuforum_count_replies ($ post ) && !has_capability ('mod/hsuforum:deleteanypost ' , $ modcontext )) {
4491- print_error ("couldnotdeletereplies " , "hsuforum " ,
4491+ throw new \ moodle_exception ("couldnotdeletereplies " , "hsuforum " ,
44924492 hsuforum_go_back_to ("discuss.php?d= $ post ->discussion " ));
44934493 }
44944494 if (!$ post ->parent ) { // post is a discussion topic as well, so delete discussion
44954495 if ($ forum ->type == 'single ' ) {
4496- print_error ('cannnotdeletesinglediscussion ' , 'hsuforum ' ,
4496+ throw new \ moodle_exception ('cannnotdeletesinglediscussion ' , 'hsuforum ' ,
44974497 hsuforum_go_back_to ("discuss.php?d= $ post ->discussion " ));
44984498 }
44994499 hsuforum_delete_discussion ($ discussion , false , $ course , $ cm , $ forum );
@@ -4514,7 +4514,7 @@ function hsuforum_verify_and_delete_post($course, $cm, $forum, $modcontext, $dis
45144514
45154515 }
45164516 if (!hsuforum_delete_post ($ post , has_capability ('mod/hsuforum:deleteanypost ' , $ modcontext ), $ course , $ cm , $ forum )) {
4517- print_error ('errorwhiledelete ' , 'hsuforum ' );
4517+ throw new \ moodle_exception ('errorwhiledelete ' , 'hsuforum ' );
45184518 }
45194519 if ($ forum ->type == 'single ' ) {
45204520 // Single discussion forums are an exception. We show
@@ -5178,7 +5178,7 @@ function hsuforum_user_can_post_discussion($forum, $currentgroup=null, $unused=-
51785178 if (!$ cm ) {
51795179 debugging ('missing cm ' , DEBUG_DEVELOPER );
51805180 if (!$ cm = get_coursemodule_from_instance ('hsuforum ' , $ forum ->id , $ forum ->course )) {
5181- print_error ('invalidcoursemodule ' );
5181+ throw new \ moodle_exception ('invalidcoursemodule ' );
51825182 }
51835183 }
51845184
@@ -5264,14 +5264,14 @@ function hsuforum_user_can_post($forum, $discussion, $user=NULL, $cm=NULL, $cour
52645264 if (!$ cm ) {
52655265 debugging ('missing cm ' , DEBUG_DEVELOPER );
52665266 if (!$ cm = get_coursemodule_from_instance ('hsuforum ' , $ forum ->id , $ forum ->course )) {
5267- print_error ('invalidcoursemodule ' );
5267+ throw new \ moodle_exception ('invalidcoursemodule ' );
52685268 }
52695269 }
52705270
52715271 if (!$ course ) {
52725272 debugging ('missing course ' , DEBUG_DEVELOPER );
52735273 if (!$ course = $ DB ->get_record ('course ' , array ('id ' => $ forum ->course ))) {
5274- print_error ('invalidcourseid ' );
5274+ throw new \ moodle_exception ('invalidcourseid ' );
52755275 }
52765276 }
52775277
@@ -5403,7 +5403,7 @@ function hsuforum_user_can_see_discussion($forum, $discussion, $context, $user=N
54035403 }
54045404 }
54055405 if (!$ cm = get_coursemodule_from_instance ('hsuforum ' , $ forum ->id , $ forum ->course )) {
5406- print_error ('invalidcoursemodule ' );
5406+ throw new \ moodle_exception ('invalidcoursemodule ' );
54075407 }
54085408
54095409 if (!has_capability ('mod/hsuforum:viewdiscussion ' , $ context )) {
@@ -5467,7 +5467,7 @@ function hsuforum_user_can_see_post($forum, $discussion, $post, $user=NULL, $cm=
54675467 if (!$ cm ) {
54685468 debugging ('missing cm ' , DEBUG_DEVELOPER );
54695469 if (!$ cm = get_coursemodule_from_instance ('hsuforum ' , $ forum ->id , $ forum ->course )) {
5470- print_error ('invalidcoursemodule ' );
5470+ throw new \ moodle_exception ('invalidcoursemodule ' );
54715471 }
54725472 }
54735473
@@ -5549,7 +5549,7 @@ function hsuforum_print_latest_discussions($course, $forum, $maxdiscussions=-1,
55495549
55505550 if (!$ cm ) {
55515551 if (!$ cm = get_coursemodule_from_instance ('hsuforum ' , $ forum ->id , $ forum ->course )) {
5552- print_error ('invalidcoursemodule ' );
5552+ throw new \ moodle_exception ('invalidcoursemodule ' );
55535553 }
55545554 }
55555555 $ context = context_module::instance ($ cm ->id );
@@ -6758,7 +6758,7 @@ function hsuforum_check_throttling($forum, $cm = null) {
67586758 */
67596759function hsuforum_check_blocking_threshold ($ thresholdwarning ) {
67606760 if (!empty ($ thresholdwarning ) && !$ thresholdwarning ->canpost ) {
6761- print_error ($ thresholdwarning ->errorcode ,
6761+ throw new \ moodle_exception ($ thresholdwarning ->errorcode ,
67626762 $ thresholdwarning ->module ,
67636763 $ thresholdwarning ->link ,
67646764 $ thresholdwarning ->additional );
@@ -7694,7 +7694,7 @@ function hsuforum_get_posts_by_user($user, array $courses, $musthaveaccess = fal
76947694 if (!is_viewing ($ coursecontext , $ user ) && !is_enrolled ($ coursecontext , $ user )) {
76957695 // Need to have full access to a course to see the rest of own info
76967696 if ($ musthaveaccess ) {
7697- print_error ('errorenrolmentrequired ' , 'hsuforum ' );
7697+ throw new \ moodle_exception ('errorenrolmentrequired ' , 'hsuforum ' );
76987698 }
76997699 continue ;
77007700 }
@@ -7703,7 +7703,7 @@ function hsuforum_get_posts_by_user($user, array $courses, $musthaveaccess = fal
77037703 // if they don't we immediately have a problem.
77047704 if (!can_access_course ($ course )) {
77057705 if ($ musthaveaccess ) {
7706- print_error ('errorenrolmentrequired ' , 'hsuforum ' );
7706+ throw new \ moodle_exception ('errorenrolmentrequired ' , 'hsuforum ' );
77077707 }
77087708 continue ;
77097709 }
@@ -7733,7 +7733,7 @@ function hsuforum_get_posts_by_user($user, array $courses, $musthaveaccess = fal
77337733 // But they're not... if it was a specific course throw an error otherwise
77347734 // just skip this course so that it is not searched.
77357735 if ($ musthaveaccess ) {
7736- print_error ("groupnotamember " , '' , $ CFG ->wwwroot ."/course/view.php?id= $ course ->id " );
7736+ throw new \ moodle_exception ("groupnotamember " , '' , $ CFG ->wwwroot ."/course/view.php?id= $ course ->id " );
77377737 }
77387738 continue ;
77397739 }
@@ -7753,7 +7753,7 @@ function hsuforum_get_posts_by_user($user, array $courses, $musthaveaccess = fal
77537753 // user doesn't have access to any courses is which the requested user has posted.
77547754 // Although we do know at this point that the requested user has posts.
77557755 if ($ musthaveaccess ) {
7756- print_error ('permissiondenied ' );
7756+ throw new \ moodle_exception ('permissiondenied ' );
77577757 } else {
77587758 return $ return ;
77597759 }
0 commit comments