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 |
* Restore task for the Completion Progress block
|
|
|
19 |
*
|
|
|
20 |
* @package block_completion_progress
|
|
|
21 |
* @copyright 2016 Michael de Raadt
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Restore task for the Completion Progress block
|
|
|
27 |
*
|
|
|
28 |
* @package block_completion_progress
|
|
|
29 |
* @copyright 2016 Michael de Raadt
|
|
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
31 |
*/
|
|
|
32 |
class restore_completion_progress_block_task extends restore_block_task {
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Translates the backed up configuration data for the target course modules.
|
|
|
36 |
*/
|
|
|
37 |
public function after_restore() {
|
|
|
38 |
global $DB;
|
|
|
39 |
|
|
|
40 |
// Get the blockid.
|
|
|
41 |
$id = $this->get_blockid();
|
|
|
42 |
|
|
|
43 |
// Get restored course id.
|
|
|
44 |
$courseid = $this->get_courseid();
|
|
|
45 |
|
|
|
46 |
if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $id))) {
|
|
|
47 |
$config = (array)unserialize(base64_decode($configdata));
|
|
|
48 |
$newactivities = array();
|
|
|
49 |
$newgroup = '0';
|
|
|
50 |
|
|
|
51 |
if (isset($config['selectactivities'])) {
|
|
|
52 |
// Translate the old config information to the target course values.
|
|
|
53 |
foreach ($config['selectactivities'] as $value) {
|
|
|
54 |
$matches = array();
|
|
|
55 |
preg_match('/(.+)-(\d+)/', $value, $matches);
|
|
|
56 |
if (!empty($matches)) {
|
|
|
57 |
$module = $matches[1];
|
|
|
58 |
$instance = $matches[2];
|
|
|
59 |
|
|
|
60 |
// Find the mapped instance ID.
|
|
|
61 |
if ($newinstance = restore_dbops::get_backup_ids_record($this->get_restoreid(), $module, $instance)) {
|
|
|
62 |
$newinstanceid = $newinstance->newitemid;
|
|
|
63 |
$newactivities[] = "$module-$newinstanceid";
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
if (!empty($config['group'])) {
|
|
|
69 |
// Try and adapt the old group/grouping to the target course.
|
|
|
70 |
if (preg_match('/^(?P<type>group|grouping)-(?P<id>\d+)$/', $config['group'], $matches)) {
|
|
|
71 |
$rec = restore_dbops::get_backup_ids_record($this->get_restoreid(), $matches['type'], $matches['id']);
|
|
|
72 |
if (!$rec || !$rec->newitemid) {
|
|
|
73 |
if ($DB->record_exists($matches['type'] . 's',
|
|
|
74 |
['id' => $matches['id'], 'courseid' => $courseid])) {
|
|
|
75 |
$newgroup = $config['group'];
|
|
|
76 |
}
|
|
|
77 |
} else {
|
|
|
78 |
$newgroup = $matches['type'] . '-' . $rec->newitemid;
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
if ($newgroup === '0') {
|
|
|
82 |
$this->get_logger()->process('Restored completion_progress block has a ' .
|
|
|
83 |
'group/grouping setting that was not restored', backup::LOG_WARNING);
|
|
|
84 |
}
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
// Save everything back to DB.
|
|
|
88 |
$config['selectactivities'] = $newactivities;
|
|
|
89 |
$config['group'] = $newgroup;
|
|
|
90 |
$configdata = base64_encode(serialize((object)$config));
|
|
|
91 |
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $id));
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* There are no unusual settings for this restore
|
|
|
97 |
*/
|
|
|
98 |
protected function define_my_settings() {
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
/**
|
|
|
102 |
* There are no unusual steps for this restore
|
|
|
103 |
*/
|
|
|
104 |
protected function define_my_steps() {
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
/**
|
|
|
108 |
* There are no files associated with this block
|
|
|
109 |
*
|
|
|
110 |
* @return array An empty array
|
|
|
111 |
*/
|
|
|
112 |
public function get_fileareas() {
|
|
|
113 |
return array();
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
/**
|
|
|
117 |
* There are no specially encoded attributes
|
|
|
118 |
*
|
|
|
119 |
* @return array An empty array
|
|
|
120 |
*/
|
|
|
121 |
public function get_configdata_encoded_attributes() {
|
|
|
122 |
return array();
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
/**
|
|
|
126 |
* There is no coded content in the backup
|
|
|
127 |
*
|
|
|
128 |
* @return array An empty array
|
|
|
129 |
*/
|
|
|
130 |
public static function define_decode_contents() {
|
|
|
131 |
return array();
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
/**
|
|
|
135 |
* There are no coded links in the backup
|
|
|
136 |
*
|
|
|
137 |
* @return array An empty array
|
|
|
138 |
*/
|
|
|
139 |
public static function define_decode_rules() {
|
|
|
140 |
return array();
|
|
|
141 |
}
|
|
|
142 |
}
|