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 | ||||
-rw-r--r-- | perllib/Open311/GetServiceRequestUpdates.pm | 17 |
6 files changed, 35 insertions, 23 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; } diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index 8193aaa9b..c0da7793f 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -235,13 +235,12 @@ sub comment_text_for_request { my ($self, $request, $problem, $state, $old_state, $ext_code, $old_ext_code) = @_; - return $request->{description} if $request->{description}; - # Response templates are only triggered if the state/external status has changed. # And treat any fixed state as fixed. my $state_changed = $state ne $old_state && !( $problem->is_fixed && FixMyStreet::DB::Result::Problem->fixed_states()->{$state} ); my $ext_code_changed = $ext_code ne $old_ext_code; + my $template; if ($state_changed || $ext_code_changed) { my $state_params = { 'me.state' => $state @@ -250,14 +249,24 @@ sub comment_text_for_request { $state_params->{'me.external_status_code'} = $ext_code; }; - if (my $template = $problem->response_templates->search({ + if (my $t = $problem->response_templates->search({ auto_response => 1, -or => $state_params, })->first) { - return $template->text; + $template = $t->text; } } + my $desc = $request->{description} || ''; + if ($desc && (!$template || $template !~ /\{\{description}}/)) { + return $desc; + } + + if ($template) { + $template =~ s/\{\{description}}/$desc/; + return $template; + } + return "" if $self->blank_updates_permitted; print STDERR "Couldn't determine update text for $request->{update_id} (report " . $problem->id . ")\n"; |