[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/backup/moodle2/ -> restore_block_task.class.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   * Defines restore_block_task class
  20   *
  21   * @package     core_backup
  22   * @subpackage  moodle2
  23   * @category    backup
  24   * @copyright   2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  25   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  /**
  31   * abstract block task that provides all the properties and common steps to be performed
  32   * when one block is being restored
  33   *
  34   * TODO: Finish phpdocs
  35   */
  36  abstract class restore_block_task extends restore_task {
  37  
  38      protected $taskbasepath; // To store the basepath of this block
  39      protected $blockname;    // Name of the block
  40      protected $contextid;   // new (target) context of the block
  41      protected $oldcontextid;// old (original) context of the block
  42      protected $blockid;     // new (target) id of the block
  43      protected $oldblockid;  // old (original) id of the block
  44  
  45      /**
  46       * Constructor - instantiates one object of this class
  47       */
  48      public function __construct($name, $taskbasepath, $plan = null) {
  49          $this->taskbasepath = $taskbasepath;
  50          $this->blockname = '';
  51          $this->contextid = 0;
  52          $this->oldcontextid = 0;
  53          $this->blockid = 0;
  54          $this->oldblockid = 0;
  55          parent::__construct($name, $plan);
  56      }
  57  
  58      /**
  59       * Block tasks have their own directory to write files
  60       */
  61      public function get_taskbasepath() {
  62          return $this->taskbasepath;
  63      }
  64  
  65      /**
  66       * Create all the steps that will be part of this task
  67       */
  68      public function build() {
  69  
  70          // If we have decided not to backup blocks, prevent anything to be built
  71          if (!$this->get_setting_value('blocks')) {
  72              $this->built = true;
  73              return;
  74          }
  75  
  76          // If "child" of activity task and it has been excluded, nothing to do
  77          $parent = basename(dirname(dirname($this->taskbasepath)));
  78          if ($parent != 'course') {
  79              $includedsetting = $parent . '_included';
  80              if (!$this->get_setting_value($includedsetting)) {
  81                  $this->built = true;
  82                  return;
  83              }
  84          }
  85  
  86          // Process the block.xml common file (instance + positions)
  87          $this->add_step(new restore_block_instance_structure_step('block_commons', 'block.xml'));
  88  
  89          // Here we add all the common steps for any block and, in the point of interest
  90          // we call to define_my_steps() in order to get the particular ones inserted in place.
  91          $this->define_my_steps();
  92  
  93          // Restore block role assignments and overrides (internally will observe the role_assignments setting)
  94          $this->add_step(new restore_ras_and_caps_structure_step('block_ras_and_caps', 'roles.xml'));
  95  
  96          // Restore block comments (conditionally)
  97          if ($this->get_setting_value('comments')) {
  98              $this->add_step(new restore_comments_structure_step('block_comments', 'comments.xml'));
  99          }
 100  
 101          // At the end, mark it as built
 102          $this->built = true;
 103      }
 104  
 105      public function set_blockname($blockname) {
 106          $this->blockname = $blockname;
 107      }
 108  
 109      public function get_blockname() {
 110          return $this->blockname;
 111      }
 112  
 113      public function set_blockid($blockid) {
 114          $this->blockid = $blockid;
 115      }
 116  
 117      public function get_blockid() {
 118          return $this->blockid;
 119      }
 120  
 121      public function set_old_blockid($blockid) {
 122          $this->oldblockid = $blockid;
 123      }
 124  
 125      public function get_old_blockid() {
 126          return $this->oldblockid;
 127      }
 128  
 129      public function set_contextid($contextid) {
 130          $this->contextid = $contextid;
 131      }
 132  
 133      public function get_contextid() {
 134          return $this->contextid;
 135      }
 136  
 137      public function set_old_contextid($contextid) {
 138          $this->oldcontextid = $contextid;
 139      }
 140  
 141      public function get_old_contextid() {
 142          return $this->oldcontextid;
 143      }
 144  
 145      /**
 146       * Define one array() of fileareas that each block controls
 147       */
 148      abstract public function get_fileareas();
 149  
 150      /**
 151       * Define one array() of configdata attributes
 152       * that need to be decoded
 153       */
 154      abstract public function get_configdata_encoded_attributes();
 155  
 156      /**
 157       * Define the contents in the activity that must be
 158       * processed by the link decoder
 159       */
 160      static public function define_decode_contents() {
 161          throw new coding_exception('define_decode_contents() method needs to be overridden in each subclass of restore_block_task');
 162      }
 163  
 164      /**
 165       * Define the decoding rules for links belonging
 166       * to the activity to be executed by the link decoder
 167       */
 168      static public function define_decode_rules() {
 169          throw new coding_exception('define_decode_rules() method needs to be overridden in each subclass of restore_block_task');
 170      }
 171  
 172  // Protected API starts here
 173  
 174      /**
 175       * Define the common setting that any backup block will have
 176       */
 177      protected function define_settings() {
 178  
 179          // Nothing to add, blocks doesn't have common settings (for now)
 180  
 181          // End of common activity settings, let's add the particular ones
 182          $this->define_my_settings();
 183      }
 184  
 185      /**
 186       * Define (add) particular settings that each block can have
 187       */
 188      abstract protected function define_my_settings();
 189  
 190      /**
 191       * Define (add) particular steps that each block can have
 192       */
 193      abstract protected function define_my_steps();
 194  }


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