moodle_database::get_in_or_equal() error when viewing question bank of restored course

moodle_database::get_in_or_equal() error when viewing question bank of restored course

Anna S. -
回帖数:6

Hi, 

I had a course backup from an old moodle installation (I think 3.6) and restored the course to a newer installation. The current version is 4.4 and was installed via Turnkey (I know, I know, I plan to do a proper setup asap). 

When I try to view the question bank for the restored course, I get the following error:

Coding error detected, it must be fixed by a programmer: moodle_database::get_in_or_equal() does not accept empty arrays

More information about this error

Debug info:
Error code: codingerror

Stack trace:

  • line 779 of /lib/dml/moodle_database.php: coding_exception thrown
  • line 328 of /tag/classes/tag.php: call to moodle_database->get_in_or_equal()
  • line 377 of /tag/classes/tag.php: call to core_tag_tag::get_by_name_bulk()
  • line 108 of /question/classes/question_reference_manager.php: call to core_tag_tag::create_if_missing()
  • line 183 of /mod/quiz/classes/question/bank/qbank_helper.php: call to core_question\question_reference_manager::convert_legacy_set_reference_filter_condition()
  • line 732 of /mod/quiz/classes/structure.php: call to mod_quiz\question\bank\qbank_helper::get_question_structure()
  • line 89 of /mod/quiz/classes/structure.php: call to mod_quiz\structure->populate_structure()
  • line 99 of /mod/quiz/report/reportlib.php: call to mod_quiz\structure::create_for_quiz()
  • line 890 of /mod/quiz/report/statistics/report.php: call to quiz_report_get_significant_questions()
  • line 996 of /mod/quiz/report/statistics/report.php: call to quiz_statistics_report->load_and_initialise_questions_for_calculations()
  • line 2532 of /mod/quiz/lib.php: call to quiz_statistics_report->calculate_questions_stats_for_question_bank()
  • line 7705 of /lib/moodlelib.php: call to mod_quiz_calculate_question_stats()
  • line 150 of /question/classes/local/statistics/statistics_bulk_loader.php: call to component_callback()
  • line 64 of /question/classes/local/statistics/statistics_bulk_loader.php: call to core_question\local\statistics\statistics_bulk_loader::load_statistics_for_place()
  • line 1220 of /question/classes/local/bank/view.php: call to core_question\local\statistics\statistics_bulk_loader::load_aggregate_statistics()
  • line 1180 of /question/classes/local/bank/view.php: call to core_question\local\bank\view->load_required_statistics()
  • line 916 of /question/classes/local/bank/view.php: call to core_question\local\bank\view->display_question_list()
  • line 65 of /question/edit.php: call to core_question\local\bank\view->display()

There is no missing plugin for any question type.

My question: 

If there is a specific category or question that is causing the issue, is there a way for me to find out which it is? 

Thanks!

回复Anna S.

moodle_database::get_in_or_equal() error when viewing question bank of restored course

Ken Task -
Particularly helpful Moodlers的头像

Around that version (3.5 or 6) I think there was still a question upgrade helper which was introduced in 2.x.
References:
https://docs.moodle.org/2x/pl/Question_engine_upgrade_helper
https://docs.moodle.org/dev/Moodle_2.1_release_notes/New_question_engine

If you un-archive the .mbz file (the backup file) in the resulting unarchive look for a moodle_backup.xml - that should tell you what moodle version the course backup came from.    And there is a questions.xml file.   That also might give you  some clues.

There is this discussion from many years ago:
https://moodle.org/mod/forum/discuss.php?d=381494

If you really want to use it, you might have to edit questions.xml and strip out offending tags.

The more info link
https://docs.moodle.org/404/en/error/debug/codingerror
Said this:
This question is of a type that is not installed on your system. No processing is possible.

This is caused because you are attempting to see/use a Quiz that uses (at least) one question that has its status as 'Draft', not ready. Change the status of the question (in the Question bank) to 'Ready' to fix this. 

If you do edit the questions.xml file to give it another try, you will have to repackage the .mbz file from inside the unarchived .mbz to get it to uncompress as moodle would expect it to uncompress.

Fun and Games!

Good luck!

'SoS', Ken

回复Ken Task

moodle_database::get_in_or_equal() error when viewing question bank of restored course

Ken Task -
Particularly helpful Moodlers的头像

Follow up ...

If you have other content in that backup that you'd like to restore, you could try this ...

A backup without any quiz/question bank still has a questions.xml file.

Looks like:

<?xml version="1.0" encoding="UTF-8"?>
<question_categories>
</question_categories>

You could delete the questions.xml file then create a new questions.xml file which consist of nothing but above.

Then recreate the .mbz ... inside the directory or folder with the uncompressed backup, which looks like:

activities
badges.xml
completion.xml
course
files
files.xml
grade_history.xml
gradebook.xml
groups.xml
moodle_backup.log
moodle_backup.xml
outcomes.xml
questions.xml
roles.xml
scales.xml
sections
users.xm

Issue:
tar -czvf backup.mbz ./*

On a mac or Linux.   Dunno if possible on Windows.

The resulting backup.mbz file can be restored ... minus the quizbank/questions.

'SoS', Ken

回复Ken Task

moodle_database::get_in_or_equal() error when viewing question bank of restored course

Ken Task -
Particularly helpful Moodlers的头像

Another follow up ... a catch 22 ... 伤心

If the questions in the original course had images (graphics), those images might be restored to the moodle file system but they could be orphaned ... not associated with anything.

There is yet another option if all you want is the files uploaded to that course.   One could extract the files and save them as humanly recognizable names to upload to a new course in new version.

Have a script for that if interested ... command line only ... mac or Linux only.

Nothing is perfect! :|

'SoS', Ken

回复Ken Task

moodle_database::get_in_or_equal() error when viewing question bank of restored course

Anna S. -
Thanks for the quick and detailed response! It turns out the backup was from version 3.9.

I'll try to do it step by step. Start with an empty question bank as you suggested (I suspect I might need to kill the quizzes that use it as well - we'll see), then add all questions of one type, then another, etc.
 
EDIT: I started by deleting all the quizzes and the question bank error disappeared! I can now access them all. 

I'd love the script, thanks! (I have both mac and linux)
回复Anna S.

moodle_database::get_in_or_equal() error when viewing question bank of restored course

Ken Task -
Particularly helpful Moodlers的头像

Will send you link via PM in this system.

'SoS', Ken

回复Anna S.

moodle_database::get_in_or_equal() error when viewing question bank of restored course

Anna S. -
Some more information. Mostly a more detailed description of what seemed to be broken (but not why), in case it might help someone with the same problem.

When I was trying to figure out what works and what not, I tried to preview some of the restored quizzes. Most worked, but for one of them I got an error that it was not possible to preview it because there were not enough options for a "random" type question to choose from. It was not clear which specific question caused the issue, but all were set up as follows: Choose a random question from category X that has tags Y, Z.

Deleting that particular quiz did not resolve the original error with the question bank, but when I mass-deleted all quizzes, that error went away.

Perhaps one of the categories was not restored properly and was missing questions or perhaps some tags where not restored properly. I'll see if I can find an older backup, to compare. It is still not clear to me why removing the quizzes solved the question bank issue.