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 * @package block_tags 19 * @copyright 2016 Marina Glancy 20 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 21 */ 22 23 /** 24 * Specialised restore task for the tags block 25 * (using execute_after_tasks for recoding of tag collection id) 26 * 27 * @package block_tags 28 * @copyright 2016 Marina Glancy 29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 30 */ 31 class restore_tags_block_task extends restore_block_task { 32 33 protected function define_my_settings() { 34 } 35 36 protected function define_my_steps() { 37 } 38 39 public function get_fileareas() { 40 return array(); // No associated fileareas. 41 } 42 43 public function get_configdata_encoded_attributes() { 44 return array(); // No special handling of configdata. 45 } 46 47 /** 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. 51 */ 52 public function after_restore() { 53 global $DB; 54 55 // Get the blockid. 56 $blockid = $this->get_blockid(); 57 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 = $this->decode_configdata($configdata); 61 $changed = false; 62 if (!empty($config->tagcoll) && $config->tagcoll > 1 && !$this->is_samesite()) { 63 $config->tagcoll = 0; 64 $changed = true; 65 } 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; 69 } else { 70 $config->ctx = 0; 71 } 72 $changed = true; 73 } 74 if ($changed) { 75 $configdata = base64_encode(serialize($config)); 76 $DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid)); 77 } 78 } 79 } 80 81 static public function define_decode_contents() { 82 return array(); 83 } 84 85 static public function define_decode_rules() { 86 return array(); 87 } 88 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body