From 415cc103ff55267cc062dbe4bfd26f4b346a4bde Mon Sep 17 00:00:00 2001 From: Stephan Robotta Date: Thu, 5 Dec 2024 13:28:11 +0100 Subject: [PATCH] Fix mapping in backup and restore. --- .../backup_verbalfeedback_stepslib.php | 56 +++++++++++++------ .../restore_verbalfeedback_stepslib.php | 16 +++++- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/backup/moodle2/backup_verbalfeedback_stepslib.php b/backup/moodle2/backup_verbalfeedback_stepslib.php index 95b78f2..6a1a865 100644 --- a/backup/moodle2/backup_verbalfeedback_stepslib.php +++ b/backup/moodle2/backup_verbalfeedback_stepslib.php @@ -144,26 +144,50 @@ protected function define_structure() { $language->set_source_table(tables::LANGUAGE_TABLE, []); $category->set_source_table(tables::INSTANCE_CATEGORY_TABLE, ['instanceid' => backup::VAR_PARENTID], 'id ASC'); - $categoryheader->set_source_table(tables::LOCALIZED_STRING_TABLE, ['foreignkey' => backup::VAR_PARENTID, - 'type' => backup_helper::is_sqlparam(localized_string_type::INSTANCE_CATEGORY_HEADER), ]); + $categoryheader->set_source_table(tables::LOCALIZED_STRING_TABLE, [ + 'foreignkey' => backup::VAR_PARENTID, + 'typeid' => backup_helper::is_sqlparam( + localized_string_type::str2id(localized_string_type::INSTANCE_CATEGORY_HEADER) + ), ]); $criterion->set_source_table(tables::INSTANCE_CRITERION_TABLE, ['categoryid' => backup::VAR_PARENTID], 'id ASC'); - $criteriontext->set_source_table(tables::LOCALIZED_STRING_TABLE, ['foreignkey' => backup::VAR_PARENTID, - 'type' => backup_helper::is_sqlparam(localized_string_type::INSTANCE_CRITERION), ]); + $criteriontext->set_source_table(tables::LOCALIZED_STRING_TABLE, [ + 'foreignkey' => backup::VAR_PARENTID, + 'typeid' => backup_helper::is_sqlparam( + localized_string_type::str2id(localized_string_type::INSTANCE_CRITERION) + ), ]); $subrating->set_source_table(tables::INSTANCE_SUBRATING_TABLE, ['criterionid' => backup::VAR_PARENTID], 'id ASC'); - $subratingtitle->set_source_table(tables::LOCALIZED_STRING_TABLE, ['foreignkey' => backup::VAR_PARENTID, - 'type' => backup_helper::is_sqlparam(localized_string_type::INSTANCE_SUBRATING_TITLE), ]); - $subratingdescription->set_source_table(tables::LOCALIZED_STRING_TABLE, ['foreignkey' => backup::VAR_PARENTID, - 'type' => backup_helper::is_sqlparam(localized_string_type::INSTANCE_SUBRATING_DESCRIPTION), ]); - $subratingverynegative->set_source_table(tables::LOCALIZED_STRING_TABLE, ['foreignkey' => backup::VAR_PARENTID, - 'type' => backup_helper::is_sqlparam(localized_string_type::INSTANCE_SUBRATING_VERY_NEGATIVE), ]); - $subratingnegative->set_source_table(tables::LOCALIZED_STRING_TABLE, ['foreignkey' => backup::VAR_PARENTID, - 'type' => backup_helper::is_sqlparam(localized_string_type::INSTANCE_SUBRATING_NEGATIVE), ]); - $subratingpositive->set_source_table(tables::LOCALIZED_STRING_TABLE, ['foreignkey' => backup::VAR_PARENTID, - 'type' => backup_helper::is_sqlparam(localized_string_type::INSTANCE_SUBRATING_POSITIVE), ]); - $subratingverypositive->set_source_table(tables::LOCALIZED_STRING_TABLE, ['foreignkey' => backup::VAR_PARENTID, - 'type' => backup_helper::is_sqlparam(localized_string_type::INSTANCE_SUBRATING_VERY_POSITIVE), ]); + $subratingtitle->set_source_table(tables::LOCALIZED_STRING_TABLE, [ + 'foreignkey' => backup::VAR_PARENTID, + 'typeid' => backup_helper::is_sqlparam( + localized_string_type::str2id(localized_string_type::INSTANCE_SUBRATING_TITLE) + ), ]); + $subratingdescription->set_source_table(tables::LOCALIZED_STRING_TABLE, [ + 'foreignkey' => backup::VAR_PARENTID, + 'typeid' => backup_helper::is_sqlparam( + localized_string_type::str2id(localized_string_type::INSTANCE_SUBRATING_DESCRIPTION) + ), ]); + $subratingverynegative->set_source_table(tables::LOCALIZED_STRING_TABLE, [ + 'foreignkey' => backup::VAR_PARENTID, + 'typeid' => backup_helper::is_sqlparam( + localized_string_type::str2id(localized_string_type::INSTANCE_SUBRATING_VERY_NEGATIVE) + ), ]); + $subratingnegative->set_source_table(tables::LOCALIZED_STRING_TABLE, [ + 'foreignkey' => backup::VAR_PARENTID, + 'typeid' => backup_helper::is_sqlparam( + localized_string_type::str2id(localized_string_type::INSTANCE_SUBRATING_NEGATIVE) + ), ]); + $subratingpositive->set_source_table(tables::LOCALIZED_STRING_TABLE, [ + 'foreignkey' => backup::VAR_PARENTID, + 'typeid' => backup_helper::is_sqlparam( + localized_string_type::str2id(localized_string_type::INSTANCE_SUBRATING_POSITIVE) + ), ]); + $subratingverypositive->set_source_table(tables::LOCALIZED_STRING_TABLE, [ + 'foreignkey' => backup::VAR_PARENTID, + 'typeid' => backup_helper::is_sqlparam( + localized_string_type::str2id(localized_string_type::INSTANCE_SUBRATING_VERY_POSITIVE) + ), ]); // All the rest of elements only happen if we are including user info. if ($userinfo) { diff --git a/backup/moodle2/restore_verbalfeedback_stepslib.php b/backup/moodle2/restore_verbalfeedback_stepslib.php index e28fc1b..8a09fd5 100644 --- a/backup/moodle2/restore_verbalfeedback_stepslib.php +++ b/backup/moodle2/restore_verbalfeedback_stepslib.php @@ -22,6 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +use mod_verbalfeedback\repository\model\localized_string_type; use mod_verbalfeedback\repository\tables; /** @@ -33,6 +34,13 @@ */ class restore_verbalfeedback_activity_structure_step extends restore_activity_structure_step { + /** + * The instance id when the item is newly inserted. + * + * @var int + */ + private $instanceid; + /** * Function that will return the structure to be processed by this restore_step. * Must return one array of @restore_path_element elements @@ -108,9 +116,9 @@ protected function process_verbalfeedback($data) { } // Insert the verbal feedback record. - $newitemid = $DB->insert_record(tables::INSTANCE_TABLE, $data); + $this->instanceid = $DB->insert_record(tables::INSTANCE_TABLE, $data); // Immediately after inserting "activity" record, call this. - $this->apply_activity_instance($newitemid); + $this->apply_activity_instance($this->instanceid); } /** @@ -326,8 +334,10 @@ private function process_localized_string($foreigenkeymapping, $data) { $data = (object) $data; $data->foreignkey = $this->get_mappingid($foreigenkeymapping, $data->foreignkey); - $data->languageid = $this->get_mappingid('language', $data->languageid); + $data->typeid = localized_string_type::str2id($data->type); + unset($data->type); + $data->instanceid = $this->instanceid; $DB->insert_record('verbalfeedback_local_string', $data); } }