diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-10-06 09:09:06 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-10-06 09:18:40 +0100 |
commit | 6d3db3167b8a1b27761dfb6e52e7dce9d2e1550e (patch) | |
tree | b425bd43587cc8bf21bb50ef34b0ffa8609967fc /perllib/FixMyStreet/Script/Alerts.pm | |
parent | 31b8008e481a1b9f9b087cdb80efe4124d9aa500 (diff) |
Fix issue sending alerts around no-text update.
If there was a normal email alert, and then an alert for an update with
no text (so no email should be sent), it would still try to send the
blank email, and then die because no e.g. $data{cobrand} set.
This moves the skip-blank-update check higher up, above any email
sending code.
Diffstat (limited to 'perllib/FixMyStreet/Script/Alerts.pm')
-rw-r--r-- | perllib/FixMyStreet/Script/Alerts.pm | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/perllib/FixMyStreet/Script/Alerts.pm b/perllib/FixMyStreet/Script/Alerts.pm index 3f26b749b..4b5641f9e 100644 --- a/perllib/FixMyStreet/Script/Alerts.pm +++ b/perllib/FixMyStreet/Script/Alerts.pm @@ -88,6 +88,24 @@ sub send() { alert_id => $row->{alert_id}, parameter => $row->{item_id}, } ); + + # this is currently only for new_updates + if (defined($row->{item_text})) { + # this might throw up the odd false positive but only in cases where the + # state has changed and there was already update text + if ($row->{item_problem_state} && + !( $last_problem_state eq '' && $row->{item_problem_state} eq 'confirmed' ) && + $last_problem_state ne $row->{item_problem_state} + ) { + my $state = FixMyStreet::DB->resultset("State")->display($row->{item_problem_state}, 1, $cobrand); + + my $update = _('State changed to:') . ' ' . $state; + $row->{item_text} = $row->{item_text} ? $row->{item_text} . "\n\n" . $update : + $update; + } + next unless $row->{item_text}; + } + if ($last_alert_id && $last_alert_id != $row->{alert_id}) { $last_problem_state = ''; _send_aggregated_alert_email(%data); @@ -106,19 +124,6 @@ sub send() { my $url = $cobrand->base_url_for_report($row); # this is currently only for new_updates if (defined($row->{item_text})) { - # this might throw up the odd false positive but only in cases where the - # state has changed and there was already update text - if ($row->{item_problem_state} && - !( $last_problem_state eq '' && $row->{item_problem_state} eq 'confirmed' ) && - $last_problem_state ne $row->{item_problem_state} - ) { - my $state = FixMyStreet::DB->resultset("State")->display($row->{item_problem_state}, 1, $cobrand); - - my $update = _('State changed to:') . ' ' . $state; - $row->{item_text} = $row->{item_text} ? $row->{item_text} . "\n\n" . $update : - $update; - } - next unless $row->{item_text}; if ( $cobrand->moniker ne 'zurich' && $row->{alert_user_id} == $row->{user_id} ) { # This is an alert to the same user who made the report - make this a login link # Don't bother with Zurich which has no accounts |