stemiwe / moodle-qformat_printout

Moodle question format plugin to print out questions for review
GNU General Public License v3.0
0 stars 1 forks source link

Error exporting quiz questions with non-standard question format. #6

Open ghost opened 3 months ago

ghost commented 3 months ago

Thank you for this plugin and all the work you have put into it. Very beneficial. When exporting quiz questions with a non-standard question format, an error occurs, preventing the export process from completing successfully. I don't know which question formats in the quiz are responsible for this error as we have several different non-standard question types in our quizzes. This error does not seem to occur for example with standard essay or true/false questions.

Steps to Reproduce:

Create a quiz with questions in a non-standard format (exact format unknown). Attempt to export the quiz questions using the printout format. Error Message:

"Exception - count(): Argument #1 ($value) must be of type Countable|array, null given"

Debug Information:

Error code: generalexceptionmessage Stack trace: Line 166 of /question/format/printout/format.php: TypeError thrown Line 1017 of /question/format.php: call to qformat_printout->writequestion() Line 1815 of /lib/questionlib.php: call to qformat_default->exportprocess() Line 5140 of /lib/filelib.php: call to question_pluginfile() Line 44 of /pluginfile.php: call to file_pluginfile()

Temporary Fix:

On our system, a temporary fix has been applied by modifying line 166 of format.php from: if (count($question->options->answers) > 1) { to: if ($question->options->answers && count($question->options->answers) > 1) {

Root Cause:

The error occurs because the $question->options->answers variable is null, causing the count() function to throw an error. The temporary fix checks if $question->options->answers is not null before attempting to count its elements.

Recommendation:

A permanent fix should be implemented to handle the case where $question->options->answers is null, ensuring that the export process can complete successfully for all question formats.

stefan-weber-think-modular commented 3 months ago

thanks for pointing this out, i haven't worked on this plugin in years, but im glad to hear that it is still used :).

are you using it in Moodle 4?

I will implement the quick fix you suggested and release a new version shortly.