Skip to content

Commit

Permalink
Merge branch 'MDL-40584_24' of https://github.com/mr-russ/moodle into…
Browse files Browse the repository at this point in the history
… MOODLE_24_STABLE
  • Loading branch information
danpoltawski committed Jul 23, 2013
2 parents 1f3be76 + 558f2de commit bb925bb
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions backup/util/dbops/restore_dbops.class.php
Expand Up @@ -614,13 +614,20 @@ public static function prechek_precheck_qbanks_by_level($restoreid, $courseid, $
} else {
self::set_backup_ids_record($restoreid, 'question_category', $category->id, $matchcat->id, $targetcontext->id);
$questions = self::restore_get_questions($restoreid, $category->id);

// Collect all the questions for this category into memory so we only talk to the DB once.
$questioncache = $DB->get_records_sql_menu("SELECT ".$DB->sql_concat('stamp', "' '", 'version').", id
FROM {question}
WHERE category = ?", array($matchcat->id));

foreach ($questions as $question) {
$matchq = $DB->get_record('question', array(
'category' => $matchcat->id,
'stamp' => $question->stamp,
'version' => $question->version));
if (isset($questioncache[$question->stamp." ".$question->version])) {
$matchqid = $questioncache[$question->stamp." ".$question->version];
} else {
$matchqid = false;
}
// 5a) No match, check if user can add q
if (!$matchq) {
if (!$matchqid) {
// 6a) User can, mark the q to be created
if ($canadd) {
// Nothing to mark, newitemid means create
Expand All @@ -645,7 +652,7 @@ public static function prechek_precheck_qbanks_by_level($restoreid, $courseid, $

// 5b) Match, mark q to be mapped
} else {
self::set_backup_ids_record($restoreid, 'question', $question->id, $matchq->id);
self::set_backup_ids_record($restoreid, 'question', $question->id, $matchqid);
}
}
}
Expand Down

0 comments on commit bb925bb

Please sign in to comment.