$section = $DB->get_record('course_sections', array('id' => $cm->section, 'course' => $cm->course));
moveto_module($newcm, $section, $cm);
moveto_module($cm, $section, $newcm);
+
+ // Trigger course module created event. We can trigger the event only if we know the newcmid.
+ $event = \core\event\course_module_created::create_from_cm($newcm);
+ $event->trigger();
}
rebuild_course_cache($cm->course);
$modinfo = $this->create_specific_module_test('assign');
$events = $sink->get_events();
$event = array_pop($events);
- $sink->close();
- $cm = $DB->get_record('course_modules', array('id' => $modinfo->coursemodule), '*', MUST_EXIST);
+ $cm = get_coursemodule_from_id('assign', $modinfo->coursemodule, 0, false, MUST_EXIST);
$mod = $DB->get_record('assign', array('id' => $modinfo->instance), '*', MUST_EXIST);
// Validate event data.
$this->assertEventLegacyLogData($arr, $event);
$this->assertEventContextNotUsed($event);
+ // Let us see if duplicating an activity results in a nice course module created event.
+ $sink->clear();
+ $course = get_course($mod->course);
+ $newcm = duplicate_module($course, $cm);
+ $events = $sink->get_events();
+ $event = array_pop($events);
+ $sink->close();
+
+ // Validate event data.
+ $this->assertInstanceOf('\core\event\course_module_created', $event);
+ $this->assertEquals($newcm->id, $event->objectid);
+ $this->assertEquals($USER->id, $event->userid);
+ $this->assertEquals($course->id, $event->courseid);
+ $url = new moodle_url('/mod/assign/view.php', array('id' => $newcm->id));
+ $this->assertEquals($url, $event->get_url());
}
/**