mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 19:50:14 +01:00
MDL-39959 events: Replace add_to_log() calls with events for course module actions (create, delete and update)
This commit is contained in:
parent
b9b994c7d2
commit
63deb5c379
@ -703,18 +703,19 @@ class dndupload_ajax_processor {
|
||||
$mod->groupmodelink = $this->cm->groupmodelink;
|
||||
$mod->groupmode = $this->cm->groupmode;
|
||||
|
||||
// Trigger mod_created event with information about this module.
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->modulename = $mod->modname;
|
||||
$eventdata->name = $mod->name;
|
||||
$eventdata->cmid = $mod->id;
|
||||
$eventdata->courseid = $this->course->id;
|
||||
$eventdata->userid = $USER->id;
|
||||
events_trigger('mod_created', $eventdata);
|
||||
// Trigger course module created event.
|
||||
$event = \core\event\course_module_created::create(array(
|
||||
'courseid' => $this->course->id,
|
||||
'context' => context_module::instance($mod->id),
|
||||
'objectid' => $mod->id,
|
||||
'other' => array(
|
||||
'modulename' => $mod->modname,
|
||||
'name' => $mod->name,
|
||||
'instanceid' => $instanceid
|
||||
)
|
||||
));
|
||||
$event->trigger();
|
||||
|
||||
add_to_log($this->course->id, "course", "add mod",
|
||||
"../mod/{$mod->modname}/view.php?id=$mod->id",
|
||||
"{$mod->modname} $instanceid");
|
||||
add_to_log($this->course->id, $mod->modname, "add",
|
||||
"view.php?id=$mod->id",
|
||||
"$instanceid", $mod->id);
|
||||
|
@ -1619,7 +1619,7 @@ function set_coursemodule_visible($id, $visible) {
|
||||
* @since 2.5
|
||||
*/
|
||||
function course_delete_module($cmid) {
|
||||
global $CFG, $DB, $USER;
|
||||
global $CFG, $DB;
|
||||
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
require_once($CFG->dirroot.'/blog/lib.php');
|
||||
@ -1702,18 +1702,18 @@ function course_delete_module($cmid) {
|
||||
"Cannot delete the module $modulename (instance) from section.");
|
||||
}
|
||||
|
||||
// Trigger a mod_deleted event with information about this module.
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->modulename = $modulename;
|
||||
$eventdata->cmid = $cm->id;
|
||||
$eventdata->courseid = $cm->course;
|
||||
$eventdata->userid = $USER->id;
|
||||
events_trigger('mod_deleted', $eventdata);
|
||||
|
||||
add_to_log($cm->course, 'course', "delete mod",
|
||||
"view.php?id=$cm->course",
|
||||
"$modulename $cm->instance", $cm->id);
|
||||
|
||||
// Trigger event for course module delete action.
|
||||
$event = \core\event\course_module_deleted::create(array(
|
||||
'courseid' => $cm->course,
|
||||
'context' => $modcontext,
|
||||
'objectid' => $cm->id,
|
||||
'other' => array(
|
||||
'modulename' => $modulename,
|
||||
'instanceid' => $cm->instance,
|
||||
)
|
||||
));
|
||||
$event->add_record_snapshot('course_modules', $cm);
|
||||
$event->trigger();
|
||||
rebuild_course_cache($cm->course, true);
|
||||
}
|
||||
|
||||
|
@ -140,16 +140,24 @@ function add_moduleinfo($moduleinfo, $course, $mform = null) {
|
||||
condition_info::update_cm_from_form((object)array('id'=>$moduleinfo->coursemodule), $moduleinfo, false);
|
||||
}
|
||||
|
||||
$eventname = 'mod_created';
|
||||
// Trigger event based on the action we did.
|
||||
$event = \core\event\course_module_created::create(array(
|
||||
'courseid' => $course->id,
|
||||
'context' => $modcontext,
|
||||
'objectid' => $moduleinfo->coursemodule,
|
||||
'other' => array(
|
||||
'modulename' => $moduleinfo->modulename,
|
||||
'name' => $moduleinfo->name,
|
||||
'instanceid' => $moduleinfo->instance
|
||||
)
|
||||
));
|
||||
$event->trigger();
|
||||
|
||||
add_to_log($course->id, "course", "add mod",
|
||||
"../mod/$moduleinfo->modulename/view.php?id=$moduleinfo->coursemodule",
|
||||
"$moduleinfo->modulename $moduleinfo->instance");
|
||||
add_to_log($course->id, $moduleinfo->modulename, "add",
|
||||
"view.php?id=$moduleinfo->coursemodule",
|
||||
"$moduleinfo->instance", $moduleinfo->coursemodule);
|
||||
|
||||
$moduleinfo = edit_module_post_actions($moduleinfo, $course, 'mod_created');
|
||||
$moduleinfo = edit_module_post_actions($moduleinfo, $course);
|
||||
|
||||
return $moduleinfo;
|
||||
}
|
||||
@ -157,28 +165,19 @@ function add_moduleinfo($moduleinfo, $course, $mform = null) {
|
||||
|
||||
/**
|
||||
* Common create/update module module actions that need to be processed as soon as a module is created/updaded.
|
||||
* For example: trigger event, create grade parent category, add outcomes, rebuild caches, regrade, save plagiarism settings...
|
||||
* For example:create grade parent category, add outcomes, rebuild caches, regrade, save plagiarism settings...
|
||||
* Please note this api does not trigger events as of MOODLE 2.6. Please trigger events before calling this api.
|
||||
*
|
||||
* @param object $moduleinfo the module info
|
||||
* @param object $course the course of the module
|
||||
* @param string $eventname the event name to trigger
|
||||
*
|
||||
* return object moduleinfo update with grading management info
|
||||
* @return object moduleinfo update with grading management info
|
||||
*/
|
||||
function edit_module_post_actions($moduleinfo, $course, $eventname) {
|
||||
global $USER, $CFG;
|
||||
function edit_module_post_actions($moduleinfo, $course) {
|
||||
global $CFG;
|
||||
|
||||
$modcontext = context_module::instance($moduleinfo->coursemodule);
|
||||
|
||||
// Trigger mod_created/mod_updated event with information about this module.
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->modulename = $moduleinfo->modulename;
|
||||
$eventdata->name = $moduleinfo->name;
|
||||
$eventdata->cmid = $moduleinfo->coursemodule;
|
||||
$eventdata->courseid = $course->id;
|
||||
$eventdata->userid = $USER->id;
|
||||
events_trigger($eventname, $eventdata);
|
||||
|
||||
// Sync idnumber with grade_item.
|
||||
if ($grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$moduleinfo->modulename,
|
||||
'iteminstance'=>$moduleinfo->instance, 'itemnumber'=>0, 'courseid'=>$course->id))) {
|
||||
@ -490,14 +489,24 @@ function update_moduleinfo($cm, $moduleinfo, $course, $mform = null) {
|
||||
$completion->reset_all_state($cm);
|
||||
}
|
||||
|
||||
add_to_log($course->id, "course", "update mod",
|
||||
"../mod/$moduleinfo->modulename/view.php?id=$moduleinfo->coursemodule",
|
||||
"$moduleinfo->modulename $moduleinfo->instance");
|
||||
// Trigger event based on the action we did.
|
||||
$event = \core\event\course_module_updated::create(array(
|
||||
'courseid' => $course->id,
|
||||
'context' => $modcontext,
|
||||
'objectid' => $moduleinfo->coursemodule,
|
||||
'other' => array(
|
||||
'modulename' => $moduleinfo->modulename,
|
||||
'name' => $moduleinfo->name,
|
||||
'instanceid' => $moduleinfo->instance
|
||||
)
|
||||
));
|
||||
$event->trigger();
|
||||
|
||||
add_to_log($course->id, $moduleinfo->modulename, "update",
|
||||
"view.php?id=$moduleinfo->coursemodule",
|
||||
"$moduleinfo->instance", $moduleinfo->coursemodule);
|
||||
|
||||
$moduleinfo = edit_module_post_actions($moduleinfo, $course, 'mod_updated');
|
||||
$moduleinfo = edit_module_post_actions($moduleinfo, $course);
|
||||
|
||||
return array($cm, $moduleinfo);
|
||||
}
|
||||
|
@ -141,6 +141,7 @@ Event triggering and event handlers:
|
||||
* groups_groupings_groups_removed -> (no replacement)
|
||||
* groups_groups_deleted -> \core\event\group_deleted
|
||||
* groups_groupings_deleted -> \core\event\grouping_deleted
|
||||
* edit_module_post_actions() does not trigger events any more.
|
||||
|
||||
=== 2.5.1 ===
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user