From ed54cb4110eaedcb917407b0c47c3a5f0f76a004 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Fri, 9 Aug 2013 18:01:05 +0800 Subject: [PATCH] MDL-39957 course: replaced add_to_log for moving courses --- course/lib.php | 32 ++++++++++++++++++++++++-------- course/manage.php | 15 ++++++++++++++- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/course/lib.php b/course/lib.php index 6df63a849d9..ef51f2cc666 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2026,14 +2026,14 @@ function course_allowed_module($course, $modname) { * @return bool success */ function move_courses($courseids, $categoryid) { - global $CFG, $DB, $OUTPUT; + global $DB; if (empty($courseids)) { - // nothing to do + // Nothing to do. return; } - if (!$category = $DB->get_record('course_categories', array('id'=>$categoryid))) { + if (!$category = $DB->get_record('course_categories', array('id' => $categoryid))) { return false; } @@ -2042,21 +2042,37 @@ function move_courses($courseids, $categoryid) { $i = 1; foreach ($courseids as $courseid) { - if ($course = $DB->get_record('course', array('id'=>$courseid), 'id, category')) { + if ($dbcourse = $DB->get_record('course', array('id' => $courseid))) { $course = new stdClass(); $course->id = $courseid; $course->category = $category->id; $course->sortorder = $category->sortorder + MAX_COURSES_IN_CATEGORY - $i++; if ($category->visible == 0) { - // hide the course when moving into hidden category, - // do not update the visibleold flag - we want to get to previous state if somebody unhides the category + // Hide the course when moving into hidden category, do not update the visibleold flag - we want to get + // to previous state if somebody unhides the category. $course->visible = 0; } $DB->update_record('course', $course); - add_to_log($course->id, "course", "move", "edit.php?id=$course->id", $course->id); - $context = context_course::instance($course->id); + // Store the context. + $context = context_course::instance($course->id); + + // Update the course object we are passing to the event. + $dbcourse->category = $course->category; + $dbcourse->sortorder = $course->sortorder; + + // Trigger a course updated event. + $event = \core\event\course_updated::create(array( + 'objectid' => $course->id, + 'context' => $context, + 'other' => array('shortname' => $dbcourse->shortname, + 'fullname' => $dbcourse->fullname) + )); + $event->add_record_snapshot('course', $dbcourse); + $event->set_legacy_logdata(array($course->id, 'course', 'move', 'edit.php?id=' . $course->id, $course->id)); + $event->trigger(); + $context->update_moved($newparent); } } diff --git a/course/manage.php b/course/manage.php index d4a905455cd..ddf02ce4848 100644 --- a/course/manage.php +++ b/course/manage.php @@ -277,7 +277,20 @@ if ((!empty($moveup) or !empty($movedown)) && confirm_sesskey()) { $DB->set_field('course', 'sortorder', $swapcourse->sortorder, array('id' => $movecourse->id)); $DB->set_field('course', 'sortorder', $movecourse->sortorder, array('id' => $swapcourse->id)); cache_helper::purge_by_event('changesincourse'); - add_to_log($movecourse->id, "course", "move", "edit.php?id=$movecourse->id", $movecourse->id); + + // Update $movecourse's sortorder. + $movecourse->sortorder = $swapcourse->sortorder; + + // Trigger a course updated event. + $event = \core\event\course_updated::create(array( + 'objectid' => $movecourse->id, + 'context' => context_course::instance($movecourse->id), + 'other' => array('shortname' => $movecourse->shortname, + 'fullname' => $movecourse->fullname) + )); + $event->add_record_snapshot('course', $movecourse); + $event->set_legacy_logdata(array($movecourse->id, 'course', 'move', 'edit.php?id=' . $movecourse->id, $movecourse->id)); + $event->trigger(); } }