diff options
author | Matthew Somerville <matthew@mysociety.org> | 2016-02-11 08:12:39 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2016-02-11 08:14:25 +0000 |
commit | 51d7011f8264a799d76483729ac1791f7dff99f9 (patch) | |
tree | e6ed1add3417f955538661e579755236b14305e5 | |
parent | ce25130c2a9789ad832848db1098f36065045673 (diff) |
Skip sending if any body marks it for skipping.
If a report was sent to multiple bodies, one of which was set to skip,
(e.g. temporarily turned off due to receiving issues), then the code
would still try and send the report due to the other bodies, leading to
multiple sendings and an error for the skipped body.
-rw-r--r-- | perllib/FixMyStreet/Script/Reports.pm | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/Script/Reports.pm b/perllib/FixMyStreet/Script/Reports.pm index d26e0fa70..e1eb5e2c5 100644 --- a/perllib/FixMyStreet/Script/Reports.pm +++ b/perllib/FixMyStreet/Script/Reports.pm @@ -130,6 +130,7 @@ sub send(;$) { my @dear; my %reporters = (); + my $skip = 0; while (my $body = $bodies->next) { my $sender_info = $cobrand->get_body_sender( $body, $row->category ); my $sender = "FixMyStreet::SendReport::" . $sender_info->{method}; @@ -141,6 +142,7 @@ sub send(;$) { $reporters{ $sender } ||= $sender->new(); if ( $reporters{ $sender }->should_skip( $row ) ) { + $skip = 1; debug_print("skipped by sender " . $sender_info->{method} . " (might be due to previous failed attempts?)", $row->id) if $debug_mode; } else { debug_print("OK, adding recipient body " . $body->id . ":" . $body->name . ", " . $body->send_method, $row->id) if $debug_mode; @@ -168,10 +170,7 @@ sub send(;$) { die 'Report not going anywhere for ID ' . $row->id . '!'; } - unless (@dear) { - debug_print("can't send because sender count is zero", $row->id) if $debug_mode; - next; - } + next if $skip; if ($h{category} eq _('Other')) { $h{category_footer} = _('this type of local problem'); |