Commit 9bd68076 authored by Tobias Reischmann's avatar Tobias Reischmann
Browse files

MDL-60669 forum: Added duplicate check for restoring forum subscriptions

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.
parent 5bde2c2b
......@@ -168,8 +168,14 @@ class restore_forum_activity_structure_step extends restore_activity_structure_s
$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);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment