Posts made by Tim Hunt

Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

There really should not be qtype_random instances any more.

The Moodle 4.0 & 4.3 changes were supposed to finally phase out the use of this fake quetion type. The randomisation feature in quizzes is now handled in a completely different way. But something must have been missed somewhere. The qtype_random plugin still exists in the code, but that should only be to support restore of old backups ... and that is probably where the problem lies.

I have just checked our Moodle db, and we seem to have unnecessary 40,000 random questions too.

I believe (but am not yet confident) that it is completely safe to run the three clean-up queries

DELETE FROM mdl_question_bank_entries
WHERE id IN (
SELECT qv.questionbankentryid
FROM mdl_question_versions qv
JOIN mdl_question q ON q.id = qv.questionid
WHERE q.qtype = 'random'
)

DELETE FROM mdl_question_versions qv
WHERE questionid IN (
SELECT id FROM mdl_question q WHERE q.qtype = 'random'
)

DELETE FROM mdl_question WHERE qtype = 'random'

Note, you can get some confidence that nothing is referring to these random questions by running the following 2 queries, which should both return 0 rows.

SELECT *
FROM mdl_question_attempts qa
JOIN mdl_question q ON q.id = qa.questionid
WHERE q.qtype = 'random'
SELECT *
FROM mdl_question_references qr
JOIN mdl_question_versions qv ON qv.questionbankentryid = qr.questionbankentryid
JOIN mdl_question q ON q.id = qv.questionid
WHERE q.qtype = 'random'

To see how many random questions you have in your database, the query is

SELECT COUNT(1) FROM mdl_question WHERE qtype = 'random'

For now, please only try this clean-up if you know what you are doing, and re able to test it first. (I have just tried it on our test server - fortuanately we are in a period of testing at the moment.)

If anyone can track down where these "should not exist" random questions are coming from, please tell us. This is a bug that needs to be fixed.

Average of ratings: Useful (7)
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
You have to teach the generator how to create instances of your plugin. That requires code in mod/myplugin/tests/generator/lib.php. If you look at some other examples from other plugins, it should be clear what you need to do.
Average of ratings: Useful (1)
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
This sort of initalisation takes places when the quiz (or whatever is using the queston) calls $quba->start_all_questions() which calls $qa->start(...) for each question in the quiz.

That initalises a bunch of stuff before calling $this->behaviour->init_first_step($firststep, $variant); and the question bahaviour then passes that on to the question type be calling $this->question->start_attempt($step, $variant);

So, for a multiple choice question you are looking for start_attempt in question/type/multichoice/question.php, and for matching, similarly in question/type/match/question.php.

You may find https://docs.moodle.org/dev/Using_the_question_engine_from_module if you have not seen it before.
Average of ratings: Useful (2)