MDL-87795 message_airnotifier: Handle 404 (unregistered token) responses

This commit is contained in:
Albert Gasset
2026-03-12 11:51:26 +01:00
parent 65b51ef436
commit 46d1003ea3
3 changed files with 20 additions and 2 deletions
@@ -0,0 +1,7 @@
issueNumber: MDL-87795
notes:
core_user:
- message: >-
Added new optional parameter `userid` to the `user_remove_user_device`
function.
type: improved
@@ -160,6 +160,14 @@ class message_output_airnotifier extends message_output {
// JSON POST raw body request.
$resp = $curl->post($serverurl, json_encode($params));
// Check if the device token is no longer registered.
if ($curl->info['http_code'] === 404) {
$json = json_decode($resp, true);
if (($json['error'] ?? null) === 'Unregistered token') {
user_remove_user_device($devicetoken->uuid, $devicetoken->appid, $devicetoken->userid);
}
}
}
return true;
+5 -2
View File
@@ -1121,13 +1121,16 @@ function user_is_previously_used_password($userid, $password) {
*
* @param string $uuid The device UUID.
* @param string $appid The app id. If empty all the devices matching the UUID for the user will be removed.
* @param int|null $userid The user id. If null, the current user will be used.
* @return bool true if removed, false if the device didn't exists in the database
* @since Moodle 2.9
*/
function user_remove_user_device($uuid, $appid = "") {
function user_remove_user_device($uuid, $appid = "", $userid = null) {
global $DB, $USER;
$conditions = array('uuid' => $uuid, 'userid' => $USER->id);
$userid ??= $USER->id;
$conditions = ['uuid' => $uuid, 'userid' => $userid];
if (!empty($appid)) {
$conditions['appid'] = $appid;
}