Hi Tim,
It looks as though there is a chunk of code that deletes the $quba object, and it's corresponding database data, before rebuilding a brand new (empty) $quba, in mod/quiz/startattempt.php#LINE166-end
. Would a new object, something like $questions_usage_carryover_data, need to be created before the deletion of the first $quba, containing the gradedright / gradedwrong data from DB table mdl_question_attempt_steps
, for immediate insertion into the metadata in mdl_question_attempt_step_data
for the brand new $quba as it is created? Am I missing some other place in the code where the two $quba objects (and their corresponding DB data) exist at the same time? For reference here is the startattempt code:
// Delete any previous preview attempts belonging to this user.
quiz_delete_previews($quizobj->get_quiz(), $USER->id);
$quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
// Create the new attempt and initialize the question sessions
$timenow = time(); // Update time now, in case the server is running really slowly.
$attempt = quiz_create_attempt($quizobj, $attemptnumber, $lastattempt, $timenow, $quizobj->is_preview_user());
if (!($quizobj->get_quiz()->attemptonlast && $lastattempt)) {
$attempt = quiz_start_new_attempt($quizobj, $quba, $attempt, $attemptnumber, $timenow);
} else {
$attempt = quiz_start_attempt_built_on_last($quba, $attempt, $lastattempt);
}
$transaction = $DB->start_delegated_transaction();
$attempt = quiz_attempt_save_started($quizobj, $quba, $attempt);
$transaction->allow_commit();
// Redirect to the attempt page.
redirect($quizobj->attempt_url($attempt->id, $page));
Thanks!