moosh icon indicating copy to clipboard operation
moosh copied to clipboard

question-import fails

Open mwithheld opened this issue 5 years ago • 2 comments

  • moosh version: 0.30
  • moodle version: 3.5.10+ (Build: 20200130)
    • database: any
  • php version: 7.2
  • operating system: linux

questions.xml file:

  • Format = Unix (LF) UTF-8 (no BOM)
  • Attached questions.txt renamed from .xml to .txt.
  • This is exported from Moodle and imports fine via the Moodle UI (question/import.php?courseid=2&cat=4%2C17)
root@e3a04e840248:/var/www/html# moosh --verbose -n question-import blocks/integrityadvocate/tests/fixtures/questions.xml 2
Moodle version detected: 35
Top Moodle dir: /var/www/html
Current working dir: /var/www/html
Relative Moodle dir:
Processing command option 'help''
Command: import (question)
Options:
        help (): ''
Arguments:
        blocks/integrityadvocate/tests/fixtures/questions.xml 2
++ Error: mdb->get_record() found more than one record! ++
* line 1583 of /lib/dml/moodle_database.php: call to debugging()
* line 1543 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()
* line 1522 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
* line 41 of /moosh/Moosh/Command/Moodle26/Question/QuestionImport.php: call to moodle_database->get_record()
* line 351 of /moosh/moosh.php: call to Moosh\Command\Moodle26\Question\QuestionImport->execute()
++ Parsing questions from import file. ++
!! Cannot read import file (or file is empty) !!
!!! Import error !!!
!!
Error code: cannotimport !!
!! Stack trace: * line 482 of /lib/setuplib.php: moodle_exception thrown
* line 69 of /moosh/Moosh/Command/Moodle26/Question/QuestionImport.php: call to print_error()
* line 351 of /moosh/moosh.php: call to Moosh\Command\Moodle26\Question\QuestionImport->execute()
 !!
root@e3a04e840248:/var/www/html# ls -altr  blocks/integrityadvocate/tests/fixtures/questions.xml
-rwxr-xr-x 1 root root 986 Mar 20 01:24 blocks/integrityadvocate/tests/fixtures/questions.xml

mwithheld avatar Mar 20 '20 01:03 mwithheld

However, it does appear to be adding the question to the quiz. That is, the problem is not fatal to the operation of the function.

Answer the first question

Select one: ( ) True (X) False

drbean avatar Apr 02 '20 14:04 drbean

The problem lines, 41-43

// Use existing questions category for quiz or create the defaults. if (!$category = $DB->get_record('question_categories', array('contextid'=>$coursecontext->id))) { $category = question_make_default_categories($contexts->all()); }

The contextid associates question_categories with course_categories. There are typically many question_categories for one course_category. In that situation, how to choose the right question category?

I have hacked up a randomquestion-import command to show only a limited number of the questions being uploaded, using tags. (At https://github.com/drbean/moosh/blob/master/Moosh/Command/Moodle26/Question/QuestionImport.php . It's not ready for prime time.)

There I require an already existing question category id to be provided. Someone should write a questioncategory-create command!

In what question category is question-import at present placing the questions when there is more than one question category with the same contextid?

Apparently in 'Default for COURSENAME | 54801 | The default category for questions shared in context 'COURSENAME'.

presumably with the aid of

question_make_default_categories, which 'Gets the default category in the most specific context.'

and

question_get_default_category, which returns 'the default question category for the context'

drbean avatar Apr 03 '20 07:04 drbean