aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/Open311')
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm23
-rw-r--r--perllib/Open311/PopulateServiceList.pm14
2 files changed, 32 insertions, 5 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index db2a452da..2620b176a 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -103,16 +103,17 @@ sub update_comments {
$problem = $self->schema->resultset('Problem')->to_body($body)->search( $criteria );
if (my $p = $problem->first) {
- next unless defined $request->{update_id} && defined $request->{description};
+ next unless defined $request->{update_id};
my $c = $p->comments->search( { external_id => $request->{update_id} } );
if ( !$c->first ) {
+ my $state = $self->map_state( $request->{status} );
my $comment = $self->schema->resultset('Comment')->new(
{
problem => $p,
user => $self->system_user,
external_id => $request->{update_id},
- text => $request->{description},
+ text => $self->comment_text_for_request($request, $p, $state),
mark_fixed => 0,
mark_open => 0,
anonymous => 0,
@@ -138,8 +139,6 @@ sub update_comments {
# do not change the status of the problem as it's
# tricky to determine the right thing to do.
if ( $comment->created > $p->lastupdate ) {
- my $state = $self->map_state( $request->{status} );
-
# don't update state unless it's an allowed state and it's
# actually changing the state of the problem
if ( FixMyStreet::DB::Result::Problem->visible_states()->{$state} && $p->state ne $state &&
@@ -180,6 +179,22 @@ sub update_comments {
return 1;
}
+sub comment_text_for_request {
+ my ($self, $request, $problem, $state) = @_;
+
+ return $request->{description} if $request->{description};
+
+ if (my $template = $problem->response_templates->search({
+ auto_response => 1,
+ 'me.state' => $state
+ })->first) {
+ return $template->text;
+ }
+
+ print STDERR "Couldn't determine update text for $request->{update_id} (report " . $problem->id . ")\n";
+ return "";
+}
+
sub map_state {
my $self = shift;
my $incoming_state = shift;
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index dbd0d1c68..e8d06efdf 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -156,7 +156,13 @@ sub _handle_existing_contact {
if ( $contact and lc($metadata) eq 'true' ) {
$self->_add_meta_to_contact( $contact );
} elsif ( $contact and $contact->extra and lc($metadata) eq 'false' ) {
- $contact->update( { extra => undef } );
+ $contact->set_extra_fields();
+ $contact->update;
+ }
+
+ if (my $group = $self->_current_service->{group}) {
+ $contact->set_extra_metadata(group => $group);
+ $contact->update;
}
push @{ $self->found_contacts }, $self->_current_service->{service_code};
@@ -182,6 +188,12 @@ sub _create_contact {
);
};
+ if (my $group = $self->_current_service->{group}) {
+ $contact->set_extra_metadata(group => $group);
+ $contact->update;
+ }
+
+
if ( $@ ) {
warn "Failed to create contact for service code " . $self->_current_service->{service_code} . " for body @{[$self->_current_body->id]}: $@\n"
if $self->verbose >= 1;