When a user updates their profile, we need to also update a record in an external system. Thus, a custom module was created that uses hook_action_info. For the most part, this has worked great. However, I just noticed an anomaly when a user email address is changed.
Whenever a change is made to a custom profile field, say first name, the same field in the external system is updated accordingly. However, when the email address is changed, the hook_action_info is obviously executed (per the change in modified date), but the email in the external system remains the same. But, if I simply hit save again in the Drupal profile, without making any changes, the email in the external system is finally updated correctly.
To me, it seems like hook_action_info is being executed before the email change is saved, or I'm using the wrong variable.
My hook_action_info calls module_add_user_action, which accepts two arguments (&$object, $context = array()). Here is how I get the user profile info:
if (isset($object->uid)) {
$uid = $object->uid;
$user = user_load($uid);
}
elseif (isset($context['uid'])) {
$uid = $context['uid'];
$user = user_load($uid);
}
else {
global $user;
$uid = $user->uid;
}
$email = $user->mail;
Any suggestions or insights?