Skip to content

Commit

Permalink
Fix mapping in backup and restore.
Browse files Browse the repository at this point in the history
  • Loading branch information
srobotta committed Dec 5, 2024
1 parent b5f81d4 commit 415cc10
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
56 changes: 40 additions & 16 deletions backup/moodle2/backup_verbalfeedback_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 13 additions & 3 deletions backup/moodle2/restore_verbalfeedback_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 415cc10

Please sign in to comment.