$DB->set_field('hsuforum_read', 'forumid', $forumto->id, array('discussionid' => $discussion->id));
        $params = array('context' => $destinationctx, 'objectid' => $discussion->id, 'other' => array('fromforumid' => $forum->id, 'toforumid' => $forumto->id));
        $event = \mod_hsuforum\event\discussion_moved::create($params);
        $event->add_record_snapshot('hsuforum_discussions', $discussion);
        $event->add_record_snapshot('hsuforum', $forum);
        $event->add_record_snapshot('hsuforum', $forumto);
        $event->trigger();
        // Delete the RSS files for the 2 forums to force regeneration of the feeds
        require_once $CFG->dirroot . '/mod/hsuforum/rsslib.php';
        hsuforum_rss_delete_file($forum);
        hsuforum_rss_delete_file($forumto);
        redirect($return . '&moved=-1&sesskey=' . sesskey());
    }
}
$params = array('context' => $modcontext, 'objectid' => $discussion->id);
$event = \mod_hsuforum\event\discussion_viewed::create($params);
$event->add_record_snapshot('hsuforum_discussions', $discussion);
$event->add_record_snapshot('hsuforum', $forum);
$event->trigger();
unset($SESSION->fromdiscussion);
if (!$root) {
    $root = $discussion->firstpost;
}
if (!($post = hsuforum_get_post_full($root))) {
    print_error("notexists", 'hsuforum', "{$CFG->wwwroot}/mod/hsuforum/view.php?f={$forum->id}");
}
if (!hsuforum_user_can_see_post($forum, $discussion, $post, null, $cm)) {
    print_error('noviewdiscussionspermission', 'hsuforum', "{$CFG->wwwroot}/mod/hsuforum/view.php?id={$forum->id}");
}
if ($mark == 'read') {
    hsuforum_tp_add_read_record($USER->id, $postid);
 /**
  * Test discussion_viewed event.
  */
 public function test_discussion_viewed()
 {
     // Setup test data.
     $course = $this->getDataGenerator()->create_course();
     $forum = $this->getDataGenerator()->create_module('hsuforum', array('course' => $course->id));
     $user = $this->getDataGenerator()->create_user();
     // Add a discussion.
     $record = array();
     $record['course'] = $course->id;
     $record['forum'] = $forum->id;
     $record['userid'] = $user->id;
     $discussion = $this->getDataGenerator()->get_plugin_generator('mod_hsuforum')->create_discussion($record);
     $context = context_module::instance($forum->cmid);
     $params = array('context' => $context, 'objectid' => $discussion->id);
     $event = \mod_hsuforum\event\discussion_viewed::create($params);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $event->trigger();
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_hsuforum\\event\\discussion_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $expected = array($course->id, 'hsuforum', 'view discussion', "discuss.php?d={$discussion->id}", $discussion->id, $forum->cmid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
 }