| 1 | 
           efrain | 
           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_data
  | 
        
        
            | 
            | 
           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/data/backup/moodle2/restore_data_stepslib.php'); // Because it exists (must)
  | 
        
        
            | 
            | 
           28 | 
              | 
        
        
            | 
            | 
           29 | 
           /**
  | 
        
        
            | 
            | 
           30 | 
            * data restore task that provides all the settings and steps to perform one
  | 
        
        
            | 
            | 
           31 | 
            * complete restore of the activity
  | 
        
        
            | 
            | 
           32 | 
            */
  | 
        
        
            | 
            | 
           33 | 
           class restore_data_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 | 
                   // Data only has one structure step
  | 
        
        
            | 
            | 
           47 | 
                   $this->add_step(new restore_data_activity_structure_step('data_structure', 'data.xml'));
  | 
        
        
            | 
            | 
           48 | 
               }
  | 
        
        
            | 
            | 
           49 | 
              | 
        
        
            | 
            | 
           50 | 
               /**
  | 
        
        
            | 
            | 
           51 | 
                * Define the contents in the activity that must be
  | 
        
        
            | 
            | 
           52 | 
                * processed by the link decoder
  | 
        
        
            | 
            | 
           53 | 
                */
  | 
        
        
            | 
            | 
           54 | 
               public static function define_decode_contents() {
  | 
        
        
            | 
            | 
           55 | 
                   $contents = array();
  | 
        
        
            | 
            | 
           56 | 
              | 
        
        
            | 
            | 
           57 | 
                   $contents[] = new restore_decode_content('data', array(
  | 
        
        
            | 
            | 
           58 | 
                                         'intro', 'singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter',
  | 
        
        
            | 
            | 
           59 | 
                                         'addtemplate', 'rsstemplate', 'rsstitletemplate', 'asearchtemplate'), 'data');
  | 
        
        
            | 
            | 
           60 | 
                   $contents[] = new restore_decode_content('data_fields', array(
  | 
        
        
            | 
            | 
           61 | 
                                         'description', 'param1', 'param2', 'param3',
  | 
        
        
            | 
            | 
           62 | 
                                         'param4', 'param5', 'param6', 'param7',
  | 
        
        
            | 
            | 
           63 | 
                                         'param8', 'param9', 'param10'), 'data_field');
  | 
        
        
            | 
            | 
           64 | 
                   $contents[] = new restore_decode_content('data_content', array(
  | 
        
        
            | 
            | 
           65 | 
                                         'content', 'content1', 'content2', 'content3', 'content4'));
  | 
        
        
            | 
            | 
           66 | 
              | 
        
        
            | 
            | 
           67 | 
                   return $contents;
  | 
        
        
            | 
            | 
           68 | 
               }
  | 
        
        
            | 
            | 
           69 | 
              | 
        
        
            | 
            | 
           70 | 
               /**
  | 
        
        
            | 
            | 
           71 | 
                * Define the decoding rules for links belonging
  | 
        
        
            | 
            | 
           72 | 
                * to the activity to be executed by the link decoder
  | 
        
        
            | 
            | 
           73 | 
                */
  | 
        
        
            | 
            | 
           74 | 
               public static function define_decode_rules() {
  | 
        
        
           | 1441 | 
           ariadna | 
           75 | 
                   $rules = [];
  | 
        
        
           | 1 | 
           efrain | 
           76 | 
              | 
        
        
            | 
            | 
           77 | 
                   $rules[] = new restore_decode_rule('DATAVIEWBYID', '/mod/data/view.php?id=$1', 'course_module');
  | 
        
        
           | 1441 | 
           ariadna | 
           78 | 
                   $rules[] = new restore_decode_rule('DATAVIEWBYIDURLENCODED', '/mod/data/view.php?id=$1', 'course_module', true);
  | 
        
        
           | 1 | 
           efrain | 
           79 | 
                   $rules[] = new restore_decode_rule('DATAVIEWBYD', '/mod/data/view.php?d=$1', 'data');
  | 
        
        
           | 1441 | 
           ariadna | 
           80 | 
                   $rules[] = new restore_decode_rule('DATAVIEWBYDURLENCODED', '/mod/data/view.php?d=$1', 'data', true);
  | 
        
        
           | 1 | 
           efrain | 
           81 | 
                   $rules[] = new restore_decode_rule('DATAINDEX', '/mod/data/index.php?id=$1', 'course');
  | 
        
        
           | 1441 | 
           ariadna | 
           82 | 
                   $rules[] = new restore_decode_rule('DATAINDEXURLENCODED', '/mod/data/index.php?id=$1', 'course', true);
  | 
        
        
            | 
            | 
           83 | 
                   $rules[] = new restore_decode_rule('DATAVIEWRECORD', '/mod/data/view.php?d=$1&rid=$2', ['data', 'data_record']);
  | 
        
        
            | 
            | 
           84 | 
                   $rules[] = new restore_decode_rule(
  | 
        
        
            | 
            | 
           85 | 
                       'DATAVIEWRECORDURLENCODED',
  | 
        
        
            | 
            | 
           86 | 
                       '/mod/data/view.php?d=$1&rid=$2',
  | 
        
        
            | 
            | 
           87 | 
                       ['data', 'data_record'],
  | 
        
        
            | 
            | 
           88 | 
                       true
  | 
        
        
            | 
            | 
           89 | 
                   );
  | 
        
        
            | 
            | 
           90 | 
                   $rules[] = new restore_decode_rule('DATAEDITBYID', '/mod/data/edit.php?id=$1', 'course_module');
  | 
        
        
            | 
            | 
           91 | 
                   $rules[] = new restore_decode_rule('DATAEDITBYIDURLENCODED', '/mod/data/edit.php?id=$1', 'course_module', true);
  | 
        
        
            | 
            | 
           92 | 
                   $rules[] = new restore_decode_rule('DATAEDITBYD', '/mod/data/edit.php?d=$1', 'data');
  | 
        
        
            | 
            | 
           93 | 
                   $rules[] = new restore_decode_rule('DATAEDITBYDURLENCODED', '/mod/data/edit.php?d=$1', 'data', true);
  | 
        
        
           | 1 | 
           efrain | 
           94 | 
              | 
        
        
            | 
            | 
           95 | 
                   return $rules;
  | 
        
        
            | 
            | 
           96 | 
               }
  | 
        
        
            | 
            | 
           97 | 
              | 
        
        
            | 
            | 
           98 | 
               /**
  | 
        
        
            | 
            | 
           99 | 
                * Define the restore log rules that will be applied
  | 
        
        
            | 
            | 
           100 | 
                * by the {@link restore_logs_processor} when restoring
  | 
        
        
            | 
            | 
           101 | 
                * data logs. It must return one array
  | 
        
        
            | 
            | 
           102 | 
                * of {@link restore_log_rule} objects
  | 
        
        
            | 
            | 
           103 | 
                */
  | 
        
        
            | 
            | 
           104 | 
               public static function define_restore_log_rules() {
  | 
        
        
            | 
            | 
           105 | 
                   $rules = array();
  | 
        
        
            | 
            | 
           106 | 
              | 
        
        
            | 
            | 
           107 | 
                   $rules[] = new restore_log_rule('data', 'add', 'view.php?d={data}&rid={data_record}', '{data}');
  | 
        
        
            | 
            | 
           108 | 
                   $rules[] = new restore_log_rule('data', 'update', 'view.php?d={data}&rid={data_record}', '{data}');
  | 
        
        
            | 
            | 
           109 | 
                   $rules[] = new restore_log_rule('data', 'view', 'view.php?id={course_module}', '{data}');
  | 
        
        
            | 
            | 
           110 | 
                   $rules[] = new restore_log_rule('data', 'record delete', 'view.php?id={course_module}', '{data}');
  | 
        
        
            | 
            | 
           111 | 
                   $rules[] = new restore_log_rule('data', 'fields add', 'field.php?d={data}&mode=display&fid={data_field}', '{data_field}');
  | 
        
        
            | 
            | 
           112 | 
                   $rules[] = new restore_log_rule('data', 'fields update', 'field.php?d={data}&mode=display&fid={data_field}', '{data_field}');
  | 
        
        
            | 
            | 
           113 | 
                   $rules[] = new restore_log_rule('data', 'fields delete', 'field.php?d={data}', '[name]');
  | 
        
        
            | 
            | 
           114 | 
              | 
        
        
            | 
            | 
           115 | 
                   return $rules;
  | 
        
        
            | 
            | 
           116 | 
               }
  | 
        
        
            | 
            | 
           117 | 
              | 
        
        
            | 
            | 
           118 | 
               /**
  | 
        
        
            | 
            | 
           119 | 
                * Define the restore log rules that will be applied
  | 
        
        
            | 
            | 
           120 | 
                * by the {@link restore_logs_processor} when restoring
  | 
        
        
            | 
            | 
           121 | 
                * course logs. It must return one array
  | 
        
        
            | 
            | 
           122 | 
                * of {@link restore_log_rule} objects
  | 
        
        
            | 
            | 
           123 | 
                *
  | 
        
        
            | 
            | 
           124 | 
                * Note this rules are applied when restoring course logs
  | 
        
        
            | 
            | 
           125 | 
                * by the restore final task, but are defined here at
  | 
        
        
            | 
            | 
           126 | 
                * activity level. All them are rules not linked to any module instance (cmid = 0)
  | 
        
        
            | 
            | 
           127 | 
                */
  | 
        
        
            | 
            | 
           128 | 
               public static function define_restore_log_rules_for_course() {
  | 
        
        
            | 
            | 
           129 | 
                   $rules = array();
  | 
        
        
            | 
            | 
           130 | 
              | 
        
        
            | 
            | 
           131 | 
                   $rules[] = new restore_log_rule('data', 'view all', 'index.php?id={course}', null);
  | 
        
        
            | 
            | 
           132 | 
              | 
        
        
            | 
            | 
           133 | 
                   return $rules;
  | 
        
        
            | 
            | 
           134 | 
               }
  | 
        
        
            | 
            | 
           135 | 
              | 
        
        
            | 
            | 
           136 | 
               /**
  | 
        
        
            | 
            | 
           137 | 
                * Given a commment area, return the itemname that contains the itemid mappings.
  | 
        
        
            | 
            | 
           138 | 
                *
  | 
        
        
            | 
            | 
           139 | 
                * @param string $commentarea Comment area name e.g. database_entry.
  | 
        
        
            | 
            | 
           140 | 
                * @return string name of the mapping used to determine the itemid.
  | 
        
        
            | 
            | 
           141 | 
                */
  | 
        
        
            | 
            | 
           142 | 
               public function get_comment_mapping_itemname($commentarea) {
  | 
        
        
            | 
            | 
           143 | 
                   if ($commentarea == 'database_entry') {
  | 
        
        
            | 
            | 
           144 | 
                       $itemname = 'data_record';
  | 
        
        
            | 
            | 
           145 | 
                   } else {
  | 
        
        
            | 
            | 
           146 | 
                       $itemname = parent::get_comment_mapping_itemname($commentarea);
  | 
        
        
            | 
            | 
           147 | 
                   }
  | 
        
        
            | 
            | 
           148 | 
                   return $itemname;
  | 
        
        
            | 
            | 
           149 | 
               }
  | 
        
        
            | 
            | 
           150 | 
           }
  |