From 935f431ee0da77dd26a78b959d3b9afb89665c0f Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 20 Dec 2017 15:58:51 +0000 Subject: fetch new problems over open311 This enables the display of existing reports from the back end on FMS if the body is configured to do this. Reports will not be created if they are missing an id, a lat or a long, if the lat/long is outside the area covered by the body, if there is already a report with a matching id, or if we can't parse out the request time. --- perllib/Open311/GetServiceRequestUpdates.pm | 32 +++-------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) (limited to 'perllib/Open311/GetServiceRequestUpdates.pm') diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index 2620b176a..8e83d08b9 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -107,7 +107,7 @@ sub update_comments { my $c = $p->comments->search( { external_id => $request->{update_id} } ); if ( !$c->first ) { - my $state = $self->map_state( $request->{status} ); + my $state = $open311->map_state( $request->{status} ); my $comment = $self->schema->resultset('Comment')->new( { problem => $p, @@ -124,16 +124,8 @@ sub update_comments { } ); - if ($request->{media_url}) { - my $ua = LWP::UserAgent->new; - my $res = $ua->get($request->{media_url}); - if ( $res->is_success && $res->content_type eq 'image/jpeg' ) { - my $photoset = FixMyStreet::App::Model::PhotoSet->new({ - data_items => [ $res->decoded_content ], - }); - $comment->photo($photoset->data); - } - } + $open311->add_media($request->{media_url}, $comment) + if $request->{media_url}; # if the comment is older than the last update # do not change the status of the problem as it's @@ -195,22 +187,4 @@ sub comment_text_for_request { return ""; } -sub map_state { - my $self = shift; - my $incoming_state = shift; - - $incoming_state = lc($incoming_state); - $incoming_state =~ s/_/ /g; - - my %state_map = ( - fixed => 'fixed - council', - 'not councils responsibility' => 'not responsible', - 'no further action' => 'unable to fix', - open => 'confirmed', - closed => 'fixed - council' - ); - - return $state_map{$incoming_state} || $incoming_state; -} - 1; -- cgit v1.2.3 From 8c23490f465fad0089d77ee362c566d066798d09 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 1 Mar 2018 12:31:48 +0000 Subject: permit blank updates to be fetched over Open311 Add a per body configuration option to allow Open311 updates to contain only a status change, rather than emitting a warning when this happens. --- perllib/Open311/GetServiceRequestUpdates.pm | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'perllib/Open311/GetServiceRequestUpdates.pm') diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index 8e83d08b9..f2a319f15 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -12,6 +12,7 @@ has end_date => ( is => 'ro', default => sub { undef } ); has suppress_alerts => ( is => 'rw', default => 0 ); has verbose => ( is => 'ro', default => 0 ); has schema => ( is =>'ro', lazy => 1, default => sub { FixMyStreet::DB->schema->connect } ); +has blank_updates_permitted => ( is => 'rw', default => 0 ); Readonly::Scalar my $AREA_ID_BROMLEY => 2482; Readonly::Scalar my $AREA_ID_OXFORDSHIRE => 2237; @@ -49,6 +50,7 @@ sub fetch { } $self->suppress_alerts( $body->suppress_alerts ); + $self->blank_updates_permitted( $body->blank_updates_permitted ); $self->system_user( $body->comment_user ); $self->update_comments( $o, $body ); } @@ -183,6 +185,8 @@ sub comment_text_for_request { return $template->text; } + return "" if $self->blank_updates_permitted; + print STDERR "Couldn't determine update text for $request->{update_id} (report " . $problem->id . ")\n"; return ""; } -- cgit v1.2.3