gbateson / moodle-qtype_ordering

Ordering question type for Moodle >= 2.1
5 stars 26 forks source link

Long draggable items break quiz statistics. #60

Open OT-AndreyUskov opened 3 years ago

OT-AndreyUskov commented 3 years ago

Ordering question type allows to create questions with draggable items longer than quiz statistics overview can handle.

'subqid' field is varchar(100). In lib/db/install.xml 'question_response_analysis' table is defined as follows:

<TABLE NAME="question_response_analysis" COMMENT="Analysis of student responses given to questions.">
     <FIELDS>
        ...
         <FIELD NAME="subqid" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false"/>
        ...
    </FIELDS>
     ...
 </TABLE>

Error: Error writing to database

[More information about this error|http://docs.moodle.org/35/en/error/moodle/dmlwriteexception] ×Debug info: Data too long for column 'subqid' at row 1 INSERT INTO mdl_question_response_analysis (hashcode,whichtries,questionid,variant,subqid,aid,response,credit,timemodified) VALUES(?,?,?,?,?,?,?,?,?) [array ( 0 => '1afcbec028f7ca4b759200c2b2aa39303f30bdba', 1 => 'lasttry', 2 => '2443', 3 => 1, 4 => 'This is the second item. This item is quite long and you may enter this item and save the ordering question but you will get an error when you try to check statistics of the quiz and recalculate the data.', 5 => 2, 6 => 'Position 2', 7 => 0.33333333333333331, 8 => 1615364109, )] Error code: dmlwriteexception ×Stack trace: * line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown

To reproduce this error:

  1. Create a quiz with an ordering question and a long option in the question (example in debug info).
  2. Login as a student and do the quiz.
  3. Login as an admin and go to Quiz administration > Results > Statistics
  4. See the error. If you are already in statistics, click 'Recalculate now' button.

Screenshot from 2021-03-10 12-04-59

It would be nice to not allow users to create content that the system cannot handle.

Ordering question item must be limited to 100.

Reproduced in LTS Moodle 3.5 and 3.9.

In Moodle tracker: https://tracker.moodle.org/browse/MDL-71085

gbateson commented 2 years ago

100 chars is not very long, especially if we consider that a draggable item could contain HTML code for multimedia. Perhaps there's a nother way to shorten the text before it gets inserted into the response analysis table. I'll try to find time to investigate.

gbateson commented 2 years ago

I took a brief look at the code, but it's pretty complex inside the "question/classes/statistics/responses". I can't fix it quickly I'm afraid.

timhunt commented 2 years ago

In the ordering questoin type, the two pleces you control this are

The bit you are currently creating as

question_utils::to_plain_text($answer->answer, $answer->answerformat)

is what is becoming subqid.

LOL. Looking at git history, I see I wrote this code. Sorry.

timhunt commented 2 years ago

Also, Gordon, while I am writing, it would nice if you could review some of the pull requests that are waiting here. Thanks.