Skip to content

Commit

Permalink
Fix if no old context exists
Browse files Browse the repository at this point in the history
  • Loading branch information
davidszkiba committed Nov 21, 2024
1 parent 2277488 commit 499a5f2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion classes/catquiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -2649,9 +2649,13 @@ private static function get_unfinished_question_states() {
* @param int $oldcontextid The ID of the context to move items from
* @return void
*/
public function move_items_to_new_context(int $newcontextid, int $oldcontextid): void {
public function move_items_to_new_context(int $newcontextid, ?int $oldcontextid): void {
global $DB;

if (!$oldcontextid) {
return;
}

$oldactiveparams = [];
$oldparams = $DB->get_records('local_catquiz_itemparams', ['contextid' => $oldcontextid]);
foreach ($oldparams as $op) {
Expand Down Expand Up @@ -2687,6 +2691,7 @@ public function move_items_to_new_context(int $newcontextid, int $oldcontextid):
$DB->update_record('local_catquiz_itemparams', $ip);
} else {
// Otherwise: Should we copy the param from the previous context?
unset($copiedparam->id);
$copiedparam = $oldactiveparams[$item->activeparamid];
$copiedparam->contextid = $newcontextid;
$now = time();
Expand Down

0 comments on commit 499a5f2

Please sign in to comment.