Skip to content

Commit

Permalink
MDL-65326 backup: check caps exist before assigning
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriim committed May 28, 2019
1 parent 383aec8 commit 2c76364
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,12 @@ protected function after_execute() {
}

$capability = 'mod/' . $modname . ':addinstance';

if (!get_capability_info($capability)) {
$this->log("Capability '{$capability}' was not found!", backup::LOG_WARNING);
continue;
}

foreach ($roleids as $roleid) {
assign_capability($capability, CAP_PREVENT, $roleid, $context);
}
Expand Down Expand Up @@ -2107,9 +2113,12 @@ public function process_override($data) {
$newroleid = $this->get_mappingid('role', $data->roleid);
// If newroleid and context are valid assign it via API (it handles dupes and so on)
if ($newroleid && $this->task->get_contextid()) {
// TODO: assign_capability() needs one userid param to be able to specify our restore userid
// TODO: it seems that assign_capability() doesn't check for valid capabilities at all ???
assign_capability($data->capability, $data->permission, $newroleid, $this->task->get_contextid());
if (!get_capability_info($data->capability)) {
$this->log("Capability '{$data->capability}' was not found!", backup::LOG_WARNING);
} else {
// TODO: assign_capability() needs one userid param to be able to specify our restore userid.
assign_capability($data->capability, $data->permission, $newroleid, $this->task->get_contextid());
}
}
}
}
Expand Down

0 comments on commit 2c76364

Please sign in to comment.