MDL-84466 qbank: Transfer question files and tags in separate tasks

On a large site, the task to transfer question categories to the new
mod_qbanks contexts could take a very long time, as of any transferred
categories contain questions using files, each file has to be updated
individually.

This change splits up the transfer into 2 stages. The first stage
(transfer_question_categories) updates the context IDs on each question
category and moves them to their new top category, then spawns an
instance of transfer_questions for each category that was moved.
transfer_questions then handles moving the files and tags for questions
in a single category at a time. This allows the transfer process to be
parallelised by using multi cron or ad-hoc task runners, so should speed
things up on larger sites.
This commit is contained in:
Mark Johnson
2025-07-15 12:03:25 +01:00
parent 61af040cd5
commit 60f58afc5f
8 changed files with 365 additions and 16 deletions
+8 -7
View File
@@ -671,14 +671,15 @@ function move_question_set_references(int $oldcategoryid, int $newcatgoryid,
if (isset($filter['questioncategoryid'])) {
$filter = question_reference_manager::convert_legacy_set_reference_filter_condition($filter);
}
if ((int)$filter['filter']['category']['values'][0] === $oldcategoryid) {
$setreference->questionscontextid = $newcontextid;
if ($oldcategoryid !== $newcatgoryid) {
$filter['filter']['category']['values'][0] = $newcatgoryid;
$setreference->filtercondition = json_encode($filter);
}
$DB->update_record('question_set_references', $setreference);
$setreference->questionscontextid = $newcontextid;
if (
(int)$filter['filter']['category']['values'][0] === $oldcategoryid
&& $oldcategoryid !== $newcatgoryid
) {
$filter['filter']['category']['values'][0] = $newcatgoryid;
$setreference->filtercondition = json_encode($filter);
}
$DB->update_record('question_set_references', $setreference);
}
$setreferences->close();
}