MDL-29332 question: calculated variables may differ in case only

This commit is contained in:
Marina Glancy
2016-09-13 10:15:26 +08:00
parent b022c2cd1c
commit bc48debf36
5 changed files with 37 additions and 15 deletions
+1 -4
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20150922" COMMENT="XMLDB file for core Moodle tables"
<XMLDB PATH="lib/db" VERSION="20160804" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
>
@@ -1352,9 +1352,6 @@
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="attemptstepid" TYPE="foreign" FIELDS="attemptstepid" REFTABLE="question_attempt_steps" REFFIELDS="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="attemptstepid-name" UNIQUE="true" FIELDS="attemptstepid, name"/>
</INDEXES>
</TABLE>
<TABLE NAME="question_statistics" COMMENT="Statistics for individual questions used in an activity.">
<FIELDS>
+15
View File
@@ -4700,5 +4700,20 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2015111605.07);
}
if ($oldversion < 2015111606.01) {
// Define index attemptstepid-name (unique) to be dropped from question_attempt_step_data.
$table = new xmldb_table('question_attempt_step_data');
$index = new xmldb_index('attemptstepid-name', XMLDB_INDEX_UNIQUE, array('attemptstepid', 'name'));
// Conditionally launch drop index attemptstepid-name.
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015111606.01);
}
return true;
}
+12 -3
View File
@@ -287,10 +287,19 @@ class question_engine_data_mapper {
*/
public function update_question_attempt_metadata(question_attempt $qa, array $names) {
global $DB;
list($condition, $params) = $DB->get_in_or_equal($names);
$params[] = $qa->get_step(0)->get_id();
if (!$names) {
return [];
}
// Use case-sensitive LIKE instead of get_in_or_equal.
// Some databases may use case-insensitive collation, we don't want to delete 'X' instead of 'x'.
$sqls = [];
$params = [$qa->get_step(0)->get_id()];
foreach ($names as $name) {
$sqls[] = $DB->sql_like('name', '?', true);
$params[] = $DB->sql_like_escape($name);
}
$DB->delete_records_select('question_attempt_step_data',
'name ' . $condition . ' AND attemptstepid = ?', $params);
'attemptstepid = ? AND (' . join(' OR ', $sqls) . ')', $params);
return $this->insert_question_attempt_metadata($qa, $names);
}
+8 -7
View File
@@ -281,9 +281,9 @@ class qtype_calculated extends question_type {
if ($sharedatasetdefs = $DB->get_records_select(
'question_dataset_definitions',
"type = '1'
AND name = ?
AND " . $DB->sql_like('name', '?') . "
AND category = ?
ORDER BY id DESC ", array($dataset->name, $question->category)
ORDER BY id DESC ", array($DB->sql_like_escape($dataset->name), $question->category)
)) { // So there is at least one.
$sharedatasetdef = array_shift($sharedatasetdefs);
if ($sharedatasetdef->options == $datasetdef->options) {// Identical so use it.
@@ -1400,9 +1400,9 @@ class qtype_calculated extends question_type {
// can manage to automatically take care of
// some possible realtime concurrence.
if ($olderdatasetdefs = $DB->get_records_select('question_dataset_definitions',
"type = ? AND name = ? AND category = ? AND id < ?
"type = ? AND " . $DB->sql_like('name', '?') . " AND category = ? AND id < ?
ORDER BY id DESC",
array($datasetdef->type, $datasetdef->name,
array($datasetdef->type, $DB->sql_like_escape($datasetdef->name),
$datasetdef->category, $datasetdef->id))) {
while ($olderdatasetdef = array_shift($olderdatasetdefs)) {
@@ -1484,8 +1484,9 @@ class qtype_calculated extends question_type {
// Construct question local options.
$sql = "SELECT a.*
FROM {question_dataset_definitions} a, {question_datasets} b
WHERE a.id = b.datasetdefinition AND a.type = '1' AND b.question = ? AND a.name = ?";
$currentdatasetdef = $DB->get_record_sql($sql, array($form->id, $name));
WHERE a.id = b.datasetdefinition AND a.type = '1' AND b.question = ? AND ".
$DB->sql_like('a.name', '?');
$currentdatasetdef = $DB->get_record_sql($sql, array($form->id, $DB->sql_like_escape($name)));
if (!$currentdatasetdef) {
$currentdatasetdef = new stdClass();
$currentdatasetdef->type = '0';
@@ -1506,7 +1507,7 @@ class qtype_calculated extends question_type {
WHERE a.id = b.datasetdefinition
AND a.type = '1'
AND a.category = ?
AND a.name = ?", array($form->category, $name));
AND " . $DB->sql_like('a.name', '?'), array($form->category, $DB->sql_like_escape($name)));
$type = 1;
$key = "{$type}-{$form->category}-{$name}";
if (!empty($categorydatasetdefs)) {
+1 -1
View File
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2015111606.00; // 20151116 = branching date YYYYMMDD - do not modify!
$version = 2015111606.01; // 20151116 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.