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

Problem importing numeric question/answer into quiz in GIFT format

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.2
    • Fix Version/s: 2.0.3
    • Component/s: Quiz
    • Environment:
      n/a
    • Testing Instructions:
      Hide

      Import a GIFT file including a numerical question. I already used the test file attached to this issue, so it would be a better test if you used a different GIFT file containing numerical questions.

      Also check that there are no regressions when editing numerical questions through the UI, or importing from Moodle XML.

      Show
      Import a GIFT file including a numerical question. I already used the test file attached to this issue, so it would be a better test if you used a different GIFT file containing numerical questions. Also check that there are no regressions when editing numerical questions through the UI, or importing from Moodle XML.
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-27155_master

      Description

      When attempting to import a text file containing questions in GIFT format into a quiz in 2.0.2+ (Build: 20110406), the import process consistently halts when encountering a numeric type

      {#1} question and reports "Error writing to database." Clicking on "More information about this error" brings up this screen:

      >error/moodle/dmlwriteexception
      >This indicates that a general error occurred when Moodle tried to write to the database. If you turn on Debugging you will get more detailed information about what the problem is.
      >When importing questions in Aiken format after successful reading all questions this error emerges when saving in the database. No definite rule why. Ver. 2.0

      When attempting to import the identical file into 1.9, everything proceeds smoothly, and all questions, including numeric ones, are handled properly.

      Repeated testing with multiple versions of the text file gives the same results (success in 1.9, failure in 2.0.2) over and over again.

      I've attached a copy of the text file, which looks like this:

      This is a note.

      This requires a numeric answer.{#1}

      This requies a text answer.

      {=Text}

      I'm told this is a bug and should be reported here.

        Gliffy Diagrams

        1. gift_test.txt
          0.1 kB
          Bill Stone
        1. messagerreur.jpg
          156 kB

          Activity

          Hide
          ppichet Pierre Pichet added a comment - - edited

          Need to set a value to instructions format for import processes in numerical save_options.
          This is set correctly in xml format code which was the only import tested so not detected when testing .

          Show
          ppichet Pierre Pichet added a comment - - edited Need to set a value to instructions format for import processes in numerical save_options. This is set correctly in xml format code which was the only import tested so not detected when testing .
          Hide
          ppichet Pierre Pichet added a comment -

          complete error message

          Show
          ppichet Pierre Pichet added a comment - complete error message
          Hide
          ppichet Pierre Pichet added a comment -

          Tim
          the following code solve the problem

          @@ -296,15 +296,18 @@ class question_numerical_qtype extends question_shortanswer_qtype {
                   if (isset($question->unitsleft)) {
                       $options->unitsleft = $question->unitsleft;
                   } else {
                       $options->unitsleft = 0 ;
                   }
          -
          +        if (isset($question->instructions) && is_array($question->instructions)){
                   $options->instructions = $this->import_or_save_files($question->instructions,
                               $question->context, 'qtype_'.$question->qtype , 'instruction', $question->id);
          -        $options->instructionsformat = $question->instructions['format'];
          -
          +            $options->instructionsformat = $question->instructions['format'];
          +        } else {
          +            $options->instructions = '' ;
          +            $options->instructionsformat = editors_get_preferred_format();
          +        }
                   $DB->update_record('question_numerical_options', $options);
           
                   return $result;
               }
           

          If you agree I transfer the commit to GitHUB

          Show
          ppichet Pierre Pichet added a comment - Tim the following code solve the problem @@ -296,15 +296,18 @@ class question_numerical_qtype extends question_shortanswer_qtype { if (isset($question->unitsleft)) { $options->unitsleft = $question->unitsleft; } else { $options->unitsleft = 0 ; } - + if (isset($question->instructions) && is_array($question->instructions)){ $options->instructions = $this->import_or_save_files($question->instructions, $question->context, 'qtype_'.$question->qtype , 'instruction', $question->id); - $options->instructionsformat = $question->instructions['format']; - + $options->instructionsformat = $question->instructions['format']; + } else { + $options->instructions = '' ; + $options->instructionsformat = editors_get_preferred_format(); + } $DB->update_record('question_numerical_options', $options); return $result; } If you agree I transfer the commit to GitHUB
          Hide
          timhunt Tim Hunt added a comment -

          Ready for integration

          Show
          timhunt Tim Hunt added a comment - Ready for integration
          Hide
          samhemelryk Sam Hemelryk added a comment -

          Thanks guys this has been integrated now.

          Cheers
          Sam

          Show
          samhemelryk Sam Hemelryk added a comment - Thanks guys this has been integrated now. Cheers Sam
          Hide
          mudrd8mz David Mudrak added a comment -

          Passed, successfully imported the following question

          ::Numerical question::When was Ulysses S. Grant born?{#1822:5}

          Show
          mudrd8mz David Mudrak added a comment - Passed, successfully imported the following question ::Numerical question::When was Ulysses S. Grant born?{#1822:5}
          Hide
          stronk7 Eloy Lafuente (stronk7) added a comment -

          Closing as fixed. Many thanks!

          Show
          stronk7 Eloy Lafuente (stronk7) added a comment - Closing as fixed. Many thanks!

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                5/May/11