Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   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_assignment
  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  defined('MOODLE_INTERNAL') || die();
  26  
  27  require_once($CFG->dirroot . '/mod/assignment/backup/moodle2/restore_assignment_stepslib.php'); // Because it exists (must)
  28  
  29  /**
  30   * assignment restore task that provides all the settings and steps to perform one
  31   * complete restore of the activity
  32   */
  33  class restore_assignment_activity_task extends restore_activity_task {
  34  
  35      /**
  36       * Define (add) particular settings this activity can have
  37       */
  38      protected function define_my_settings() {
  39          // No particular settings for this activity
  40      }
  41  
  42      /**
  43       * Define (add) particular steps this activity can have
  44       */
  45      protected function define_my_steps() {
  46          // Choice only has one structure step
  47          $this->add_step(new restore_assignment_activity_structure_step('assignment_structure', 'assignment.xml'));
  48      }
  49  
  50      /**
  51       * Define the contents in the activity that must be
  52       * processed by the link decoder
  53       */
  54      static public function define_decode_contents() {
  55          $contents = array();
  56  
  57          $contents[] = new restore_decode_content('assignment', array('intro'), 'assignment');
  58  
  59          return $contents;
  60      }
  61  
  62      /**
  63       * Define the decoding rules for links belonging
  64       * to the activity to be executed by the link decoder
  65       */
  66      static public function define_decode_rules() {
  67          $rules = array();
  68  
  69          $rules[] = new restore_decode_rule('ASSIGNMENTVIEWBYID', '/mod/assignment/view.php?id=$1', 'course_module');
  70          $rules[] = new restore_decode_rule('ASSIGNMENTINDEX', '/mod/assignment/index.php?id=$1', 'course');
  71  
  72          return $rules;
  73  
  74      }
  75  
  76      /**
  77       * Define the restore log rules that will be applied
  78       * by the {@link restore_logs_processor} when restoring
  79       * assignment logs. It must return one array
  80       * of {@link restore_log_rule} objects
  81       */
  82      static public function define_restore_log_rules() {
  83          $rules = array();
  84  
  85          $rules[] = new restore_log_rule('assignment', 'add', 'view.php?id={course_module}', '{assignment}');
  86          $rules[] = new restore_log_rule('assignment', 'update', 'view.php?id={course_module}', '{assignment}');
  87          $rules[] = new restore_log_rule('assignment', 'view', 'view.php?id={course_module}', '{assignment}');
  88          $rules[] = new restore_log_rule('assignment', 'upload', 'view.php?a={assignment}', '{assignment}');
  89          $rules[] = new restore_log_rule('assignment', 'view submission', 'submissions.php.php?id={course_module}', '{assignment}');
  90          $rules[] = new restore_log_rule('assignment', 'update grades', 'submissions.php.php?id={course_module}&user={user}', '{user}');
  91  
  92          return $rules;
  93      }
  94  
  95      /**
  96       * Define the restore log rules that will be applied
  97       * by the {@link restore_logs_processor} when restoring
  98       * course logs. It must return one array
  99       * of {@link restore_log_rule} objects
 100       *
 101       * Note this rules are applied when restoring course logs
 102       * by the restore final task, but are defined here at
 103       * activity level. All them are rules not linked to any module instance (cmid = 0)
 104       */
 105      static public function define_restore_log_rules_for_course() {
 106          $rules = array();
 107  
 108          $rules[] = new restore_log_rule('assignment', 'view all', 'index.php?id={course}', null);
 109  
 110          return $rules;
 111      }
 112  
 113      /**
 114       * Expose the restore mode so we can skip automatic upgrade for MODE_IMPORT (e.g. duplicate).
 115       *
 116       * @return int
 117       */
 118      public function get_mode() {
 119          return $this->plan->get_mode();
 120      }
 121  }