1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Define all the backup steps that will be used by the backup_reengagement_activity_task
|
|
|
19 |
*
|
|
|
20 |
* @package mod_reengagement
|
|
|
21 |
* @author Peter Bulmer <peter.bulmer@catlayst.net.nz>
|
|
|
22 |
* @copyright 2016 Catalyst IT {@link http://www.catalyst.net.nz}
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
defined('MOODLE_INTERNAL') || die();
|
|
|
27 |
|
|
|
28 |
require_once($CFG->dirroot . '/mod/reengagement/backup/moodle2/restore_reengagement_stepslib.php');
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Task that provides all the settings and steps to perform one complete restore of the activity.
|
|
|
32 |
*
|
|
|
33 |
* @package mod_reengagement
|
|
|
34 |
* @author Peter Bulmer <peter.bulmer@catlayst.net.nz>
|
|
|
35 |
* @copyright 2016 Catalyst IT {@link http://www.catalyst.net.nz}
|
|
|
36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
37 |
*/
|
|
|
38 |
class restore_reengagement_activity_task extends restore_activity_task {
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Define (add) particular settings this activity can have
|
|
|
42 |
*/
|
|
|
43 |
protected function define_my_settings() {
|
|
|
44 |
// No particular settings for this activity.
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* Define (add) particular steps this activity can have.
|
|
|
49 |
*/
|
|
|
50 |
protected function define_my_steps() {
|
|
|
51 |
// The reengagement only has one structure step.
|
|
|
52 |
$this->add_step(new restore_reengagement_activity_structure_step('reengagement_structure', 'reengagement.xml'));
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
* Define the contents in the activity that must be
|
|
|
57 |
* processed by the link decoder
|
|
|
58 |
*/
|
|
|
59 |
public static function define_decode_contents() {
|
|
|
60 |
$contents = array();
|
|
|
61 |
|
|
|
62 |
$contents[] = new restore_decode_content('reengagement', 'emailcontent');
|
|
|
63 |
$contents[] = new restore_decode_content('reengagement', 'emailcontentmanager');
|
|
|
64 |
$contents[] = new restore_decode_content('reengagement', 'emailcontentthirdparty');
|
|
|
65 |
|
|
|
66 |
return $contents;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Define the decoding rules for links belonging
|
|
|
71 |
* to the activity to be executed by the link decoder
|
|
|
72 |
*/
|
|
|
73 |
public static function define_decode_rules() {
|
|
|
74 |
$rules = array();
|
|
|
75 |
|
|
|
76 |
$rules[] = new restore_decode_rule('STANDDOWNVIEWBYID', '/mod/reengagement/view.php?id=$1', 'course_module');
|
|
|
77 |
$rules[] = new restore_decode_rule('STANDDOWNINDEX', '/mod/reengagement/index.php?id=$1', 'course');
|
|
|
78 |
|
|
|
79 |
return $rules;
|
|
|
80 |
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* Define the restore log rules that will be applied
|
|
|
85 |
* by the {@see restore_logs_processor} when restoring
|
|
|
86 |
* reengagement logs. It must return one array
|
|
|
87 |
* of {@see restore_log_rule} objects
|
|
|
88 |
*/
|
|
|
89 |
public static function define_restore_log_rules() {
|
|
|
90 |
$rules = array();
|
|
|
91 |
|
|
|
92 |
return $rules;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* Define the restore log rules that will be applied
|
|
|
97 |
* by the {@see restore_logs_processor} when restoring
|
|
|
98 |
* course logs. It must return one array
|
|
|
99 |
* of {@see 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 |
public static function define_restore_log_rules_for_course() {
|
|
|
106 |
$rules = array();
|
|
|
107 |
|
|
|
108 |
// Fix old wrong uses (missing extension).
|
|
|
109 |
$rules[] = new restore_log_rule('reengagement', 'view all', 'index?id={course}', null,
|
|
|
110 |
null, null, 'index.php?id={course}');
|
|
|
111 |
$rules[] = new restore_log_rule('reengagement', 'view all', 'index.php?id={course}', null);
|
|
|
112 |
|
|
|
113 |
return $rules;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
/**
|
|
|
117 |
* The reengagement module has a suppresstarget which is a cmid, we need to update that accordingly, however,
|
|
|
118 |
* in certain cases, that course may be restored to our target course
|
|
|
119 |
* After the reengagement itself is restored, so we do the cmid mapping fix after the restore has finished.
|
|
|
120 |
*/
|
|
|
121 |
public function after_restore() {
|
|
|
122 |
global $DB;
|
|
|
123 |
$id = $this->get_activityid();
|
|
|
124 |
$course = $this->get_courseid();
|
|
|
125 |
$reengagement = $DB->get_record('reengagement', array('id' => $id));
|
|
|
126 |
if (empty($reengagement)) {
|
|
|
127 |
// Unexpected, but nothing needs doing.
|
|
|
128 |
return;
|
|
|
129 |
}
|
|
|
130 |
if (empty($reengagement->suppresstarget)) {
|
|
|
131 |
// Restored activity didn't have a targeted activity. Nothing needs mapping.
|
|
|
132 |
return;
|
|
|
133 |
}
|
|
|
134 |
// Find the mapping between old course_module id and new course_module id.
|
|
|
135 |
$map = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'course_module', $reengagement->suppresstarget);
|
|
|
136 |
if ($map) {
|
|
|
137 |
$newid = $map->newitemid;
|
|
|
138 |
// Update cmid if the mapping exists.
|
|
|
139 |
$reengagement->suppresstarget = $newid;
|
|
|
140 |
$DB->update_record('reengagement', $reengagement);
|
|
|
141 |
} else {
|
|
|
142 |
// If there is no new cm, then the course we are targeting is not included in the backup
|
|
|
143 |
// put out a log warning and set a target of 0. not much else we can do here
|
|
|
144 |
// nb: according to wiki doc these logs go nowhere!
|
|
|
145 |
$this->get_logger()->process("Failed to restore the suppressed email target in reengagement: '$id'. " .
|
|
|
146 |
"Backup and restore of this item will not work correctly unless you include the required activity ".
|
|
|
147 |
"in the restore to course:$course.", backup::LOG_ERROR);
|
|
|
148 |
$reengagement->suppresstarget = 0;
|
|
|
149 |
$DB->update_record('reengagement', $reengagement);
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
}
|