+ $original = clone($user);
+
+ $user->nickname = $nickname;
+
+ $result = $user->updateKeys($original);
+
+ if ($result === FALSE) {
+ common_log_db_error($user, 'UPDATE', __FILE__);
+ common_server_error(_t('Couldnt update user.'));
+ return;
+ }
+ }
+
+ if ($user->email != $email) {
+
+ common_debug('Updating user email from ' . $user->email . ' to ' . $email,
+ __FILE__);
+
+ # We don't update email directly; it gets done by confirmemail
+
+ $confirm = new Confirm_address();
+
+ $confirm->code = common_confirmation_code(128);
+ $confirm->user_id = $user->id;
+ $confirm->address = $email;
+ $confirm->address_type = 'email';
+
+ $result = $confirm->insert();
+
+ if (!$result) {
+ common_log_db_error($confirm, 'INSERT', __FILE__);
+ common_server_error(_t('Couldnt confirm email.'));
+ return FALSE;
+ }
+
+ # XXX: try not to do this in the middle of a transaction
+
+ mail_confirm_address($confirm->code,
+ $profile->nickname,
+ $email);