From 9806941217c7f96c2612276858b5c1f4464252c5 Mon Sep 17 00:00:00 2001 From: Faustin Date: Sun, 22 Jan 2023 12:37:40 +0100 Subject: [PATCH] Update what is needed --- htdocs/admin/oauth.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/htdocs/admin/oauth.php b/htdocs/admin/oauth.php index 1ed4683496e..6fadc36a285 100644 --- a/htdocs/admin/oauth.php +++ b/htdocs/admin/oauth.php @@ -109,13 +109,36 @@ if ($action == 'update') { $error++; } } - print $newconstvalue.'_ID'."######".GETPOST($constvalue.'_ID')."\n"; + // If name changed, we have to delete old const and proceed few other changes if ($constvalue !== $newconstvalue) { dolibarr_del_const($db, $constvalue.'_ID', $conf->entity); dolibarr_del_const($db, $constvalue.'_SECRET', $conf->entity); dolibarr_del_const($db, $constvalue.'_URLAUTHORIZE', $conf->entity); dolibarr_del_const($db, $constvalue.'_SCOPE', $conf->entity); + + // Update name of token + $oldname = preg_replace('/^OAUTH_/', '', $constvalue); + $oldprovider = ucfirst(strtolower(preg_replace('/-.*$/', '', $oldname))); + $oldlabel = preg_replace('/^.*-/', '', $oldname); + $newlabel = preg_replace('/^.*-/', '', $newconstvalue); + + $sql = "UPDATE ".MAIN_DB_PREFIX."oauth_token"; + $sql.= " SET service = '".$oldprovider."-".$newlabel."'"; + $sql.= " WHERE service = '".$oldprovider."-".$oldlabel."'"; + + + $resql = $db->query($sql); + if (!$resql) { + $error++; + } + + // Update const where the token was used, might not be exhaustive + if (getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE') == $oldname) { + if (!dolibarr_set_const($db, 'MAIN_MAIL_SMTPS_OAUTH_SERVICE', strtoupper($oldprovider).'-'.$newlabel, 'chaine', 0, '', $conf->entity)) { + $error++; + } + } } } }