Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-35146

Restore of wiki fails with unique constraint violation

    Details

    • Database:
      PostgreSQL
    • Testing Instructions:
      Hide
      1. Create a course.
      2. Enrol a bunch of users into this course.
      3. Under 'Course administration' click on 'Users' then 'Groups'.
      4. Click on 'Auto-create groups'.
      5. Create at least 2 groups.
      6. Go to the course page and create a wiki with 'Group mode' set to 'Separate groups'.
      7. Click on the wiki and create the first page of the wiki with 'Group' set to 'All participants' and click 'Create page'.
      8. Set the HTML format to whatever you want and click 'Save'.
      9. Under 'Separate groups' select the first group you created.
      10. Create this page again but with the 'Group' set to the group you chose and click 'Create page'.
      11. Set the HTML format to the group name to remember it and click 'Save'.
      12. Under 'Wiki administration' click on 'Backup'.
      13. Go through the backup process with default settings.
      14. Once completed click on 'Restore' next to the name of the backup you just created.
      15. Visit the newly created wiki and check that it is the same as the wiki you created the backup of.
      16. Under 'Course administration' click on 'Users' then 'Groups'.
      17. Delete the group you created the wiki page for.
      18. Visit the first wiki you created.
      19. Under 'Wiki administration' click on 'Backup'.
      20. Go through the backup process with default settings.
      21. Once completed click on 'Restore' next to the name of the backup you just created.
      22. Follow the restore process and select the course you created in this test.
      23. Check that it restores successfully and that when browsing the wiki it is the same as the wiki you created the backup of.
      Show
      Create a course. Enrol a bunch of users into this course. Under 'Course administration' click on 'Users' then 'Groups'. Click on 'Auto-create groups'. Create at least 2 groups. Go to the course page and create a wiki with 'Group mode' set to 'Separate groups'. Click on the wiki and create the first page of the wiki with 'Group' set to 'All participants' and click 'Create page'. Set the HTML format to whatever you want and click 'Save'. Under 'Separate groups' select the first group you created. Create this page again but with the 'Group' set to the group you chose and click 'Create page'. Set the HTML format to the group name to remember it and click 'Save'. Under 'Wiki administration' click on 'Backup'. Go through the backup process with default settings. Once completed click on 'Restore' next to the name of the backup you just created. Visit the newly created wiki and check that it is the same as the wiki you created the backup of. Under 'Course administration' click on 'Users' then 'Groups'. Delete the group you created the wiki page for. Visit the first wiki you created. Under 'Wiki administration' click on 'Backup'. Go through the backup process with default settings. Once completed click on 'Restore' next to the name of the backup you just created. Follow the restore process and select the course you created in this test. Check that it restores successfully and that when browsing the wiki it is the same as the wiki you created the backup of.
    • Affected Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE
    • Fixed Branches:
      MOODLE_24_STABLE, MOODLE_25_STABLE
    • Pull Master Branch:
      MDL-35146_master
    • Story Points (Obsolete):
      13
    • Sprint:
      BACKEND Sprint 6

      Description

      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.

      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()
      ...

      Here are the related records from the db:

      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

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Votes:
                  5 Vote for this issue
                  Watchers:
                  12 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    11/Nov/13