From f79e0753d46a75e7dce26c81f86b2c2b3b4c6b47 Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Mon, 1 Nov 2010 15:55:12 +0000 Subject: [PATCH] MDL-23478 backup - Implement glossary_random & quiz_results after_restore() methods --- ...store_glossary_random_block_task.class.php | 81 +++++++++++++++++++ .../restore_quiz_results_block_task.class.php | 81 +++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 blocks/glossary_random/backup/moodle2/restore_glossary_random_block_task.class.php create mode 100644 blocks/quiz_results/backup/moodle2/restore_quiz_results_block_task.class.php diff --git a/blocks/glossary_random/backup/moodle2/restore_glossary_random_block_task.class.php b/blocks/glossary_random/backup/moodle2/restore_glossary_random_block_task.class.php new file mode 100644 index 0000000000000..6b4b91802b00a --- /dev/null +++ b/blocks/glossary_random/backup/moodle2/restore_glossary_random_block_task.class.php @@ -0,0 +1,81 @@ +. + +/** + * @package moodlecore + * @subpackage backup-moodle2 + * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Specialised restore task for the glossary_random block + * (using execute_after_tasks for recoding of glossaryid) + * + * TODO: Finish phpdocs + */ +class restore_glossary_random_block_task extends restore_block_task { + + protected function define_my_settings() { + } + + protected function define_my_steps() { + } + + public function get_fileareas() { + return array(); // No associated fileareas + } + + public function get_configdata_encoded_attributes() { + return array(); // No special handling of configdata + } + + /** + * This function, executed after all the tasks in the plan + * have been executed, will perform the recode of the + * target glossary for the block. This must be done here + * and not in normal execution steps because the glossary + * may be restored after the block. + */ + public function after_restore() { + global $DB; + + // Get the blockid + $blockid = $this->get_blockid(); + + // Extract block configdata and update it to point to the new glossary + if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) { + $config = unserialize(base64_decode($configdata)); + if (!empty($config->glossary)) { + // Get glossary mapping and replace it in config + if ($glossarymap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary', $config->glossary)) { + $config->glossary = $glossarymap->newitemid; + $configdata = base64_encode(serialize($config)); + $DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid)); + } + } + } + } + + static public function define_decode_contents() { + return array(); + } + + static public function define_decode_rules() { + return array(); + } +} diff --git a/blocks/quiz_results/backup/moodle2/restore_quiz_results_block_task.class.php b/blocks/quiz_results/backup/moodle2/restore_quiz_results_block_task.class.php new file mode 100644 index 0000000000000..6e6e73062abf3 --- /dev/null +++ b/blocks/quiz_results/backup/moodle2/restore_quiz_results_block_task.class.php @@ -0,0 +1,81 @@ +. + +/** + * @package moodlecore + * @subpackage backup-moodle2 + * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Specialised restore task for the quiz_results block + * (using execute_after_tasks for recoding of target quiz) + * + * TODO: Finish phpdocs + */ +class restore_quiz_results_block_task extends restore_block_task { + + protected function define_my_settings() { + } + + protected function define_my_steps() { + } + + public function get_fileareas() { + return array(); // No associated fileareas + } + + public function get_configdata_encoded_attributes() { + return array(); // No special handling of configdata + } + + /** + * This function, executed after all the tasks in the plan + * have been executed, will perform the recode of the + * target quiz for the block. This must be done here + * and not in normal execution steps because the quiz + * can be restored after the block. + */ + public function after_restore() { + global $DB; + + // Get the blockid + $blockid = $this->get_blockid(); + + // Extract block configdata and update it to point to the new quiz + if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) { + $config = unserialize(base64_decode($configdata)); + if (!empty($config->quizid)) { + // Get quiz mapping and replace it in config + if ($quizmap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'quiz', $config->quizid)) { + $config->quizid = $quizmap->newitemid; + $configdata = base64_encode(serialize($config)); + $DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid)); + } + } + } + } + + static public function define_decode_contents() { + return array(); + } + + static public function define_decode_rules() { + return array(); + } +}