Skip to content

Commit

Permalink
MDL-51782 mod_forum: moved post_deleted event into function
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Oct 15, 2015
1 parent b117fac commit 9f468b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
18 changes: 17 additions & 1 deletion mod/forum/lib.php
Expand Up @@ -4458,7 +4458,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);
Expand Down Expand Up @@ -4512,6 +4512,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;
Expand Down
18 changes: 0 additions & 18 deletions mod/forum/post.php
Expand Up @@ -364,24 +364,6 @@
$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');
Expand Down

0 comments on commit 9f468b1

Please sign in to comment.