From 102ffb8e18b7bcbb466163d6b344e29cce21f57f Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 14 Oct 2015 17:35:40 -0700 Subject: [PATCH] MDL-51782 mod_forum: moved post_deleted event into function --- mod/forum/lib.php | 18 +++++++++++++++++- mod/forum/post.php | 18 ------------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/mod/forum/lib.php b/mod/forum/lib.php index ab2754a1995..a17eb907050 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -4629,7 +4629,7 @@ function forum_delete_discussion($discussion, $fulldelete, $course, $cm, $forum) * @return bool */ function forum_delete_post($post, $children, $course, $cm, $forum, $skipcompletion=false) { - global $DB, $CFG; + global $DB, $CFG, $USER; require_once($CFG->libdir.'/completionlib.php'); $context = context_module::instance($cm->id); @@ -4683,6 +4683,22 @@ function forum_delete_post($post, $children, $course, $cm, $forum, $skipcompleti } } + $params = array( + 'context' => $context, + 'objectid' => $post->id, + 'other' => array( + 'discussionid' => $post->discussion, + 'forumid' => $forum->id, + 'forumtype' => $forum->type, + ) + ); + if ($post->userid !== $USER->id) { + $params['relateduserid'] = $post->userid; + } + $event = \mod_forum\event\post_deleted::create($params); + $event->add_record_snapshot('forum_posts', $post); + $event->trigger(); + return true; } return false; diff --git a/mod/forum/post.php b/mod/forum/post.php index 2b21726e24d..4d94b83fd4c 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -360,24 +360,6 @@ if (!empty($forum)) { // User is starting a new discussion in a forum $discussionurl = new moodle_url("/mod/forum/discuss.php", array('d' => $discussion->id)); } - $params = array( - 'context' => $modcontext, - 'objectid' => $post->id, - 'other' => array( - 'discussionid' => $discussion->id, - 'forumid' => $forum->id, - 'forumtype' => $forum->type, - ) - ); - - if ($post->userid !== $USER->id) { - $params['relateduserid'] = $post->userid; - } - $event = \mod_forum\event\post_deleted::create($params); - $event->add_record_snapshot('forum_posts', $post); - $event->add_record_snapshot('forum_discussions', $discussion); - $event->trigger(); - redirect(forum_go_back_to($discussionurl)); } else { print_error('errorwhiledelete', 'forum');