Skip to content

Commit

Permalink
Issue #121 Update valuetrust if exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomoTsuyuki committed Jun 4, 2024
1 parent 6ce35f0 commit de26795
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,25 @@ function xmldb_cms_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2023120101, 'cms');
}

if ($oldversion < 2023120102) {
$dbman = $DB->get_manager();
// Conditionally launch add field valuetrust.
if ($dbman->field_exists('customfield_data', 'valuetrust')) {
$sql = "SELECT mcd.id mcdid
FROM {customfield_data} mcd
JOIN {customfield_field} mcf ON mcf.id = mcd.fieldid
JOIN {customfield_category} mcc ON mcc.id = mcf.categoryid
WHERE mcc.component = 'mod_cms' AND mcd.valuetrust = 0";
$records = $DB->get_records_sql($sql);
$mcdids = array_keys($records);
foreach (array_chunk($mcdids, 100) as $ids) {
[$sql, $params] = $DB->get_in_or_equal($ids);
$sql = 'UPDATE {customfield_data} SET valuetrust = 1 WHERE id ' . $sql;
$DB->execute($sql, $params);
}
}
upgrade_mod_savepoint(true, 2023120102, '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 = 2023120101;
$plugin->version = 2023120102;
$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 de26795

Please sign in to comment.