[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/forum/backup/moodle2/ -> backup_forum_stepslib.php (source)

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * @package    mod_forum
  20   * @subpackage backup-moodle2
  21   * @copyright  2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  /**
  26   * Define all the backup steps that will be used by the backup_forum_activity_task
  27   */
  28  
  29  /**
  30   * Define the complete forum structure for backup, with file and id annotations
  31   */
  32  class backup_forum_activity_structure_step extends backup_activity_structure_step {
  33  
  34      protected function define_structure() {
  35  
  36          // To know if we are including userinfo
  37          $userinfo = $this->get_setting_value('userinfo');
  38  
  39          // Define each element separated
  40  
  41          $forum = new backup_nested_element('forum', array('id'), array(
  42              'type', 'name', 'intro', 'introformat',
  43              'assessed', 'assesstimestart', 'assesstimefinish', 'scale',
  44              'maxbytes', 'maxattachments', 'forcesubscribe', 'trackingtype',
  45              'rsstype', 'rssarticles', 'timemodified', 'warnafter',
  46              'blockafter', 'blockperiod', 'completiondiscussions', 'completionreplies',
  47              'completionposts', 'displaywordcount'));
  48  
  49          $discussions = new backup_nested_element('discussions');
  50  
  51          $discussion = new backup_nested_element('discussion', array('id'), array(
  52              'name', 'firstpost', 'userid', 'groupid',
  53              'assessed', 'timemodified', 'usermodified', 'timestart',
  54              'timeend', 'pinned'));
  55  
  56          $posts = new backup_nested_element('posts');
  57  
  58          $post = new backup_nested_element('post', array('id'), array(
  59              'parent', 'userid', 'created', 'modified',
  60              'mailed', 'subject', 'message', 'messageformat',
  61              'messagetrust', 'attachment', 'totalscore', 'mailnow'));
  62  
  63          $ratings = new backup_nested_element('ratings');
  64  
  65          $rating = new backup_nested_element('rating', array('id'), array(
  66              'component', 'ratingarea', 'scaleid', 'value', 'userid', 'timecreated', 'timemodified'));
  67  
  68          $discussionsubs = new backup_nested_element('discussion_subs');
  69  
  70          $discussionsub = new backup_nested_element('discussion_sub', array('id'), array(
  71              'userid',
  72              'preference',
  73          ));
  74  
  75          $subscriptions = new backup_nested_element('subscriptions');
  76  
  77          $subscription = new backup_nested_element('subscription', array('id'), array(
  78              'userid'));
  79  
  80          $digests = new backup_nested_element('digests');
  81  
  82          $digest = new backup_nested_element('digest', array('id'), array(
  83              'userid', 'maildigest'));
  84  
  85          $readposts = new backup_nested_element('readposts');
  86  
  87          $read = new backup_nested_element('read', array('id'), array(
  88              'userid', 'discussionid', 'postid', 'firstread',
  89              'lastread'));
  90  
  91          $trackedprefs = new backup_nested_element('trackedprefs');
  92  
  93          $track = new backup_nested_element('track', array('id'), array(
  94              'userid'));
  95  
  96          // Build the tree
  97  
  98          $forum->add_child($discussions);
  99          $discussions->add_child($discussion);
 100  
 101          $forum->add_child($subscriptions);
 102          $subscriptions->add_child($subscription);
 103  
 104          $forum->add_child($digests);
 105          $digests->add_child($digest);
 106  
 107          $forum->add_child($readposts);
 108          $readposts->add_child($read);
 109  
 110          $forum->add_child($trackedprefs);
 111          $trackedprefs->add_child($track);
 112  
 113          $discussion->add_child($posts);
 114          $posts->add_child($post);
 115  
 116          $post->add_child($ratings);
 117          $ratings->add_child($rating);
 118  
 119          $discussion->add_child($discussionsubs);
 120          $discussionsubs->add_child($discussionsub);
 121  
 122          // Define sources
 123  
 124          $forum->set_source_table('forum', array('id' => backup::VAR_ACTIVITYID));
 125  
 126          // All these source definitions only happen if we are including user info
 127          if ($userinfo) {
 128              $discussion->set_source_sql('
 129                  SELECT *
 130                    FROM {forum_discussions}
 131                   WHERE forum = ?',
 132                  array(backup::VAR_PARENTID));
 133  
 134              // Need posts ordered by id so parents are always before childs on restore
 135              $post->set_source_table('forum_posts', array('discussion' => backup::VAR_PARENTID), 'id ASC');
 136              $discussionsub->set_source_table('forum_discussion_subs', array('discussion' => backup::VAR_PARENTID));
 137  
 138              $subscription->set_source_table('forum_subscriptions', array('forum' => backup::VAR_PARENTID));
 139              $digest->set_source_table('forum_digests', array('forum' => backup::VAR_PARENTID));
 140  
 141              $read->set_source_table('forum_read', array('forumid' => backup::VAR_PARENTID));
 142  
 143              $track->set_source_table('forum_track_prefs', array('forumid' => backup::VAR_PARENTID));
 144  
 145              $rating->set_source_table('rating', array('contextid'  => backup::VAR_CONTEXTID,
 146                                                        'component'  => backup_helper::is_sqlparam('mod_forum'),
 147                                                        'ratingarea' => backup_helper::is_sqlparam('post'),
 148                                                        'itemid'     => backup::VAR_PARENTID));
 149              $rating->set_source_alias('rating', 'value');
 150          }
 151  
 152          // Define id annotations
 153  
 154          $forum->annotate_ids('scale', 'scale');
 155  
 156          $discussion->annotate_ids('group', 'groupid');
 157  
 158          $post->annotate_ids('user', 'userid');
 159  
 160          $discussionsub->annotate_ids('user', 'userid');
 161  
 162          $rating->annotate_ids('scale', 'scaleid');
 163  
 164          $rating->annotate_ids('user', 'userid');
 165  
 166          $subscription->annotate_ids('user', 'userid');
 167  
 168          $digest->annotate_ids('user', 'userid');
 169  
 170          $read->annotate_ids('user', 'userid');
 171  
 172          $track->annotate_ids('user', 'userid');
 173  
 174          // Define file annotations
 175  
 176          $forum->annotate_files('mod_forum', 'intro', null); // This file area hasn't itemid
 177  
 178          $post->annotate_files('mod_forum', 'post', 'id');
 179          $post->annotate_files('mod_forum', 'attachment', 'id');
 180  
 181          // Return the root element (forum), wrapped into standard activity structure
 182          return $this->prepare_activity_structure($forum);
 183      }
 184  
 185  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1