Skip to content

Commit

Permalink
MDL-60669 forum: Added duplicate check for restoring forum subscriptions
Browse files Browse the repository at this point in the history
Before MDL-59854 it was possible to have duplicate forum subscriptions.
Trying to import backups created from back then, caused a DB exception
due to unqiue key constraints. Now only one of multiple identical forum
subscritions is restored.
  • Loading branch information
tobiasreischmann committed Nov 27, 2017
1 parent 5bde2c2 commit 9bd6807
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mod/forum/backup/moodle2/restore_forum_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,14 @@ protected function process_forum_subscription($data) {
$data->forum = $this->get_new_parentid('forum');
$data->userid = $this->get_mappingid('user', $data->userid);

$newitemid = $DB->insert_record('forum_subscriptions', $data);
$this->set_mapping('forum_subscription', $oldid, $newitemid, true);
// Create only a new subscription if it does not already exist (see MDL-59854).
if ($subscription = $DB->get_record('forum_subscriptions',
array('forum' => $data->forum, 'userid' => $data->userid))) {
$this->set_mapping('forum_subscription', $oldid, $subscription->id, true);
} else {
$newitemid = $DB->insert_record('forum_subscriptions', $data);
$this->set_mapping('forum_subscription', $oldid, $newitemid, true);
}

}

Expand Down

0 comments on commit 9bd6807

Please sign in to comment.