2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 * @copyright 2016 Marina Glancy
20 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 * Specialised restore task for the tags block
25 * (using execute_after_tasks for recoding of tag collection id)
28 * @copyright 2016 Marina Glancy
29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 class restore_tags_block_task extends restore_block_task {
33 protected function define_my_settings() {
36 protected function define_my_steps() {
39 public function get_fileareas() {
40 return array(); // No associated fileareas.
43 public function get_configdata_encoded_attributes() {
44 return array(); // No special handling of configdata.
48 * This function, executed after all the tasks in the plan
49 * have been executed, will remove tag collection reference in case block was restored into another site.
50 * Also get mapping of contextid.
52 public function after_restore() {
56 $blockid = $this->get_blockid();
58 // Extract block configdata and remove tag collection reference if this is another site. Also map contextid.
59 if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) {
60 $config = unserialize(base64_decode($configdata));
62 if (!empty($config->tagcoll) && $config->tagcoll > 1 && !$this->is_samesite()) {
66 if (!empty($config->ctx)) {
67 if ($ctxmap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'context', $config->ctx)) {
68 $config->ctx = $ctxmap->newitemid;
75 $configdata = base64_encode(serialize($config));
76 $DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid));
81 static public function define_decode_contents() {
85 static public function define_decode_rules() {