MDL-4908 Forum: Add backup/restore steps for per-forum digest settings
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 6 Aug 2013 22:41:13 +0000 (23:41 +0100)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 13 Aug 2013 13:46:11 +0000 (14:46 +0100)
mod/forum/backup/moodle2/backup_forum_stepslib.php
mod/forum/backup/moodle2/restore_forum_stepslib.php
mod/forum/lang/en/forum.php

index 2ad3580..1a47641 100644 (file)
@@ -70,6 +70,11 @@ class backup_forum_activity_structure_step extends backup_activity_structure_ste
         $subscription = new backup_nested_element('subscription', array('id'), array(
             'userid'));
 
+        $digests = new backup_nested_element('digests');
+
+        $digest = new backup_nested_element('digest', array('id'), array(
+            'userid', 'maildigest'));
+
         $readposts = new backup_nested_element('readposts');
 
         $read = new backup_nested_element('read', array('id'), array(
@@ -89,6 +94,9 @@ class backup_forum_activity_structure_step extends backup_activity_structure_ste
         $forum->add_child($subscriptions);
         $subscriptions->add_child($subscription);
 
+        $forum->add_child($digests);
+        $digests->add_child($digest);
+
         $forum->add_child($readposts);
         $readposts->add_child($read);
 
@@ -118,6 +126,8 @@ class backup_forum_activity_structure_step extends backup_activity_structure_ste
 
             $subscription->set_source_table('forum_subscriptions', array('forum' => backup::VAR_PARENTID));
 
+            $digest->set_source_table('forum_digests', array('forum' => backup::VAR_PARENTID));
+
             $read->set_source_table('forum_read', array('forumid' => backup::VAR_PARENTID));
 
             $track->set_source_table('forum_track_prefs', array('forumid' => backup::VAR_PARENTID));
@@ -143,6 +153,8 @@ class backup_forum_activity_structure_step extends backup_activity_structure_ste
 
         $subscription->annotate_ids('user', 'userid');
 
+        $digest->annotate_ids('user', 'userid');
+
         $read->annotate_ids('user', 'userid');
 
         $track->annotate_ids('user', 'userid');
index c5b2386..2dfac63 100644 (file)
@@ -42,6 +42,7 @@ class restore_forum_activity_structure_step extends restore_activity_structure_s
             $paths[] = new restore_path_element('forum_post', '/activity/forum/discussions/discussion/posts/post');
             $paths[] = new restore_path_element('forum_rating', '/activity/forum/discussions/discussion/posts/post/ratings/rating');
             $paths[] = new restore_path_element('forum_subscription', '/activity/forum/subscriptions/subscription');
+            $paths[] = new restore_path_element('forum_digest', '/activity/forum/digests/digest');
             $paths[] = new restore_path_element('forum_read', '/activity/forum/readposts/read');
             $paths[] = new restore_path_element('forum_track', '/activity/forum/trackedprefs/track');
         }
@@ -149,6 +150,18 @@ class restore_forum_activity_structure_step extends restore_activity_structure_s
         $newitemid = $DB->insert_record('forum_subscriptions', $data);
     }
 
+    protected function process_forum_digest($data) {
+        global $DB;
+
+        $data = (object)$data;
+        $oldid = $data->id;
+
+        $data->forum = $this->get_new_parentid('forum');
+        $data->userid = $this->get_mappingid('user', $data->userid);
+
+        $newitemid = $DB->insert_record('forum_digests', $data);
+    }
+
     protected function process_forum_read($data) {
         global $DB;
 
index f8af84d..7653e3a 100644 (file)
@@ -158,7 +158,7 @@ $string['emaildigesttype_help'] = 'The type of notification that you will receiv
 $string['emaildigestupdated'] = 'The e-mail digest option was changed to \'{$a->maildigesttitle}\' for the forum \'{$a->forum}\'. {$a->maildigestdescription}';
 $string['emaildigestupdated_default'] = 'Your default profile setting of \'{$a->maildigesttitle}\' was used for the forum \'{$a->forum}\'. {$a->maildigestdescription}.';
 $string['emaildigest_0'] = 'You will receive one e-mail per forum post.';
-$string['emaildigest_1'] = 'You will receive one digest e-mail per day containing the  complete contents of each forum post.';
+$string['emaildigest_1'] = 'You will receive one digest e-mail per day containing the complete contents of each forum post.';
 $string['emaildigest_2'] = 'You will receive one digest e-mail per day containing the subject of each forum post.';
 $string['emptymessage'] = 'Something was wrong with your post. Perhaps you left it blank, or the attachment was too big. Your changes have NOT been saved.';
 $string['erroremptymessage'] = 'Post message cannot be empty';