Project: moodle
Issue MDL-35146: Restore of wiki fails with unique constraint violation
In a Moodle 2.3.1 that was upgraded from 1.9.x => 2.2.x => 2.3.1, backing up then restoring a course with a particular wiki in it fails with a database error. Although the database has some data related to this wiki, it appears when viewing the wiki in the source course that it has no pages. The wiki was created before the upgrade from 1.9 to 2.3.1. {noformat} Default exception handler: Error writing to database Debug: ERROR: duplicate key value violates unique constraint "mdl_wikisubw_wikgrouse_uix" INSERT INTO mdl_wiki_subwikis (groupid,userid,wikiid) VALUES($1,$2,$3) RETURNING id [array ( 'groupid' => 0, 'userid' => 0, 'wikiid' => 2749, )] Error code: dmlwriteexception * line 410 of /lib/dml/moodle_database.php: dml_write_exception thrown * line 239 of /lib/dml/pgsql_native_moodle_database.php: call to moodle_database->query_end() * line 812 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end() * line 864 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->insert_record_raw() * line 80 of /mod/wiki/backup/moodle2/restore_wiki_stepslib.php: call to pgsql_native_moodle_database->insert_record() * line 131 of /backup/util/plan/restore_structure_step.class.php: call to restore_wiki_activity_structure_step->process_wiki_subwiki() * line 103 of /backup/util/helper/restore_structure_parser_processor.class.php: call to restore_structure_step->process() * line 125 of /backup/util/xml/parser/processors/grouped_parser_processor.class.php: call to restore_structure_parser_processor->dispatch_chunk() * line 91 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 169 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser_processor->receive_chunk() * line 212 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->publish() * line ? of unknownfile: call to progressive_parser->start_tag() * line 158 of /backup/util/xml/parser/progressive_parser.class.php: call to xml_parse() * line 137 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->parse() * line 105 of /backup/util/plan/restore_structure_step.class.php: call to progressive_parser->process() * line 153 of /backup/util/plan/base_task.class.php: call to restore_structure_step->execute() * line 192 of /backup/moodle2/restore_activity_task.class.php: call to base_task->execute() * line 163 of /backup/util/plan/base_plan.class.php: call to restore_activity_task->execute() * line 157 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute() * line 315 of /backup/controller/restore_controller.class.php: call to restore_plan->execute() ... {noformat} Here are the related records from the db: {noformat} moodle=# select * from mdl_course_modules where id=179212; id | course | module | instance | section | idnumber | added | score | indent | visible | visibleold | groupmode | groupingid | groupmembersonly | completion | completiongradeitemnumber | completionview | completionexpected | availablefrom | availableuntil | showavailability | showdescription --------+--------+--------+----------+---------+----------+------------+-------+--------+---------+------------+-----------+------------+------------------+------------+---------------------------+----------------+--------------------+---------------+----------------+------------------+----------------- 179212 | 4371 | 16 | 2557 | 52394 | | 1327672348 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | | 0 | 0 | 0 | 0 | 0 | 0 moodle=# select * from mdl_wiki where id=2557; id | course | name | timemodified | intro | introformat | firstpagetitle | wikimode | defaultformat | forceformat | editbegin | editend | timecreated ------+--------+------------------------------------------------------------------+--------------+-------------------------------------------------------------------------+-------------+-----------------------------------------+---------------+---------------+-------------+-----------+---------+------------- 2557 | 4371 | anonymized "Anonymized" | 1331379009 | Anonymized | 0 | anonymized "anonymized" | collaborative | html | 1 | 0 | 0 | 0 moodle=# select * from mdl_wiki_subwikis where wikiid=2557; id | wikiid | groupid | userid ------+--------+---------+-------- 237 | 2557 | 5646 | 0 590 | 2557 | 5649 | 0 650 | 2557 | 5645 | 0 992 | 2557 | 5648 | 0 1557 | 2557 | 5644 | 0 1999 | 2557 | 5647 | 0 2251 | 2557 | 0 | 0 moodle=# select id, subwikiid, 'anonymized' as title, 'anonymized' as cachedcontent, timecreated, timemodified, timerendered, userid, pageviews, readonly from mdl_wiki_pages where subwikiid in (select id from mdl_wiki_subwikis where wikiid=2557); id | subwikiid | title | cachedcontent | timecreated | timemodified | timerendered | userid | pageviews | readonly ------+-----------+------------+---------------+-------------+--------------+--------------+--------+-----------+---------- 6719 | 1557 | anonymized | anonymized | 1327672570 | 1332150929 | 1345290323 | 13020 | 230 | 0 6724 | 1999 | anonymized | anonymized | 1327672984 | 1332460271 | 1345290323 | 13044 | 111 | 0 6723 | 590 | anonymized | anonymized | 1327672870 | 1333543094 | 1345290323 | 6542 | 119 | 0 7290 | 2251 | anonymized | anonymized | 1346323212 | 1346323212 | 1346327547 | 20760 | 8 | 0 6721 | 237 | anonymized | anonymized | 1327672701 | 1331551184 | 1345290323 | 9094 | 117 | 0 6720 | 650 | anonymized | anonymized | 1327672976 | 1334228293 | 1345290323 | 10764 | 94 | 0 6722 | 992 | anonymized | anonymized | 1327672861 | 1332347078 | 1345290323 | 10845 | 140 | 0 {noformat}
Story points: 13