MDL-67853 message: Translate user message preference from restore and WS

This commit is contained in:
Pau Ferrer Ocaña 2021-12-10 12:40:38 +01:00
parent b4c75986ad
commit d195956f3a
2 changed files with 48 additions and 2 deletions

View file

@ -415,6 +415,18 @@ class core_user_external extends external_api {
if (!empty($preferences)) {
$userpref = ['id' => $userid];
foreach ($preferences as $preference) {
/*
* Rename user message provider preferences to avoid orphan settings on old app versions.
* @todo Remove this "translation" block on MDL-73284.
*/
if (preg_match('/message_provider_.*_loggedin/', $preference['type']) ||
preg_match('/message_provider_.*_loggedoff/', $preference['type'])) {
$nameparts = explode('_', $preference['type']);
array_pop($nameparts);
$preference['type'] = implode('_', $nameparts).'_enabled';
}
$userpref['preference_' . $preference['type']] = $preference['value'];
}
useredit_update_user_preference($userpref);