MDL-63969 core_course: Store favourite courses in the course context

The course favourites were previously set in the system context which
is not right as they should be stored in the course context.
This commit is contained in:
Mihail Geshoski 2018-11-16 12:20:17 +08:00
parent 214696b04f
commit 329f1f23ff
3 changed files with 20 additions and 4 deletions

View File

@ -3823,12 +3823,14 @@ class core_course_external extends external_api {
$warning = [];
$favouriteexists = $ufservice->favourite_exists('core_course', 'courses', $course['id'], \context_system::instance());
$favouriteexists = $ufservice->favourite_exists('core_course', 'courses', $course['id'],
\context_course::instance($course['id']));
if ($course['favourite']) {
if (!$favouriteexists) {
try {
$ufservice->create_favourite('core_course', 'courses', $course['id'], \context_system::instance());
$ufservice->create_favourite('core_course', 'courses', $course['id'],
\context_course::instance($course['id']));
} catch (Exception $e) {
$warning['courseid'] = $course['id'];
if ($e instanceof moodle_exception) {
@ -3849,7 +3851,8 @@ class core_course_external extends external_api {
} else {
if ($favouriteexists) {
try {
$ufservice->delete_favourite('core_course', 'courses', $course['id'], \context_system::instance());
$ufservice->delete_favourite('core_course', 'courses', $course['id'],
\context_course::instance($course['id']));
} catch (Exception $e) {
$warning['courseid'] = $course['id'];
if ($e instanceof moodle_exception) {

View File

@ -2771,5 +2771,18 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2018110700.01);
}
if ($oldversion < 2018111300.01) {
// Update favourited courses, so they are saved in the particular course context instead of the system.
$favouritedcourses = $DB->get_records('favourite', ['component' => 'core_course', 'itemtype' => 'courses']);
foreach ($favouritedcourses as $fc) {
$coursecontext = \context_course::instance($fc->itemid);
$fc->contextid = $coursecontext->id;
$DB->update_record('favourite', $fc);
}
upgrade_main_savepoint(true, 2018111300.01);
}
return true;
}

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2018111300.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2018111300.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.