Skip to content

Commit dbc3f7a

Browse files
INT-18999: Fixed deprecated function print_error() in mod_ plugins
1 parent ad94f0e commit dbc3f7a

File tree

16 files changed

+122
-122
lines changed

16 files changed

+122
-122
lines changed

classes/controller/edit_controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public function edit_post_form_action() {
256256
$postid = required_param('postid', PARAM_INT);
257257

258258
if (!$post = hsuforum_get_post_full($postid)) {
259-
print_error('invalidpostid', 'hsuforum');
259+
throw new \moodle_exception('invalidpostid', 'hsuforum');
260260
}
261261
$discussion = $DB->get_record('hsuforum_discussions', array('id' => $post->discussion), '*', MUST_EXIST);
262262

@@ -306,7 +306,7 @@ public function delete_post_action() {
306306
$candeleteown = ($post->userid == $USER->id && has_capability('mod/hsuforum:deleteownpost', $PAGE->context));
307307

308308
if (!($candeleteown || has_capability('mod/hsuforum:deleteanypost', $PAGE->context))) {
309-
print_error('cannotdeletepost', 'hsuforum');
309+
throw new \moodle_exception('cannotdeletepost', 'hsuforum');
310310
}
311311

312312
$redirect = hsuforum_verify_and_delete_post($PAGE->course, $PAGE->cm,

classes/controller/export_controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function require_capability($action) {
5555
require_capability('mod/hsuforum:viewdiscussion', $PAGE->context);
5656

5757
if (is_guest($PAGE->context)) {
58-
print_error('noguest');
58+
throw new \moodle_exception('noguest');
5959
}
6060
}
6161

classes/controller/posts_controller.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function require_capability($action) {
6262
switch ($action) {
6363
case 'discsubscribers':
6464
if (!has_capability('mod/hsuforum:viewsubscribers', $PAGE->context)) {
65-
print_error('nopermissiontosubscribe', 'hsuforum');
65+
throw new \moodle_exception('nopermissiontosubscribe', 'hsuforum');
6666
}
6767
break;
6868
default:
@@ -88,19 +88,19 @@ public function markread_action() {
8888
$cm = $PAGE->cm;
8989

9090
if (!$post = hsuforum_get_post_full($postid)) {
91-
print_error("notexists", 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?f=$forum->id");
91+
throw new \moodle_exception("notexists", 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?f=$forum->id");
9292
}
9393
$discussion = $DB->get_record('hsuforum_discussions', array('id' => $post->discussion), '*', MUST_EXIST);
9494

9595
if ($forum->type == 'news') {
9696
if (!($USER->id == $discussion->userid || (($discussion->timestart == 0
9797
|| $discussion->timestart <= time())
9898
&& ($discussion->timeend == 0 || $discussion->timeend > time())))) {
99-
print_error('invaliddiscussionid', 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?f=$forum->id");
99+
throw new \moodle_exception('invaliddiscussionid', 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?f=$forum->id");
100100
}
101101
}
102102
if (!hsuforum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
103-
print_error('nopermissiontoview', 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?f=$forum->id");
103+
throw new \moodle_exception('nopermissiontoview', 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?f=$forum->id");
104104
}
105105
hsuforum_tp_add_read_record($USER->id, $post->id);
106106
return new json_response(array('postid' => $postid, 'discussionid' => $discussion->id));
@@ -170,7 +170,7 @@ public function discsubscribers_action() {
170170
$unsubscribe = (bool)optional_param('unsubscribe', false, PARAM_RAW);
171171
/** It has to be one or the other, not both or neither */
172172
if (!($subscribe xor $unsubscribe)) {
173-
print_error('invalidaction');
173+
throw new \moodle_exception('invalidaction');
174174
}
175175
if ($subscribe) {
176176
$users = $subscriberselector->get_selected_users();

classes/service/discussion_service.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,14 @@ public function get_posts($discussionid) {
269269
|| $discussion->timestart <= time())
270270
&& ($discussion->timeend == 0 || $discussion->timeend > time())))
271271
) {
272-
print_error('invaliddiscussionid', 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?f=$forum->id");
272+
throw new \moodle_exception('invaliddiscussionid', 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?f=$forum->id");
273273
}
274274
}
275275
if (!$post = hsuforum_get_post_full($discussion->firstpost)) {
276-
print_error("notexists", 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?f=$forum->id");
276+
throw new \moodle_exception("notexists", 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?f=$forum->id");
277277
}
278278
if (!hsuforum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
279-
print_error('nopermissiontoview', 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?f=$forum->id");
279+
throw new \moodle_exception('nopermissiontoview', 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?f=$forum->id");
280280
}
281281

282282
$posts = hsuforum_get_all_discussion_posts($discussion->id);

classes/service/post_service.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ public function require_can_edit_post($forum, \context_module $context, $discuss
196196
if (((time() - $post->created) > $CFG->maxeditingtime) and
197197
!has_capability('mod/hsuforum:editanypost', $context)
198198
) {
199-
print_error('maxtimehaspassed', 'hsuforum', '', format_time($CFG->maxeditingtime));
199+
throw new \moodle_exception('maxtimehaspassed', 'hsuforum', '', format_time($CFG->maxeditingtime));
200200
}
201201
}
202202
if (($post->userid <> $USER->id) && !has_capability('mod/hsuforum:editanypost', $context)) {
203-
print_error('cannoteditposts', 'hsuforum');
203+
throw new \moodle_exception('cannoteditposts', 'hsuforum');
204204
}
205205
}
206206

discuss.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
$d = optional_param('id', null, PARAM_INT);
4141

4242
if ($d === null) {
43-
print_error('missingparameter');
43+
throw new \moodle_exception('missingparameter');
4444
}
4545
}
4646

@@ -104,26 +104,26 @@
104104
require_capability('mod/hsuforum:movediscussions', $modcontext);
105105

106106
if ($forum->type == 'single') {
107-
print_error('cannotmovefromsingleforum', 'hsuforum', $return);
107+
throw new \moodle_exception('cannotmovefromsingleforum', 'hsuforum', $return);
108108
}
109109

110110
if (!$forumto = $DB->get_record('hsuforum', array('id' => $move))) {
111-
print_error('cannotmovetonotexist', 'hsuforum', $return);
111+
throw new \moodle_exception('cannotmovetonotexist', 'hsuforum', $return);
112112
}
113113

114114
if ($forumto->type == 'single') {
115-
print_error('cannotmovetosingleforum', 'hsuforum', $return);
115+
throw new \moodle_exception('cannotmovetosingleforum', 'hsuforum', $return);
116116
}
117117

118118
// Get target forum cm and check it is visible to current user.
119119
$modinfo = get_fast_modinfo($course);
120120
$forums = $modinfo->get_instances_of('hsuforum');
121121
if (!array_key_exists($forumto->id, $forums)) {
122-
print_error('cannotmovetonotfound', 'hsuforum', $return);
122+
throw new \moodle_exception('cannotmovetonotfound', 'hsuforum', $return);
123123
}
124124
$cmto = $forums[$forumto->id];
125125
if (!$cmto->uservisible) {
126-
print_error('cannotmovenotvisible', 'hsuforum', $return);
126+
throw new \moodle_exception('cannotmovenotvisible', 'hsuforum', $return);
127127
}
128128

129129
$destinationctx = context_module::instance($cmto->id);
@@ -192,11 +192,11 @@
192192
}
193193

194194
if (! $post = hsuforum_get_post_full($root)) {
195-
print_error("notexists", 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?f=$forum->id");
195+
throw new \moodle_exception("notexists", 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?f=$forum->id");
196196
}
197197

198198
if (!hsuforum_user_can_see_post($forum, $discussion, $post, null, $cm, false)) {
199-
print_error('noviewdiscussionspermission', 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?id=$forum->id");
199+
throw new \moodle_exception('noviewdiscussionspermission', 'hsuforum', "$CFG->wwwroot/mod/hsuforum/view.php?id=$forum->id");
200200
}
201201

202202
if ($mark == 'read') {

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
if ($id) {
4444
if (!$course = $DB->get_record('course', array('id' => $id))) {
45-
print_error('invalidcourseid');
45+
throw new \moodle_exception('invalidcourseid');
4646
}
4747
} else {
4848
$course = get_site();

lib.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
67596759
function 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

Comments
 (0)