Skip to content

Commit c0341a2

Browse files
TomoTsuyukiFragonite
authored andcommitted
Issue #121 Update valuetrust if exists.
1 parent ac6bb99 commit c0341a2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
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, 2023120101, '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
}

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 = 2023120101;
28+
$plugin->version = 2023120102;
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)