Copying a quiz through the block Sharing Cart says "found more than one record!"

Copying a quiz through the block Sharing Cart says "found more than one record!"

Visvanath Ratnaweera - මගින්
Number of replies: 4
Particularly helpful Moodlers ගේ පින්තුරය Translators ගේ පින්තුරය
A teacher tries to copy a quiz from one course to the other through the Sharing Cart and gets "Error: mdb->get_record() found more than one record!" This is reproducible. The debug trace is pasted below. Apparently the problem started after a large scale exchange of question categories with a sister school. Where should I start? Moodle: $version = 2020061516.00;
$release = '3.9.16 (Build: 20220822)';
$branch = '39';
$maturity = MATURITY_STABLE; Sharing Cart: $plugin->version = 2021092900;
$plugin->requires = 2018120300;
$plugin->release = '3.9, release 6';
$plugin->maturity = MATURITY_STABLE; Debug trace:

Error: mdb->get_record() found more than one record!
line 1636 of /lib/dml/moodle_database.php: call to debugging()
line 1697 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()
line 4833 of /backup/moodle2/restore_stepslib.php: call to moodle_database->get_field_sql()
line 137 of /backup/util/plan/restore_structure_step.class.php: call to restore_create_categories_and_questions->process_question_hint()
line 121 of /backup/util/helper/restore_structure_parser_processor.class.php: call to restore_structure_step->process()
line 178 of /backup/util/xml/parser/processors/grouped_parser_processor.class.php: call to restore_structure_parser_processor->dispatch_chunk()
line 109 of /backup/util/helper/restore_structure_parser_processor.class.php: call to grouped_parser_processor->postprocess_chunk()
line 148 of /backup/util/xml/parser/processors/simplified_parser_processor.class.php: call to restore_structure_parser_processor->postprocess_chunk()
line 92 of /backup/util/xml/parser/processors/progressive_parser_processor.class.php: call to simplified_parser_processor->process_chunk()
line 190 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser_processor->receive_chunk()
line 278 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->publish()
line ? of unknownfile: call to progressive_parser->end_tag()
line 179 of /backup/util/xml/parser/progressive_parser.class.php: call to xml_parse()
line 158 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->parse()
line 110 of /backup/util/plan/restore_structure_step.class.php: call to progressive_parser->process()
line 181 of /backup/util/plan/base_task.class.php: call to restore_structure_step->execute()
line 191 of /backup/util/plan/base_plan.class.php: call to base_task->execute()
line 168 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()
line 394 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()
line 537 of /blocks/sharing_cart/classes/controller.php: call to restore_controller->execute_plan()
line 118 of /blocks/sharing_cart/restore.php: call to block_sharing_cart\controller->restore()
Error: mdb->get_record() found more than one record!
line 1636 of /lib/dml/moodle_database.php: call to debugging()
line 1697 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()
line 4833 of /backup/moodle2/restore_stepslib.php: call to moodle_database->get_field_sql()
line 137 of /backup/util/plan/restore_structure_step.class.php: call to restore_create_categories_and_questions->process_question_hint()
line 121 of /backup/util/helper/restore_structure_parser_processor.class.php: call to restore_structure_step->process()
line 178 of /backup/util/xml/parser/processors/grouped_parser_processor.class.php: call to restore_structure_parser_processor->dispatch_chunk() line 109 of
/backup/util/helper/restore_structure_parser_processor.class.php: call to grouped_parser_processor->postprocess_chunk() line 148 of
/backup/util/xml/parser/processors/simplified_parser_processor.class.php:
call to restore_structure_parser_processor->postprocess_chunk() line 92 of /backup/util/xml/parser/processors/progressive_parser_processor.class.php: call to simplified_parser_processor->process_chunk()
line 190 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser_processor->receive_chunk()
line 278 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->publish()
line ? of unknownfile: call to progressive_parser->end_tag()
line 179 of /backup/util/xml/parser/progressive_parser.class.php: call to xml_parse()
line 158 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->parse()
line 110 of /backup/util/plan/restore_structure_step.class.php: call to progressive_parser->process()
line 181 of /backup/util/plan/base_task.class.php: call to restore_structure_step->execute()
line 191 of /backup/util/plan/base_plan.class.php: call to base_task->execute()
line 168 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()
line 394 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()
line 537 of /blocks/sharing_cart/classes/controller.php: call to restore_controller->execute_plan()
line 118 of /blocks/sharing_cart/restore.php: call to block_sharing_cart\controller->restore()
ශ්‍රේණිගත කිරීම්වල සාමාන්යය: -
In reply to Visvanath Ratnaweera

Re: Copying a quiz through the block Sharing Cart says "found more than one record!"

Emma Richardson - මගින්
Documentation writers ගේ පින්තුරය Particularly helpful Moodlers ගේ පින්තුරය Plugin developers ගේ පින්තුරය
There are so many problems with the question bank sharing and backup and restore process. I would suggest that until https://tracker.moodle.org/browse/MDL-41924 has some resolution to not even try it, especially if you have a large question bank.
For this specific issue, I am guessing that when they imported the question bank from other school, some id was duplicated. I would start by looking at the lines referenced in the debug code and see if they don't all point to a specific table and then go to that table and search for duplicates...
ශ්‍රේණිගත කිරීම්වල සාමාන්යය: Useful (1)
In reply to Emma Richardson

Re: Copying a quiz through the block Sharing Cart says "found more than one record!"

Nathan Lind - මගින්
Hi Emma,
Grateful for your reply. Does your suggestion to try avoiding copying quizzes also apply to the Backup/Restore process, and the Import Process, or only when using the Sharing Cart? Just clarifying what you meant by "so many problems with the question bank sharing and backup and restore process".
For the Tracker MDL-41924, should additional versions be added to the list of Affected Versions?
Just hoping all the bases are covered for this fix request.
Many thanks!
Nathan
ශ්‍රේණිගත කිරීම්වල සාමාන්යය: -
In reply to Nathan Lind

Re: Copying a quiz through the block Sharing Cart says "found more than one record!"

Emma Richardson - මගින්
Documentation writers ගේ පින්තුරය Particularly helpful Moodlers ගේ පින්තුරය Plugin developers ගේ පින්තුරය
All processes that use backup/restore. The big issue is that the entire question bank is included in any quiz copy/backup/restore and times out if you actually have a useful sized bank! Thanks for moving that to a bug instead of improvement and yes, it is still an issue so affects clear through 4.2...
ශ්‍රේණිගත කිරීම්වල සාමාන්යය: -
In reply to Emma Richardson

Re: Copying a quiz through the block Sharing Cart says "found more than one record!"

Visvanath Ratnaweera - මගින්
Particularly helpful Moodlers ගේ පින්තුරය Translators ගේ පින්තුරය
Hi Emma

Completely new land for me! I have seen plenty of cases about questions banks multiplying etc. This is the first time it happened to my users.

Let's make a start. Here is ./blocks/sharing_cart/restore.php

<?php
use block_sharing_cart\controller;
use block_sharing_cart\section_title_form;

require_once '../../config.php';

global $OUTPUT, $PAGE;

$directory = required_param('directory', PARAM_BOOL);
$id = null;
$path = null;

if ($directory) {
$path = required_param('path', PARAM_TEXT);
} else {
$id = required_param('id', PARAM_INT);
}
$courseid = required_param('course', PARAM_INT);
$sectionnumber = required_param('section', PARAM_INT);
$in_section = optional_param('in_section', 0, PARAM_INT);

if ($courseid == SITEID) {
$returnurl = new moodle_url('/');
} else {
$returnurl = new moodle_url('/course/view.php', array('id' => $courseid));
}

if ($in_section) {
$returnurl .= '&section=' . $sectionnumber;
} else {
$returnurl .= '#section-' . $sectionnumber;
}

require_login($courseid);

try {
$controller = new controller();

if ($directory) { <--
$form = new section_title_form($directory, $path, $courseid, $sectionnumber, array());

[...]

} else {
$controller->restore($id, $courseid, $sectionnumber); <-- Line 118
}
Line 118 is the place where it goes wrong. From the error message "line 118 of /blocks/sharing_cart/restore.php: call to block_sharing_cart\controller->restore() Error: mdb->get_record() found more than one record!" I assume, there is another 'id'.

What is that 'id'? Anybody knows?
ශ්‍රේණිගත කිරීම්වල සාමාන්යය: -