Skip to content

Commit

Permalink
Merge branch '31_mdl75668' of https://github.com/danmarsden/moodle in…
Browse files Browse the repository at this point in the history
…to MOODLE_311_STABLE
  • Loading branch information
snake committed Sep 28, 2022
2 parents 47f85d5 + e237e83 commit f40424c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions backup/moodle2/restore_stepslib.php
Expand Up @@ -4239,7 +4239,8 @@ public function process_block($data) {

// Look for the parent contextid
if (!$data->parentcontextid = $this->get_mappingid('context', $data->parentcontextid)) {
throw new restore_step_exception('restore_block_missing_parent_ctx', $data->parentcontextid);
// Parent contextid does not exist, ignore this block.
return false;
}

// TODO: it would be nice to use standard plugin supports instead of this instance_allow_multiple()
Expand Down Expand Up @@ -4285,14 +4286,17 @@ public function process_block($data) {
$params['subpagepattern'] = $data->subpagepattern;
}

$exists = $DB->record_exists_sql("SELECT bi.id
$existingblock = $DB->get_records_sql("SELECT bi.id
FROM {block_instances} bi
JOIN {block} b ON b.name = bi.blockname
WHERE bi.blockname = :blockname
AND $contextsql
AND bi.pagetypepattern $pagetypepatternsql
AND $subpagepatternsql", $params);
if ($exists) {
if (!empty($existingblock)) {
// Save the context mapping in case something else is linking to this block's context.
$newcontext = context_block::instance(reset($existingblock)->id);
$this->set_mapping('context', $oldcontextid, $newcontext->id);
// There is at least one very similar block visible on the page where we
// are trying to restore the block. In these circumstances the block API
// would not allow the user to add another instance of the block, so we
Expand All @@ -4311,6 +4315,9 @@ public function process_block($data) {
if ($birecs = $DB->get_records('block_instances', $params)) {
foreach($birecs as $birec) {
if ($birec->configdata == $data->configdata) {
// Save the context mapping in case something else is linking to this block's context.
$newcontext = context_block::instance($birec->id);
$this->set_mapping('context', $oldcontextid, $newcontext->id);
return false;
}
}
Expand Down

0 comments on commit f40424c

Please sign in to comment.