Permalink
Browse files

MDL-34118 question backup: fixes for usage prefixes in backups.

  • Loading branch information...
1 parent 3e3ae0e commit 895d364bcf865729cf1ebe3485962390c0147e2e Juergen Zimmer committed with timhunt Jul 19, 2012
Showing with 11 additions and 9 deletions.
  1. +11 −9 backup/moodle2/restore_stepslib.php
@@ -3499,6 +3499,7 @@ protected function add_question_usages($element, &$paths, $nameprefix = '') {
if (! $element instanceof restore_path_element) {
throw new restore_step_exception('element_must_be_restore_path_element', $element);
}
+
// Check $paths is one array
if (!is_array($paths)) {
throw new restore_step_exception('paths_must_be_array', $paths);
@@ -3517,7 +3518,7 @@ protected function add_question_usages($element, &$paths, $nameprefix = '') {
/**
* Process question_usages
*/
- protected function process_question_usage($data) {
+ protected function process_question_usage($data, $nameprefix = '') {
global $DB;
// Clear our caches.
@@ -3535,7 +3536,7 @@ protected function process_question_usage($data) {
$this->inform_new_usage_id($newitemid);
- $this->set_mapping('question_usage', $oldid, $newitemid, false);
+ $this->set_mapping($nameprefix . 'question_usage', $oldid, $newitemid, false);
}
/**
@@ -3549,43 +3550,43 @@ protected function process_question_usage($data) {
/**
* Process question_attempts
*/
- protected function process_question_attempt($data) {
+ protected function process_question_attempt($data, $nameprefix = '') {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$question = $this->get_mapping('question', $data->questionid);
- $data->questionusageid = $this->get_new_parentid('question_usage');
+ $data->questionusageid = $this->get_new_parentid($nameprefix . 'question_usage');
$data->questionid = $question->newitemid;
$data->timemodified = $this->apply_date_offset($data->timemodified);
$newitemid = $DB->insert_record('question_attempts', $data);
- $this->set_mapping('question_attempt', $oldid, $newitemid);
+ $this->set_mapping($nameprefix . 'question_attempt', $oldid, $newitemid);
$this->qtypes[$newitemid] = $question->info->qtype;
$this->newquestionids[$newitemid] = $data->questionid;
}
/**
* Process question_attempt_steps
*/
- protected function process_question_attempt_step($data) {
+ protected function process_question_attempt_step($data, $nameprefix = '') {
global $DB;
$data = (object)$data;
$oldid = $data->id;
// Pull out the response data.
$response = array();
- if (!empty($data->response['variable'])) {
- foreach ($data->response['variable'] as $variable) {
+ if (!empty($data->{$nameprefix . 'response'}[$nameprefix . 'variable'])) {
+ foreach ($data->{$nameprefix . 'response'}[$nameprefix . 'variable'] as $variable) {
$response[$variable['name']] = $variable['value'];
}
}
unset($data->response);
- $data->questionattemptid = $this->get_new_parentid('question_attempt');
+ $data->questionattemptid = $this->get_new_parentid($nameprefix . 'question_attempt');
$data->timecreated = $this->apply_date_offset($data->timecreated);
$data->userid = $this->get_mappingid('user', $data->userid);
@@ -3598,6 +3599,7 @@ protected function process_question_attempt_step($data) {
$this->qtypes[$data->questionattemptid],
$this->newquestionids[$data->questionattemptid],
$data->sequencenumber, $response);
+
foreach ($response as $name => $value) {
$row = new stdClass();
$row->attemptstepid = $newitemid;

0 comments on commit 895d364

Please sign in to comment.