@@ -341,5 +341,35 @@ function xmldb_cms_upgrade($oldversion) {
341
341
upgrade_mod_savepoint (true , 2023112100 , 'cms ' );
342
342
}
343
343
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
+
344
374
return true ;
345
375
}
0 commit comments