diff options
author | Frédéric Buclin <LpSolit@gmail.com> | 2010-05-07 14:59:28 +0200 |
---|---|---|
committer | Frédéric Buclin <LpSolit@gmail.com> | 2010-05-07 14:59:28 +0200 |
commit | 4ec67697f3ea85ebf73f486f6dea1aba87d7da76 (patch) | |
tree | 60ad3d69ac496a5bc360253745f4f46656b53b34 /userprefs.cgi | |
parent | Bug 395451 - "Bugzilla::BugMail needs to use Bug objects internally instead o... (diff) | |
download | bugzilla-4ec67697f3ea85ebf73f486f6dea1aba87d7da76.tar.gz bugzilla-4ec67697f3ea85ebf73f486f6dea1aba87d7da76.tar.bz2 bugzilla-4ec67697f3ea85ebf73f486f6dea1aba87d7da76.zip |
Bug 561745: Impossible to uncheck boxes in the Email preferences
r/a=mkanat
Diffstat (limited to 'userprefs.cgi')
-rwxr-xr-x | userprefs.cgi | 77 |
1 files changed, 36 insertions, 41 deletions
diff --git a/userprefs.cgi b/userprefs.cgi index f95ddb3e3..d15bcd13a 100755 --- a/userprefs.cgi +++ b/userprefs.cgi @@ -219,21 +219,6 @@ sub DoEmail { @watchers = sort { lc($a) cmp lc($b) } @watchers; $vars->{'watchers'} = \@watchers; - - ########################################################################### - # Role-based preferences - ########################################################################### - my $sth = $dbh->prepare("SELECT relationship, event " . - "FROM email_setting " . - "WHERE user_id = ?"); - $sth->execute($user->id); - - my %mail; - while (my ($relationship, $event) = $sth->fetchrow_array()) { - $mail{$relationship}{$event} = 1; - } - - $vars->{'mail'} = \%mail; } sub SaveEmail { @@ -248,54 +233,64 @@ sub SaveEmail { ########################################################################### $dbh->bz_start_transaction(); - # Delete all the user's current preferences - $dbh->do("DELETE FROM email_setting WHERE user_id = ?", undef, $user->id); + my $sth_insert = $dbh->prepare('INSERT INTO email_setting + (user_id, relationship, event) VALUES (?, ?, ?)'); - # Repopulate the table - first, with normal events in the + my $sth_delete = $dbh->prepare('DELETE FROM email_setting + WHERE user_id = ? AND relationship = ? AND event = ?'); + # Load current email preferences into memory before updating them. + my $settings = $user->mail_settings; + + # Update the table - first, with normal events in the # relationship/event matrix. - # Note: the database holds only "off" email preferences, as can be implied - # from the name of the table - profiles_nomail. my %relationships = Bugzilla::BugMail::relationships(); foreach my $rel (keys %relationships) { + next if ($rel == REL_QA && !Bugzilla->params->{'useqacontact'}); # Positive events: a ticked box means "send me mail." foreach my $event (POS_EVENTS) { - if (defined($cgi->param("email-$rel-$event")) - && $cgi->param("email-$rel-$event") == 1) - { - $dbh->do("INSERT INTO email_setting " . - "(user_id, relationship, event) " . - "VALUES (?, ?, ?)", - undef, ($user->id, $rel, $event)); + my $is_set = $cgi->param("email-$rel-$event"); + if ($is_set xor $settings->{$rel}{$event}) { + if ($is_set) { + $sth_insert->execute($user->id, $rel, $event); + } + else { + $sth_delete->execute($user->id, $rel, $event); + } } } # Negative events: a ticked box means "don't send me mail." foreach my $event (NEG_EVENTS) { - if (!defined($cgi->param("neg-email-$rel-$event")) || - $cgi->param("neg-email-$rel-$event") != 1) - { - $dbh->do("INSERT INTO email_setting " . - "(user_id, relationship, event) " . - "VALUES (?, ?, ?)", - undef, ($user->id, $rel, $event)); + my $is_set = $cgi->param("neg-email-$rel-$event"); + if (!$is_set xor $settings->{$rel}{$event}) { + if (!$is_set) { + $sth_insert->execute($user->id, $rel, $event); + } + else { + $sth_delete->execute($user->id, $rel, $event); + } } } } # Global positive events: a ticked box means "send me mail." foreach my $event (GLOBAL_EVENTS) { - if (defined($cgi->param("email-" . REL_ANY . "-$event")) - && $cgi->param("email-" . REL_ANY . "-$event") == 1) - { - $dbh->do("INSERT INTO email_setting " . - "(user_id, relationship, event) " . - "VALUES (?, ?, ?)", - undef, ($user->id, REL_ANY, $event)); + my $is_set = $cgi->param("email-" . REL_ANY . "-$event"); + if ($is_set xor $settings->{+REL_ANY}{$event}) { + if ($is_set) { + $sth_insert->execute($user->id, REL_ANY, $event); + } + else { + $sth_delete->execute($user->id, REL_ANY, $event); + } } } $dbh->bz_commit_transaction(); + # We have to clear the cache about email preferences. + delete $user->{'mail_settings'}; + ########################################################################### # User watching ########################################################################### |