diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/SendReport.pm | 17 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Zurich.pm | 5 |
5 files changed, 22 insertions, 19 deletions
diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm index db95850e6..b869299a2 100644 --- a/perllib/FixMyStreet/SendReport.pm +++ b/perllib/FixMyStreet/SendReport.pm @@ -60,4 +60,21 @@ sub add_body { $self->body_config->{ $body->id } = $config; } +sub fetch_category { + my ($self, $body, $row, $category_override) = @_; + + my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find( { + body_id => $body->id, + category => $category_override || $row->category, + } ); + + unless ($contact) { + my $error = "Category " . $row->category . " does not exist for body " . $body->id . " and report " . $row->id . "\n"; + $self->error( "Failed to send over Open311\n" ) unless $self->error; + $self->error( $self->error . "\n" . $error ); + } + + return $contact; +} + 1; diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 679530507..6cd9afccd 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -12,10 +12,7 @@ sub build_recipient_list { my $all_confirmed = 1; foreach my $body ( @{ $self->bodies } ) { - my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find( { - body_id => $body->id, - category => $row->category - } ); + my $contact = $self->fetch_category($body, $row) or next; my ($body_email, $state, $note) = ( $contact->email, $contact->state, $contact->note ); diff --git a/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm b/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm index cf778c549..1ae938317 100644 --- a/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm +++ b/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm @@ -15,11 +15,7 @@ sub build_recipient_list { my $body = $self->bodies->[0]; # We don't care what the category was, look up the relevant contact - my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find({ - body_id => $body->id, - category => $self->contact, - }); - return unless $contact; + my $contact = $self->fetch_category($body, $row, $self->contact) or return; @{$self->to} = map { [ $_, $body->name ] } split /,/, $contact->email; return 1; diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index 8a6b992fd..45b056dc2 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -36,13 +36,9 @@ sub send { my $cobrand = $body->get_cobrand_handler || $row->get_cobrand_logged; $cobrand->call_hook(open311_config => $row, $h, \%open311_params); - # Try and fill in some ones that we've been asked for, but not asked the user for - - my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find( { - body_id => $body->id, - category => $row->category - } ); + my $contact = $self->fetch_category($body, $row) or next; + # Try and fill in some ones that we've been asked for, but not asked the user for my $extra = $row->get_extra_fields(); my $id_field = $contact->id_field; diff --git a/perllib/FixMyStreet/SendReport/Zurich.pm b/perllib/FixMyStreet/SendReport/Zurich.pm index 59adfd688..7416c64f9 100644 --- a/perllib/FixMyStreet/SendReport/Zurich.pm +++ b/perllib/FixMyStreet/SendReport/Zurich.pm @@ -29,10 +29,7 @@ sub build_recipient_list { my $parent = $body->parent; if ($parent && !$parent->parent) { # Division, might have an individual contact email address - my $contact = $row->result_source->schema->resultset("Contact")->find( { - body_id => $body->id, - category => $row->category - } ); + my $contact = $self->fetch_category($body, $row); $body_email = $contact->email if $contact && $contact->email; } |