MDL-51782 mod_forum: moved post_deleted event into function
This commit is contained in:
+17
-1
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user