print_error('cannotmovetonotfound', 'hsuforum', $return); } $cmto = $forums[$forumto->id]; if (!$cmto->uservisible) { print_error('cannotmovenotvisible', 'hsuforum', $return); } $destinationctx = context_module::instance($cmto->id); require_capability('mod/hsuforum:startdiscussion', $destinationctx); if (!$forum->anonymous or $warned) { if (!hsuforum_move_attachments($discussion, $forum->id, $forumto->id)) { echo $OUTPUT->notification("Errors occurred while moving attachment directories - check your file permissions"); } $DB->set_field('hsuforum_discussions', 'forum', $forumto->id, array('id' => $discussion->id)); $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);
/** * Test discussion_moved event. */ public function test_discussion_moved() { // Setup test data. $course = $this->getDataGenerator()->create_course(); $fromforum = $this->getDataGenerator()->create_module('hsuforum', array('course' => $course->id)); $toforum = $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'] = $fromforum->id; $record['userid'] = $user->id; $discussion = $this->getDataGenerator()->get_plugin_generator('mod_hsuforum')->create_discussion($record); $context = context_module::instance($toforum->cmid); $params = array('context' => $context, 'objectid' => $discussion->id, 'other' => array('fromforumid' => $fromforum->id, 'toforumid' => $toforum->id)); $event = \mod_hsuforum\event\discussion_moved::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_moved', $event); $this->assertEquals($context, $event->get_context()); $expected = array($course->id, 'hsuforum', 'move discussion', "discuss.php?d={$discussion->id}", $discussion->id, $toforum->cmid); $this->assertEventLegacyLogData($expected, $event); $this->assertEventContextNotUsed($event); $this->assertNotEmpty($event->get_name()); }