MDL-79256 customfield: add new valuetrust to data table schema.

This commit is contained in:
Paul Holden 2023-12-18 18:27:08 +00:00
parent 810554ee83
commit d0cab9a4a0
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
15 changed files with 50 additions and 11 deletions

View File

@ -477,7 +477,7 @@ class backup_course_structure_step extends backup_structure_step {
$customfields = new backup_nested_element('customfields');
$customfield = new backup_nested_element('customfield', array('id'), array(
'shortname', 'type', 'value', 'valueformat'
'shortname', 'type', 'value', 'valueformat', 'valuetrust',
));
$courseformatoptions = new backup_nested_element('courseformatoptions');
@ -1361,7 +1361,7 @@ class backup_groups_structure_step extends backup_structure_step {
$groupcustomfields = new backup_nested_element('groupcustomfields');
$groupcustomfield = new backup_nested_element('groupcustomfield', ['id'], [
'shortname', 'type', 'value', 'valueformat', 'groupid']);
'shortname', 'type', 'value', 'valueformat', 'valuetrust', 'groupid']);
$members = new backup_nested_element('group_members');
@ -1376,7 +1376,7 @@ class backup_groups_structure_step extends backup_structure_step {
$groupingcustomfields = new backup_nested_element('groupingcustomfields');
$groupingcustomfield = new backup_nested_element('groupingcustomfield', ['id'], [
'shortname', 'type', 'value', 'valueformat', 'groupingid']);
'shortname', 'type', 'value', 'valueformat', 'valuetrust', 'groupingid']);
$groupinggroups = new backup_nested_element('grouping_groups');

View File

@ -231,6 +231,7 @@ class course_handler extends \core_customfield\handler {
$d->set($d->datafield(), $data['value']);
$d->set('value', $data['value']);
$d->set('valueformat', $data['valueformat']);
$d->set('valuetrust', !empty($data['valuetrust']));
$d->set('contextid', $context->id);
$d->save();
}

View File

@ -96,6 +96,12 @@ class data extends persistent {
'default' => FORMAT_MOODLE,
'optional' => true
],
'valuetrust' => [
'type' => PARAM_BOOL,
'null' => NULL_NOT_ALLOWED,
'default' => false,
'optional' => true,
],
'contextid' => [
'type' => PARAM_INT,
'optional' => false,

View File

@ -354,7 +354,10 @@ abstract class data_controller {
} else if ($this->datafield() === 'decvalue') {
return (float)$value;
} else if ($this->datafield() === 'value') {
return format_text($value, $this->get('valueformat'), ['context' => $this->get_context()]);
return format_text($value, $this->get('valueformat'), [
'context' => $this->get_context(),
'trusted' => $this->get('valuetrust'),
]);
} else {
return format_string($value, true, ['context' => $this->get_context()]);
}

View File

@ -512,7 +512,9 @@ abstract class handler {
'shortname' => $d->get_field()->get('shortname'),
'type' => $d->get_field()->get('type'),
'value' => $d->get_value(),
'valueformat' => $d->get('valueformat')];
'valueformat' => $d->get('valueformat'),
'valuetrust' => $d->get('valuetrust'),
];
}
}
return $finalfields;

View File

@ -72,6 +72,7 @@ class provider implements
'charvalue' => 'privacy:metadata:customfield_data:charvalue',
'value' => 'privacy:metadata:customfield_data:value',
'valueformat' => 'privacy:metadata:customfield_data:valueformat',
'valuetrust' => 'privacy:metadata:customfield_data:valuetrust',
'timecreated' => 'privacy:metadata:customfield_data:timecreated',
'timemodified' => 'privacy:metadata:customfield_data:timemodified',
'contextid' => 'privacy:metadata:customfield_data:contextid',
@ -485,7 +486,10 @@ class provider implements
$record->timecreated = \core_privacy\local\request\transform::datetime($record->timecreated);
$record->timemodified = \core_privacy\local\request\transform::datetime($record->timemodified);
unset($record->contextid);
$record->value = format_text($record->value, $record->valueformat, ['context' => $context]);
$record->value = format_text($record->value, $record->valueformat, [
'context' => $context,
'trusted' => $record->valuetrust,
]);
writer::with_context($context)->export_data($subcontext, $record);
}
}

View File

@ -149,6 +149,7 @@ class group_handler extends handler {
'type' => $data->get_field()->get('type'),
'value' => $data->get_value(),
'valueformat' => $data->get('valueformat'),
'valuetrust' => $data->get('valuetrust'),
'groupid' => $data->get('instanceid'),
];
}
@ -175,6 +176,7 @@ class group_handler extends handler {
$d->set($d->datafield(), $data['value']);
$d->set('value', $data['value']);
$d->set('valueformat', $data['valueformat']);
$d->set('valuetrust', !empty($data['valuetrust']));
$d->set('contextid', $context->id);
$d->save();
}

View File

@ -148,6 +148,7 @@ class grouping_handler extends handler {
'type' => $data->get_field()->get('type'),
'value' => $data->get_value(),
'valueformat' => $data->get('valueformat'),
'valuetrust' => $data->get('valuetrust'),
'groupingid' => $data->get('instanceid'),
];
}
@ -176,6 +177,7 @@ class grouping_handler extends handler {
$d->set($d->datafield(), $data['value']);
$d->set('value', $data['value']);
$d->set('valueformat', $data['valueformat']);
$d->set('valuetrust', !empty($data['valuetrust']));
$d->set('contextid', $context->id);
$d->save();
}

View File

@ -82,6 +82,7 @@ $string['privacy:metadata:customfield_data:timecreated'] = 'Time when data was c
$string['privacy:metadata:customfield_data:timemodified'] = 'Time when data was last modified';
$string['privacy:metadata:customfield_data:value'] = 'Data value, when it is a text';
$string['privacy:metadata:customfield_data:valueformat'] = 'The format of the value, when it is a text';
$string['privacy:metadata:customfield_data:valuetrust'] = 'The trust flag of the value, when it is text';
$string['privacy:metadata:customfieldpluginsummary'] = 'Fields for various components';
$string['privacy:metadata:filepurpose'] = 'File attached to the custom field data';
$string['shortname'] = 'Short name';

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20240110" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20240123" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@ -4332,6 +4332,7 @@
<FIELD NAME="charvalue" TYPE="char" LENGTH="1333" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="value" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="valueformat" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="valuetrust" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>

View File

@ -964,5 +964,20 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2024010400.01);
}
if ($oldversion < 2024012300.00) {
// Define field valuetrust to be added to customfield_data.
$table = new xmldb_table('customfield_data');
$field = new xmldb_field('valuetrust', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'valueformat');
// Conditionally launch add field valuetrust.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2024012300.00);
}
return true;
}

View File

@ -41,12 +41,13 @@ class backup_qbank_customfields_plugin extends \backup_qbank_plugin {
$plugin->add_child($pluginwrapper);
$customfields = new backup_nested_element('customfields');
$customfield = new backup_nested_element('customfield', ['id'], ['shortname', 'type', 'value', 'valueformat']);
$customfield = new backup_nested_element('customfield', ['id'],
['shortname', 'type', 'value', 'valueformat', 'valuetrust']);
$pluginwrapper->add_child($customfields);
$customfields->add_child($customfield);
$customfield->set_source_sql("SELECT cfd.id, cff.shortname, cff.type, cfd.value, cfd.valueformat
$customfield->set_source_sql("SELECT cfd.id, cff.shortname, cff.type, cfd.value, cfd.valueformat, cfd.valuetrust
FROM {customfield_data} cfd
JOIN {customfield_field} cff ON cff.id = cfd.fieldid
JOIN {customfield_category} cfc ON cfc.id = cff.categoryid

View File

@ -318,6 +318,7 @@ class question_handler extends \core_customfield\handler {
$d->set($d->datafield(), $data['value']);
$d->set('value', $data['value']);
$d->set('valueformat', $data['valueformat']);
$d->set('valuetrust', !empty($data['valuetrust']));
$d->set('contextid', $data['fieldcontextid']);
$d->save();
}

View File

@ -167,7 +167,7 @@ class custom_fields {
$selectfields = "{$customdatatablealias}.id, {$customdatatablealias}.contextid";
if ($datafield === 'value') {
// We will take the format into account when displaying the individual values.
$selectfields .= ", {$customdatatablealias}.valueformat";
$selectfields .= ", {$customdatatablealias}.valueformat, {$customdatatablealias}.valuetrust";
}
$columns[] = (new column(

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2024011900.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2024012300.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.4dev (Build: 20240119)'; // Human-friendly version name