I have backed up a course and am trying to restore it within the same site as a new course. When I do so, I get the following error:
Default exception handler: Error writing to database Debug: Duplicate entry '6-109' for key 'mdl_forusubs_usefor_uix'
INSERT INTO mdl_forum_subscriptions (userid,forum) VALUES(?,?)
0 => '6',
1 => 109,
Error code: dmlwriteexception
For the course I'm trying to restore, the duplicate entry is always 6, but the other value changes. It's been 109, 127, 129, etc. Looking at the mdl_forum_subscriptions table, the 6 is the user id and the second number is the forum to which the user is subscribed. When I tried to backup and restore another course, I got an identical error message, but for user 7.
I've looked in the mdl_forum_subscriptions table for the Moodle installation from which I backed up the course and to which I'm trying to restore it (same site), and there isn't a single row with user 6 or 7 and any of the forum IDs which are coming back as duplicates, let alone two duplicate entries.
Based on other forum threads, I have increased max_allowed_packet to 100M in my.cnf, which did not help. The entire backup file is just ~27M. The database is already in Barracuda format.
If I restore the course without user data, it works fine. However, that means I lose all the forum posts, which are an important part of the course setup, so that's not an option. However, I don't need the forum subscriptions, if there was some way to just strip that part of the backup file? I've unzipped the .mbz file and dug around, but I don't know what I'm looking for. (And besides, as I said above, the table for the original course doesn't include the subscriptions which are showing up as duplicate in the debugging message.)
We recently upgraded to Moodle 3.4. The change to Barracuda was also fairly recent, but everything seems to be working apart from this issue. Any suggestions?
Here is the stack trace
line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown
line 1300 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
line 1346 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
line 171 of /mod/forum/backup/moodle2/restore_forum_stepslib.php: call to mysqli_native_moodle_database->insert_record()
line 137 of /backup/util/plan/restore_structure_step.class.php: call to restore_forum_activity_structure_step->process_forum_subscription()
line 112 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 100 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 210 of /backup/moodle2/restore_activity_task.class.php: call to base_task->execute()
line 178 of /backup/util/plan/base_plan.class.php: call to restore_activity_task->execute()
line 167 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()
line 339 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()
line 224 of /backup/util/ui/restore_ui.class.php: call to restore_controller->execute_plan()
line 135 of /backup/restore.php: call to restore_ui->execute()