Skip to content

Commit

Permalink
Issue #121 Update old records from system context to cm context.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomoTsuyuki authored and Fragonite committed Aug 29, 2024
1 parent ba37892 commit 1a38e0b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,35 @@ function xmldb_cms_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2023112100, 'cms');
}

if ($oldversion < 2023120101) {
// Update query for setting.
$sql = "UPDATE {customfield_data} mcd1
SET contextid = sub.mcid
FROM (
SELECT mcd.id mcdid, mcd.contextid mcdcontextid, mc.id mcid
FROM {customfield_data} mcd
JOIN {customfield_field} mcf ON mcf.id = mcd.fieldid
JOIN {customfield_category} mcc ON mcc.id = mcf.categoryid
JOIN {course_modules} mcm ON mcm.instance = mcd.instanceid AND mcm.module = (
SELECT id FROM {modules} WHERE name = 'cms'
)
JOIN {context} mc ON mc.instanceid = mcm.id AND contextlevel = 70
WHERE mcd.id IN (
SELECT mcd.id
FROM {customfield_data} mcd
JOIN {customfield_field} mcf ON mcf.id = mcd.fieldid
JOIN {customfield_category} mcc ON mcc.id = mcf.categoryid
JOIN {course_modules} mcm ON mcm.instance = mcd.instanceid AND mcm.module = (
SELECT id FROM {modules} WHERE name = 'cms'
)
JOIN {context} mc ON mc.instanceid = mcm.id AND contextlevel = 70
WHERE mcf.type = 'textarea' AND mcc.component = 'mod_cms' AND mcd.contextid != mc.id
)
) sub
WHERE mcd1.id = sub.mcdid";
$DB->execute($sql);
upgrade_mod_savepoint(true, 2023120101, 'cms');
}

return true;
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023120100;
$plugin->version = 2023120101;
$plugin->requires = 2020061500; // Moodle 3.9.0 and above.
$plugin->supported = [39, 401]; // Moodle 3.9 to 4.1 inclusive.
$plugin->component = 'mod_cms';
Expand Down

0 comments on commit 1a38e0b

Please sign in to comment.