On a drupal 4.7 RC1 with CVS module: I receive an email when I make a change to user profile (created before module installed). I'll try to look more into it I'm surprised of such a bug because if it was happening to everybody there would be an issue about it here for sure and this bug would be corrected.
Note i received the email account blocked but the account is not blocked (thankfully)

I'm using module version 1.4 from 20 march

Comments

alliax’s picture

I looked in the module code and in my opinion the bug can happen only in this part of the code :

function user_status_user($op, &$edit, &$user) {
  switch ($op) {
  case 'update':
    if ($edit['status'] != $user->status) {
      $notify_site = variable_get('site_name', 'Drupal');
      $notify_loginurl = url('user', NULL, NULL, TRUE);
      $from = variable_get('site_mail', ini_get('sendmail_from'));
      $headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: <$from>\nErrors-to: $from\n";
      if (valid_email_address($user->mail) && valid_email_address($from)) {
        switch ($edit['status']) {
        case 0:
          if (variable_get('user_status_blocked_enable', FALSE)) {
            return user_mail($user->mail,
                             str_replace(array('%site', '%user'),
                                         array($notify_site, $user->name),
                                         variable_get('user_status_blocked_subject', user_status_blocked_subject())),
                             str_replace(array('%site', '%user', '%loginurl'),
                                       array($notify_site, $user->name, $notify_loginurl),
                                       variable_get('user_status_blocked_body', user_status_blocked_body())),
                             $headers);
          }
          break;

So do you have any idea why it behaves like that on my website ?

alliax’s picture

in fact to be more precise, I think the problem is on this line :

if ($edit['status'] != $user->status) {
............
and then :
switch ($edit['status']) {
        case 0:

since it is because the module thinks that I've updated the status (when I just make profile changes) and that the status is now UNACTIVE that it triggers an email for account blocked!
So is $edit['status'] really a good variable ?

gte451f’s picture

I can confirm on RC2, when I change a user profile I get an email saying that there have been account changes but the body says....

Hello user,

Your account on GameTrust has been blocked.

LuckyOne’s picture

Maybe it would help if rewritten as follows:

if ($edit['status'] != $user->status) {

should become

if (isset($user->status) && isset($edit['status']) && $edit['status'] != $user->status) {

Could somebody try that because I just cannot reproduce this bug...

alliax’s picture

Still on RC1, I tried your change and it works as it should, thank you!

dww’s picture

Assigned: Unassigned » dww
Status: Active » Needs review
StatusFileSize
new895 bytes

sorry y'all, i've been on vacation in brazil for 2 weeks, and totally out of touch with drupal. just got back today. i don't have time right now to fully test/review this bug. is this the patch y'all are proposing should go in? i'll take a closer look tomorrow (and probably commit it) but i just wanted to be sure we're all talking about the same change. ;)

thanks,
-derek

dww’s picture

Status: Needs review » Fixed

the check for isset($user->status) is unnecessary, since the user object will *always* have a status (or things are really busted). ;) i committed the attached simplified version of this patch to 4.6, 4.7 and CVS head. thanks to everyone for the report and the suggested fix.

-derek

dww’s picture

StatusFileSize
new982 bytes

whoops, forgot to attach the patch (for the interested reader)

Anonymous’s picture

Status: Fixed » Closed (fixed)