Merge branch 'MDL-78572_401' of https://github.com/timhunt/moodle into MOODLE_401_STABLE

This commit is contained in:
Jun Pataleta 2023-07-04 09:47:43 +08:00
commit 5db1843de2
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7
2 changed files with 28 additions and 1 deletions

View File

@ -272,8 +272,34 @@ class backpack_api2p1 {
$msg['status'] = \core\output\notification::NOTIFY_SUCCESS;
$msg['message'] = get_string('addedtobackpack', 'badges');
} else {
if ($response) {
// Although the specification defines that status error is a string, some providers, like Badgr, are wrongly
// returning an array. It has been reported, but adding these extra checks doesn't hurt, just in case.
if (
property_exists($response, 'status') &&
is_object($response->status) &&
property_exists($response->status, 'error')
) {
$statuserror = $response->status->error;
if (is_array($statuserror)) {
$statuserror = implode($statuserror);
}
} else if (property_exists($response, 'error')) {
$statuserror = $response->error;
if (property_exists($response, 'message')) {
$statuserror .= '. Message: ' . $response->message;
}
}
} else {
$statuserror = 'Empty response';
}
$data = [
'badgename' => $data['assertion']['badge']['name'],
'error' => $statuserror,
];
$msg['status'] = \core\output\notification::NOTIFY_ERROR;
$msg['message'] = get_string('backpackexporterror', 'badges', $data['assertion']['badge']['name']);
$msg['message'] = get_string('backpackexporterrorwithinfo', 'badges', $data);
}
return $msg;
}

View File

@ -130,6 +130,7 @@ $string['backpackemailverifypending'] = 'A verification email has been sent to <
$string['backpackemailverifysuccess'] = 'Thanks for verifying your email address. You are now connected to your backpack.';
$string['backpackemailverifytokenmismatch'] = 'The token in the link you clicked does not match the stored token. Make sure you clicked the link in most recent email you received.';
$string['backpackexporterror'] = 'Can\'t export the badge to backpack';
$string['backpackexporterrorwithinfo'] = 'Can\'t export the badge "{$a->badgename}" to backpack. Error: {$a->error}';
$string['backpackimport'] = 'Badge import settings';
$string['backpackimport_help'] = 'After the backpack connection is successfully established, badges from your backpack can be displayed on your badges page and your profile page.