Find duplicate questions in a Moodle question bank
Imports, restored backups and teachers copying each other's questions leave the same question in a bank several times. Our free qbank_duplicates lists them in groups.
Short answer: Moodle question banks fill up with copies. A course restored twice, a quiz imported again from an old export, two teachers adding the same question to a shared bank. Moodle has no screen that shows them. Our free plugin, qbank_duplicates, adds a Duplicates page to the question bank that lists them in groups.
This is the ninth plugin in our series: one plugin for each Moodle plugin type, each one teaching DevLMS Studio, our AI plugin builder, how that type works.
What it finds
- Questions of the same type, in the category you are looking at, whose text is the same once formatting, capital letters, spaces and punctuation are ignored. “Moodle is written in PHP.” and “moodle is written in php” are one group. A true/false question and a short answer with the same text are not.
- Only the latest version of each question counts, and hidden questions are left out.
- Each group shows the shared text and every copy, with its name, when it last changed and a link to edit it.
- Nothing is deleted or merged for you. You decide which copy stays, which matters because quizzes may already use one of them.
It works with course question banks in Moodle 4.5 and with question bank activities in Moodle 5.0 to 5.3. The code is on GitHub.
How a question bank plugin works
From Moodle 5.3’s own question bank plugins (Import, Export to XML):
- Everything on the question bank screen is a plugin: columns, actions, bulk actions, filters and tabs. A plugin says what it adds in one
plugin_featureclass. - A new tab is a small navigation class plus a page. The page calls
question_edit_setup(), which hides the difference between 4.5’s course banks and 5.x’s bank activities, so one page works on both. - Questions are versioned. Every edit saves a new version, so the query must take only the latest version of each question, or an old wording shows up as a false duplicate.
- The question bank menu is a drop-down that needs JavaScript, and on 5.x the category picker is a JavaScript filter. The browser tests have to run with JavaScript on.
We tested it with PHPUnit (same text with different formatting, different types, a newer version with new text) and a browser test that opens the Duplicates page from the question bank menu.
Need a plugin like this for your own Moodle?
Describe it in DevLMS Studio and watch it built and tested in a real Moodle, or ask our team for a fixed price.
Open DevLMS Studio