From 32fc1a69a518d34272ea3a6f6dbd6a45d2cb9be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Thu, 4 Feb 2016 23:44:15 +0100 Subject: [PATCH] MDL-50310 glossary: Fix restore of random glossary entry block When restoring the random glossary entry block, we need to check that the associated glossary has also been included in the backup and is being restored. If not, we must invalidate the block configuration. Before this patch, the block configuration was not invalidated. Additionally, as a result of MDL-20131, the block configuration also contains the course id of the associated glossary (which by the way does not seem to be a wise choice, but I may be missing something). So we need to remap this course id as well to avoid mismatch. --- .../moodle2/restore_glossary_random_block_task.class.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 index 017e407897e..cfc5bc14f97 100644 --- 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 @@ -62,9 +62,16 @@ class restore_glossary_random_block_task extends restore_block_task { 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; + $mappedglossary = $DB->get_record('glossary', array('id' => $glossarymap->newitemid), + 'id,course,globalglossary', MUST_EXIST); + $config->glossary = $mappedglossary->id; + $config->courseid = $mappedglossary->course; + $config->globalglossary = $mappedglossary->globalglossary; $configdata = base64_encode(serialize($config)); $DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid)); + } else { + // The block refers to a glossary not present in the backup file. + $DB->set_field('block_instances', 'configdata', '', array('id' => $blockid)); } } }