Skip to content

Commit 035152a

Browse files
committed
Issue #121 Update old records from system context to cm context.
1 parent 6afcda1 commit 035152a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

db/upgrade.php

+30
Original file line numberDiff line numberDiff line change
@@ -341,5 +341,35 @@ function xmldb_cms_upgrade($oldversion) {
341341
upgrade_mod_savepoint(true, 2023112100, 'cms');
342342
}
343343

344+
if ($oldversion < 2023120101) {
345+
// Update query for setting.
346+
$sql = "UPDATE {customfield_data} mcd1
347+
SET contextid = sub.mcid
348+
FROM (
349+
SELECT mcd.id mcdid, mcd.contextid mcdcontextid, mc.id mcid
350+
FROM {customfield_data} mcd
351+
JOIN {customfield_field} mcf ON mcf.id = mcd.fieldid
352+
JOIN {customfield_category} mcc ON mcc.id = mcf.categoryid
353+
JOIN {course_modules} mcm ON mcm.instance = mcd.instanceid AND mcm.module = (
354+
SELECT id FROM {modules} WHERE name = 'cms'
355+
)
356+
JOIN {context} mc ON mc.instanceid = mcm.id AND contextlevel = 70
357+
WHERE mcd.id IN (
358+
SELECT mcd.id
359+
FROM {customfield_data} mcd
360+
JOIN {customfield_field} mcf ON mcf.id = mcd.fieldid
361+
JOIN {customfield_category} mcc ON mcc.id = mcf.categoryid
362+
JOIN {course_modules} mcm ON mcm.instance = mcd.instanceid AND mcm.module = (
363+
SELECT id FROM {modules} WHERE name = 'cms'
364+
)
365+
JOIN {context} mc ON mc.instanceid = mcm.id AND contextlevel = 70
366+
WHERE mcf.type = 'textarea' AND mcc.component = 'mod_cms' AND mcd.contextid != mc.id
367+
)
368+
) sub
369+
WHERE mcd1.id = sub.mcdid";
370+
$DB->execute($sql);
371+
upgrade_mod_savepoint(true, 2023120101, 'cms');
372+
}
373+
344374
return true;
345375
}

version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

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

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

0 commit comments

Comments
 (0)