-
Bug
-
Resolution: Fixed
-
Minor
-
2.0.3, 2.1
-
None
-
Any
-
MOODLE_20_STABLE, MOODLE_21_STABLE
-
MOODLE_20_STABLE
-
I have categories with very long names.
On upgrade from moodle 1.9 this causes error:
!!! Error writing to database !!!
!! Data too long for column 'name' at row 27
UPDATE mdl_question SET name = ? WHERE qtype = 'random' AND category = ? AND questiontext = ?
[array (
0 => 'Random ( VERY LONG STRING HERE IN RUSSIAN (two bytes per char in utf8) and sub-categories)',
1 => '7926'
2 => '1',
)] !!
!! Stack trace: * line 394 of /lib/dml/moodle_database.php: dml_write_exception thrown
- line 1056 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
- line 50 of /question/type/multichoice/db/upgrade.php: call to mysqli_native_moodle_database->set_field_select()
- line 373 of /lib/upgradelib.php: call to xmldb_qtype_multichoice_upgrade()
- line 1421 of /lib/upgradelib.php: call to upgrade_plugins()
- line 146 of /admin/cli/upgrade.php: call to upgrade_noncore()
problem is in /question/type/multichoice/db/upgrade.php:
where str length of $randomqname is not limited.
$randomqname = $QTYPES[RANDOM]->question_name($cat, false);
$DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '0'));
better is to limit it into
/question/type/random/questiontype.php :
function question_name($category, $includesubcategories) should be something like :
function question_name($category, $includesubcategories) {
+$max = 50;
+$str = $category->name;
+if (mb_strlen($str,'utf-8') > $max) {$str = mb_substr($str,0,$max-3,'utf-8').'...';}
if ($includesubcategories)
{ $string = 'randomqplusname'; }else
{ $string = 'randomqname'; }return get_string($string, 'qtype_random', $category>name);
+return get_string($string, 'qtype_random', $str);
}