diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-05-01 16:51:48 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2019-06-20 12:57:12 +0100 |
commit | 67ef55d16668102724fc23d2d95dcbc9705afed1 (patch) | |
tree | edc9b29c7f17b9e5a71d8cc1a80d274ba2984a34 /perllib/Open311/GetServiceRequestUpdates.pm | |
parent | 1aeca7c6130aa6de377c8e00e8d22ae05943e919 (diff) |
[Open311] Allow description in email template.
By specifying a placeholder in an email template, it can be replaced
by the description returned from the Open311 server.
Diffstat (limited to 'perllib/Open311/GetServiceRequestUpdates.pm')
-rw-r--r-- | perllib/Open311/GetServiceRequestUpdates.pm | 17 |
1 files changed, 13 insertions, 4 deletions
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"; |