Skip to content

Instantly share code, notes, and snippets.

@adixon
Last active January 16, 2019 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adixon/b7338d361c08d241f11d07b7c6913ffe to your computer and use it in GitHub Desktop.
Save adixon/b7338d361c08d241f11d07b7c6913ffe to your computer and use it in GitHub Desktop.
diff --git a/CRM/Utils/System/Drupal.php b/CRM/Utils/System/Drupal.php
index 4a677da..4a5e712 100644
--- a/CRM/Utils/System/Drupal.php
+++ b/CRM/Utils/System/Drupal.php
@@ -94,10 +94,14 @@ class CRM_Utils_System_Drupal extends CRM_Utils_System_DrupalBase {
public function updateCMSName($ufID, $ufName) {
// CRM-5555
if (function_exists('user_load')) {
- $user = user_load($ufID);
- if ($user->mail != $ufName) {
- user_save($user, array('mail' => $ufName));
- $user = user_load($ufID);
+ $account = user_load($ufID);
+ if ($account->mail != $ufName) {
+ if (user_access('administer users') || $account->uid == $user->uid) {
+ user_save($account, array('mail' => $ufName));
+ if ($account->uid == $user->uid) {
+ $user = user_load($ufID);
+ }
+ }
}
}
}
@jackrabbithanna
Copy link

should there be a 'global $user;' after / before the $account object is loaded?
where is the $user variable defined before it is used in line 15?

@adixon
Copy link
Author

adixon commented Jan 16, 2019

Yes, that's an interesting question. There was no global $user in the existing code, so in theory that code shouldn't really do much. I left it in case there's some subtle cases where it does matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment