|
| 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 | + * Backup 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 | +class restore_completion_progress_block_task extends restore_block_task { |
| 25 | + |
| 26 | + /** |
| 27 | + * Translates the backed up configuration data for the target course modules. |
| 28 | + * |
| 29 | + * @global type $DB |
| 30 | + */ |
| 31 | + public function after_restore() { |
| 32 | + global $DB; |
| 33 | + |
| 34 | + // Get the blockid. |
| 35 | + $id = $this->get_blockid(); |
| 36 | + |
| 37 | + // Get restored course id. |
| 38 | + $courseid = $this->get_courseid(); |
| 39 | + |
| 40 | + if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $id))) { |
| 41 | + $config = (array)unserialize(base64_decode($configdata)); |
| 42 | + $newactivities = array(); |
| 43 | + |
| 44 | + // Translate the old config information to the target course values. |
| 45 | + foreach ($config['selectactivities'] as $index => $value) { |
| 46 | + $matches = array(); |
| 47 | + preg_match('/(.+)-(\d+)/', $value, $matches); |
| 48 | + if (!empty($matches)) { |
| 49 | + $module = $matches[1]; |
| 50 | + $instance = $matches[2]; |
| 51 | + |
| 52 | + // Find the mapped instance ID. |
| 53 | + if ($newinstance = restore_dbops::get_backup_ids_record($this->get_restoreid(), $module, $instance)) { |
| 54 | + $newinstanceid = $newinstance->newitemid; |
| 55 | + $newactivities[] = "$module-$newinstanceid"; |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + // Save everything back to DB. |
| 61 | + $config['selectactivities'] = $newactivities; |
| 62 | + $configdata = base64_encode(serialize((object)$config)); |
| 63 | + $DB->set_field('block_instances', 'configdata', $configdata, array('id' => $id)); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * There are no unusual settings for this restore |
| 69 | + */ |
| 70 | + protected function define_my_settings() { |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * There are no unusual steps for this restore |
| 75 | + */ |
| 76 | + protected function define_my_steps() { |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * There are no files associated with this block |
| 81 | + * |
| 82 | + * @return array An empty array |
| 83 | + */ |
| 84 | + public function get_fileareas() { |
| 85 | + return array(); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * There are no specially encoded attributes |
| 90 | + * |
| 91 | + * @return array An empty array |
| 92 | + */ |
| 93 | + public function get_configdata_encoded_attributes() { |
| 94 | + return array(); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * There is no coded content in the backup |
| 99 | + * |
| 100 | + * @return array An empty array |
| 101 | + */ |
| 102 | + static public function define_decode_contents() { |
| 103 | + return array(); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * There are no coded links in the backup |
| 108 | + * |
| 109 | + * @return array An empty array |
| 110 | + */ |
| 111 | + static public function define_decode_rules() { |
| 112 | + return array(); |
| 113 | + } |
| 114 | +} |
0 commit comments