Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-28132

long question categories names causes errors on upgrade

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.3, 2.1
    • Fix Version/s: 2.0.4
    • Component/s: Questions
    • Labels:
      None
    • Database:
      Any
    • Testing Instructions:
      Hide

      1. Create a question category with a very long name.
      2. Create a question in that category (e.g. truefalse)
      3. Try to add one random question from that category to a quiz.

      Show
      1. Create a question category with a very long name. 2. Create a question in that category (e.g. truefalse) 3. Try to add one random question from that category to a quiz.
    • Affected Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Pull from Repository:
    • Pull Master Branch:

      Description

      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);
      }

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  1/Aug/11