[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/backup/moodle2/ -> restore_plan_builder.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_plan_builder 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  require_once($CFG->dirroot . '/backup/moodle2/restore_root_task.class.php');
  31  require_once($CFG->dirroot . '/backup/moodle2/restore_course_task.class.php');
  32  require_once($CFG->dirroot . '/backup/moodle2/restore_section_task.class.php');
  33  require_once($CFG->dirroot . '/backup/moodle2/restore_activity_task.class.php');
  34  require_once($CFG->dirroot . '/backup/moodle2/restore_final_task.class.php');
  35  require_once($CFG->dirroot . '/backup/moodle2/restore_block_task.class.php');
  36  require_once($CFG->dirroot . '/backup/moodle2/restore_default_block_task.class.php');
  37  require_once($CFG->dirroot . '/backup/moodle2/restore_plugin.class.php');
  38  require_once($CFG->dirroot . '/backup/moodle2/restore_qtype_plugin.class.php');
  39  require_once($CFG->dirroot . '/backup/moodle2/restore_format_plugin.class.php');
  40  require_once($CFG->dirroot . '/backup/moodle2/restore_local_plugin.class.php');
  41  require_once($CFG->dirroot . '/backup/moodle2/restore_theme_plugin.class.php');
  42  require_once($CFG->dirroot . '/backup/moodle2/restore_report_plugin.class.php');
  43  require_once($CFG->dirroot . '/backup/moodle2/restore_coursereport_plugin.class.php');
  44  require_once($CFG->dirroot . '/backup/moodle2/restore_plagiarism_plugin.class.php');
  45  require_once($CFG->dirroot . '/backup/moodle2/restore_gradingform_plugin.class.php');
  46  require_once($CFG->dirroot . '/backup/moodle2/restore_enrol_plugin.class.php');
  47  require_once($CFG->dirroot . '/backup/moodle2/backup_plugin.class.php');
  48  require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_plugin.class.php');
  49  require_once($CFG->dirroot . '/backup/moodle2/backup_format_plugin.class.php');
  50  require_once($CFG->dirroot . '/backup/moodle2/backup_local_plugin.class.php');
  51  require_once($CFG->dirroot . '/backup/moodle2/backup_theme_plugin.class.php');
  52  require_once($CFG->dirroot . '/backup/moodle2/backup_report_plugin.class.php');
  53  require_once($CFG->dirroot . '/backup/moodle2/backup_coursereport_plugin.class.php');
  54  require_once($CFG->dirroot . '/backup/moodle2/backup_plagiarism_plugin.class.php');
  55  require_once($CFG->dirroot . '/backup/moodle2/backup_gradingform_plugin.class.php');
  56  require_once($CFG->dirroot . '/backup/moodle2/backup_enrol_plugin.class.php');
  57  require_once($CFG->dirroot . '/backup/moodle2/restore_subplugin.class.php');
  58  require_once($CFG->dirroot . '/backup/moodle2/restore_settingslib.php');
  59  require_once($CFG->dirroot . '/backup/moodle2/restore_stepslib.php');
  60  
  61  // Load all the activity tasks for moodle2 format
  62  $mods = core_component::get_plugin_list('mod');
  63  foreach ($mods as $mod => $moddir) {
  64      $taskpath = $moddir . '/backup/moodle2/restore_' . $mod . '_activity_task.class.php';
  65      if (plugin_supports('mod', $mod, FEATURE_BACKUP_MOODLE2)) {
  66          if (file_exists($taskpath)) {
  67              require_once($taskpath);
  68          }
  69      }
  70  }
  71  
  72  // Load all the block tasks for moodle2 format
  73  $blocks = core_component::get_plugin_list('block');
  74  foreach ($blocks as $block => $blockdir) {
  75      $taskpath = $blockdir . '/backup/moodle2/restore_' . $block . '_block_task.class.php';
  76      if (file_exists($taskpath)) {
  77          require_once($taskpath);
  78      }
  79  }
  80  
  81  /**
  82   * Abstract class defining the static method in charge of building the whole
  83   * restore plan, based in @restore_controller preferences.
  84   *
  85   * TODO: Finish phpdocs
  86   */
  87  abstract class restore_plan_builder {
  88  
  89      /**
  90       * Dispatches, based on type to specialised builders
  91       */
  92      static public function build_plan($controller) {
  93  
  94          $plan = $controller->get_plan();
  95  
  96          // Add the root task, responsible for
  97          // preparing everything, creating the
  98          // needed structures (users, roles),
  99          // preloading information to temp table
 100          // and other init tasks
 101          $plan->add_task(new restore_root_task('root_task'));
 102          $controller->get_progress()->progress();
 103  
 104          switch ($controller->get_type()) {
 105              case backup::TYPE_1ACTIVITY:
 106                  self::build_activity_plan($controller, key($controller->get_info()->activities));
 107                  break;
 108              case backup::TYPE_1SECTION:
 109                  self::build_section_plan($controller, key($controller->get_info()->sections));
 110                  break;
 111              case backup::TYPE_1COURSE:
 112                  self::build_course_plan($controller, $controller->get_courseid());
 113                  break;
 114          }
 115  
 116          // Add the final task, responsible for closing
 117          // all the pending bits (remapings, inter-links
 118          // conversion...)
 119          // and perform other various final actions.
 120          $plan->add_task(new restore_final_task('final_task'));
 121          $controller->get_progress()->progress();
 122      }
 123  
 124  
 125  // Protected API starts here
 126  
 127      /**
 128       * Restore one 1-activity backup
 129       */
 130      static protected function build_activity_plan($controller, $activityid) {
 131  
 132          $plan = $controller->get_plan();
 133          $info = $controller->get_info();
 134          $infoactivity = $info->activities[$activityid];
 135  
 136          // Add the activity task, responsible for restoring
 137          // all the module related information. So it conditionally
 138          // as far as the module can be missing on restore
 139          if ($task = restore_factory::get_restore_activity_task($infoactivity)) { // can be missing
 140              $plan->add_task($task);
 141              $controller->get_progress()->progress();
 142  
 143              // For the given activity path, add as many block tasks as necessary
 144              // TODO: Add blocks, we need to introspect xml here
 145              $blocks = backup_general_helper::get_blocks_from_path($task->get_taskbasepath());
 146              foreach ($blocks as $basepath => $name) {
 147                  if ($task = restore_factory::get_restore_block_task($name, $basepath)) {
 148                      $plan->add_task($task);
 149                      $controller->get_progress()->progress();
 150                  } else {
 151                      // TODO: Debug information about block not supported
 152                  }
 153              }
 154          } else { // Activity is missing in target site, inform plan about that
 155              $plan->set_missing_modules();
 156          }
 157  
 158      }
 159  
 160      /**
 161       * Restore one 1-section backup
 162       */
 163      static protected function build_section_plan($controller, $sectionid) {
 164  
 165          $plan = $controller->get_plan();
 166          $info = $controller->get_info();
 167          $infosection = $info->sections[$sectionid];
 168  
 169          // Add the section task, responsible for restoring
 170          // all the section related information
 171          $plan->add_task(restore_factory::get_restore_section_task($infosection));
 172          $controller->get_progress()->progress();
 173          // For the given section, add as many activity tasks as necessary
 174          foreach ($info->activities as $activityid => $activity) {
 175              if ($activity->sectionid != $infosection->sectionid) {
 176                  continue;
 177              }
 178              if (plugin_supports('mod', $activity->modulename, FEATURE_BACKUP_MOODLE2)) { // Check we support the format
 179                  self::build_activity_plan($controller, $activityid);
 180              } else {
 181                  // TODO: Debug information about module not supported
 182              }
 183          }
 184      }
 185  
 186      /**
 187       * Restore one 1-course backup
 188       */
 189      static protected function build_course_plan($controller, $courseid) {
 190  
 191          $plan = $controller->get_plan();
 192          $info = $controller->get_info();
 193  
 194          // Add the course task, responsible for restoring
 195          // all the course related information
 196          $task = restore_factory::get_restore_course_task($info->course, $courseid);
 197          $plan->add_task($task);
 198          $controller->get_progress()->progress();
 199  
 200          // For the given course path, add as many block tasks as necessary
 201          // TODO: Add blocks, we need to introspect xml here
 202          $blocks = backup_general_helper::get_blocks_from_path($task->get_taskbasepath());
 203          foreach ($blocks as $basepath => $name) {
 204              if ($task = restore_factory::get_restore_block_task($name, $basepath)) {
 205                  $plan->add_task($task);
 206                  $controller->get_progress()->progress();
 207              } else {
 208                  // TODO: Debug information about block not supported
 209              }
 210          }
 211  
 212          // For the given course, add as many section tasks as necessary
 213          foreach ($info->sections as $sectionid => $section) {
 214              self::build_section_plan($controller, $sectionid);
 215          }
 216      }
 217  }


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