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

Course restore can fail if it includes discussion forums

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      I added two backups with dummy activities. Both have only one registered user. The first one has one unique forum subscription for that user, the second one has a duplicate forum subscription.

      For testing this patch, restore both backups.

      Before the patch the backup with the duplicate subscription will fail.

      After the patch both backups can be restored without error.

      Show
      I added two backups with dummy activities. Both have only one registered user. The first one has one unique forum subscription for that user, the second one has a duplicate forum subscription. For testing this patch, restore both backups. Before the patch the backup with the duplicate subscription will fail. After the patch both backups can be restored without error.
    • Affected Branches:
      MOODLE_33_STABLE
    • Fixed Branches:
      MOODLE_33_STABLE, MOODLE_34_STABLE
    • Pull Master Branch:
      MDL-60669-master

      Description

      Note: This only seems to occur if it is a course being restored after that course has been deleted from Moodle.

      After an update of our Moodle on October 20, 2017 using the Moodle 3.3.2+ release, we began noticing that course restores would fail with Moodle delivering the message: "Error writing to database"

      Checking the error logs, we saw this information:

      2017/11/01 13:59:55 [error] 1795#0: *5215685 FastCGI sent in stderr: "PHP message: Default exception handler: Error writing to database Debug: ERROR: duplicate key value violates unique constraint "mdl_forusubs_usefor_uix"
      DETAIL: Key (userid, forum)=(4426, 57209) already exists.
      INSERT INTO mdl_forum_subscriptions (userid,forum) VALUES($1,$2) RETURNING id
      [array (
      'userid' => '4426',
      'forum' => 57209,
      )]
      Error code: dmlwriteexception
      * line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown
      * line 242 of /lib/dml/pgsql_native_moodle_database.php: call to moodle_database->query_end()
      * line 886 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end()
      * line 934 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->insert_record_raw()
      * line 174 of /mod/forum/backup/moodle2/restore_forum_stepslib.php: call to pgsql_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_subscript" while reading upstream, client: 172.16.17.18, server: moodle.ourserver.org, request: "POST /backup/restore.php HTTP/1.0", upstream: "fastcgi://172.16.18.19:9000", host: "moodle.ourserver.org", referrer: "https://moodle.ourserver.org/backup/restore.php"
      

      Looking into the "mdl_forusubs_usefor_uix" constraint, I found an issue that had been recently resolved with the fix being rolled into 3.3.2+ here:

      https://tracker.moodle.org/browse/MDL-59854

      It seems that the new uniqueness constraint for the forum_submissions table is the culprit here.  I was able to have course restores work properly by unchecking any discussion forum entries during the restore process.  Since we sometimes need this information, I've opted to temporarily drop that new index and recreate it without the the unique keyword.

      The commit that caused this issue is here:

      https://git.moodle.org/gw?p=moodle.git;a=commit;h=8db207f90fbf55a3001e7b419a6b1cfe73c5c20d

      and the specific database change operations are here:

      https://git.moodle.org/gw?p=moodle.git;a=blobdiff;f=mod/forum/db/upgrade.php;h=015d453eb5dabcca7463fa624cb7c8931bccc3e6;hp=ae449d58070908f450a56812ae5f6025abfbfa10;hb=8db207f90fbf55a3001e7b419a6b1cfe73c5c20d;hpb=2ffd848807c1336aa088f6488838a3eb520f795b

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              tobias.reischmann Tobias Reischmann
              Reporter:
              neifirst Aaron Bean
              Peer reviewer:
              Ryan Wyllie
              Integrator:
              Damyon Wiese
              Tester:
              Helen Foster
              Participants:
              Component watchers:
              Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
              Votes:
              2 Vote for this issue
              Watchers:
              10 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                15/Jan/18