mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Merge branch 'wip-MDL-41508-master' of git://github.com/marinaglancy/moodle
This commit is contained in:
commit
34ac96bf6d
2 changed files with 57 additions and 33 deletions
|
@ -2046,10 +2046,11 @@ function move_courses($courseids, $categoryid) {
|
||||||
$newparent = context_coursecat::instance($category->id);
|
$newparent = context_coursecat::instance($category->id);
|
||||||
$i = 1;
|
$i = 1;
|
||||||
|
|
||||||
foreach ($courseids as $courseid) {
|
list($where, $params) = $DB->get_in_or_equal($courseids);
|
||||||
if ($dbcourse = $DB->get_record('course', array('id' => $courseid))) {
|
$dbcourses = $DB->get_records_select('course', 'id ' . $where, $params);
|
||||||
|
foreach ($dbcourses as $dbcourse) {
|
||||||
$course = new stdClass();
|
$course = new stdClass();
|
||||||
$course->id = $courseid;
|
$course->id = $dbcourse->id;
|
||||||
$course->category = $category->id;
|
$course->category = $category->id;
|
||||||
$course->sortorder = $category->sortorder + MAX_COURSES_IN_CATEGORY - $i++;
|
$course->sortorder = $category->sortorder + MAX_COURSES_IN_CATEGORY - $i++;
|
||||||
if ($category->visible == 0) {
|
if ($category->visible == 0) {
|
||||||
|
@ -2066,6 +2067,9 @@ function move_courses($courseids, $categoryid) {
|
||||||
// Update the course object we are passing to the event.
|
// Update the course object we are passing to the event.
|
||||||
$dbcourse->category = $course->category;
|
$dbcourse->category = $course->category;
|
||||||
$dbcourse->sortorder = $course->sortorder;
|
$dbcourse->sortorder = $course->sortorder;
|
||||||
|
if (isset($course->visible)) {
|
||||||
|
$dbcourse->visible = $course->visible;
|
||||||
|
}
|
||||||
|
|
||||||
// Trigger a course updated event.
|
// Trigger a course updated event.
|
||||||
$event = \core\event\course_updated::create(array(
|
$event = \core\event\course_updated::create(array(
|
||||||
|
@ -2080,7 +2084,6 @@ function move_courses($courseids, $categoryid) {
|
||||||
|
|
||||||
$context->update_moved($newparent);
|
$context->update_moved($newparent);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
fix_course_sortorder();
|
fix_course_sortorder();
|
||||||
cache_helper::purge_by_event('changesincourse');
|
cache_helper::purge_by_event('changesincourse');
|
||||||
|
|
||||||
|
|
|
@ -1429,6 +1429,9 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||||
// Create a category we are going to move this course to.
|
// Create a category we are going to move this course to.
|
||||||
$category = $this->getDataGenerator()->create_category();
|
$category = $this->getDataGenerator()->create_category();
|
||||||
|
|
||||||
|
// Create a hidden category we are going to move this course to.
|
||||||
|
$categoryhidden = $this->getDataGenerator()->create_category(array('visible' => 0));
|
||||||
|
|
||||||
// Catch the update events.
|
// Catch the update events.
|
||||||
$sink = $this->redirectEvents();
|
$sink = $this->redirectEvents();
|
||||||
|
|
||||||
|
@ -1447,11 +1450,18 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||||
// Return the moved course information from the DB.
|
// Return the moved course information from the DB.
|
||||||
$movedcourse = $DB->get_record('course', array('id' => $course->id), '*', MUST_EXIST);
|
$movedcourse = $DB->get_record('course', array('id' => $course->id), '*', MUST_EXIST);
|
||||||
|
|
||||||
|
// Now move the course to the hidden category, this will also trigger an event.
|
||||||
|
move_courses(array($course->id), $categoryhidden->id);
|
||||||
|
|
||||||
|
// Return the moved course information from the DB.
|
||||||
|
$movedcoursehidden = $DB->get_record('course', array('id' => $course->id), '*', MUST_EXIST);
|
||||||
|
|
||||||
// Now we want to set the sortorder back to what it was before fix_course_sortorder() was called. The reason for
|
// Now we want to set the sortorder back to what it was before fix_course_sortorder() was called. The reason for
|
||||||
// this is because update_course() and move_courses() call fix_course_sortorder() which alters the sort order in
|
// this is because update_course() and move_courses() call fix_course_sortorder() which alters the sort order in
|
||||||
// the DB, but it does not set the value of the sortorder for the course object passed to the event.
|
// the DB, but it does not set the value of the sortorder for the course object passed to the event.
|
||||||
$updatedcourse->sortorder = $sortorder;
|
$updatedcourse->sortorder = $sortorder;
|
||||||
$movedcourse->sortorder = $category->sortorder + MAX_COURSES_IN_CATEGORY - 1;
|
$movedcourse->sortorder = $category->sortorder + MAX_COURSES_IN_CATEGORY - 1;
|
||||||
|
$movedcoursehidden->sortorder = $categoryhidden->sortorder + MAX_COURSES_IN_CATEGORY - 1;
|
||||||
|
|
||||||
// Capture the events.
|
// Capture the events.
|
||||||
$events = $sink->get_events();
|
$events = $sink->get_events();
|
||||||
|
@ -1479,6 +1489,17 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||||
$this->assertEventLegacyData($movedcourse, $event);
|
$this->assertEventLegacyData($movedcourse, $event);
|
||||||
$expectedlog = array($movedcourse->id, 'course', 'move', 'edit.php?id=' . $movedcourse->id, $movedcourse->id);
|
$expectedlog = array($movedcourse->id, 'course', 'move', 'edit.php?id=' . $movedcourse->id, $movedcourse->id);
|
||||||
$this->assertEventLegacyLogData($expectedlog, $event);
|
$this->assertEventLegacyLogData($expectedlog, $event);
|
||||||
|
|
||||||
|
$event = $events[2];
|
||||||
|
$this->assertInstanceOf('\core\event\course_updated', $event);
|
||||||
|
$this->assertEquals('course', $event->objecttable);
|
||||||
|
$this->assertEquals($movedcoursehidden->id, $event->objectid);
|
||||||
|
$this->assertEquals(context_course::instance($movedcoursehidden->id)->id, $event->contextid);
|
||||||
|
$this->assertEquals($movedcoursehidden, $event->get_record_snapshot('course', $movedcoursehidden->id));
|
||||||
|
$this->assertEquals('course_updated', $event->get_legacy_eventname());
|
||||||
|
$this->assertEventLegacyData($movedcoursehidden, $event);
|
||||||
|
$expectedlog = array($movedcoursehidden->id, 'course', 'move', 'edit.php?id=' . $movedcoursehidden->id, $movedcoursehidden->id);
|
||||||
|
$this->assertEventLegacyLogData($expectedlog, $event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue