Skip to content

Commit 2ccb5b5

Browse files
committed
Issue #121 Update valuetrust if exists.
1 parent 57d7398 commit 2ccb5b5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

db/upgrade.php

+20
Original file line numberDiff line numberDiff line change
@@ -349,5 +349,25 @@ function xmldb_cms_upgrade($oldversion) {
349349
upgrade_mod_savepoint(true, 2024090301, 'cms');
350350
}
351351

352+
if ($oldversion < 2023120102) {
353+
$dbman = $DB->get_manager();
354+
// Conditionally launch add field valuetrust.
355+
if ($dbman->field_exists('customfield_data', 'valuetrust')) {
356+
$sql = "SELECT mcd.id mcdid
357+
FROM {customfield_data} mcd
358+
JOIN {customfield_field} mcf ON mcf.id = mcd.fieldid
359+
JOIN {customfield_category} mcc ON mcc.id = mcf.categoryid
360+
WHERE mcc.component = 'mod_cms' AND mcd.valuetrust = 0";
361+
$records = $DB->get_records_sql($sql);
362+
$mcdids = array_keys($records);
363+
foreach (array_chunk($mcdids, 100) as $ids) {
364+
[$sql, $params] = $DB->get_in_or_equal($ids);
365+
$sql = 'UPDATE {customfield_data} SET valuetrust = 1 WHERE id ' . $sql;
366+
$DB->execute($sql, $params);
367+
}
368+
}
369+
upgrade_mod_savepoint(true, 2023120102, 'cms');
370+
}
371+
352372
return true;
353373
}

0 commit comments

Comments
 (0)