diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm | 17 | ||||
-rw-r--r-- | perllib/Open311.pm | 13 | ||||
-rw-r--r-- | perllib/Open311/GetServiceRequestUpdates.pm | 32 |
3 files changed, 41 insertions, 21 deletions
diff --git a/perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm b/perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm index 31876d83d..03bc511a0 100644 --- a/perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm +++ b/perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm @@ -137,7 +137,7 @@ sub close_problems { my $problems = shift; while (my $problem = $problems->next) { my $timestamp = \'current_timestamp'; - $problem->add_to_comments( { + my $comment = $problem->add_to_comments( { text => '', created => $timestamp, confirmed => $timestamp, @@ -150,5 +150,20 @@ sub close_problems { extra => { is_superuser => 1 }, } ); $problem->update({ state => 'closed', send_questionnaire => 0 }); + + # Stop any alerts being sent out about this closure. + my @alerts = FixMyStreet::DB->resultset('Alert')->search( { + alert_type => 'new_updates', + parameter => $problem->id, + confirmed => 1, + } ); + + for my $alert (@alerts) { + my $alerts_sent = FixMyStreet::DB->resultset('AlertSent')->find_or_create( { + alert_id => $alert->id, + parameter => $comment->id, + } ); + } + } } diff --git a/perllib/Open311.pm b/perllib/Open311.pm index 577de31ea..a65e19fa6 100644 --- a/perllib/Open311.pm +++ b/perllib/Open311.pm @@ -257,7 +257,7 @@ sub get_service_request_updates { my $end_date = shift; my $params = { - api_key => $self->api_key, + api_key => $self->api_key || '', }; if ( $start_date || $end_date ) { @@ -420,9 +420,12 @@ sub _get { $params->{ jurisdiction_id } = $self->jurisdiction if $self->jurisdiction; $uri->path( $uri->path . $path ); + my $base_uri = $uri->clone; $uri->query_form( $params ); - $self->debug_details( $self->debug_details . "\nrequest:" . $uri->as_string ); + my $debug_request = "GET " . $base_uri->as_string . "\n\n"; + $debug_request .= join("\n", map { "$_: $params->{$_}" } keys %$params); + $self->debug_details( $self->debug_details . $debug_request ); my $content; if ( $self->test_mode ) { @@ -464,11 +467,13 @@ sub _post { $params->{jurisdiction_id} = $self->jurisdiction if $self->jurisdiction; - $params->{api_key} = $self->api_key + $params->{api_key} = ($self->api_key || '') if $self->api_key; my $req = POST $uri->as_string, $params; - $self->debug_details( $self->debug_details . "\nrequest:" . $req->as_string ); + my $debug_request = $req->method . ' ' . $uri->as_string . "\n\n"; + $debug_request .= join("\n", map { "$_: $params->{$_}" } keys %$params); + $self->debug_details( $self->debug_details . $debug_request ); my $ua = LWP::UserAgent->new(); my $res; diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index cee1a629f..b3b165d27 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -138,22 +138,22 @@ sub update_comments { $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 - # tricky to determine the right thing to do. - # Allow the same time in case report/update created at same time (in external system) - if ( $comment->created >= $p->lastupdate ) { - # 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 && - # For Oxfordshire, don't allow changes back to Open from other open states - !( $body->areas->{$AREA_ID_OXFORDSHIRE} && $state eq 'confirmed' && $p->is_open ) && - # Don't let it change between the (same in the front end) fixed states - !( $p->is_fixed && FixMyStreet::DB::Result::Problem->fixed_states()->{$state} ) ) { - if ($p->is_visible) { - $p->state($state); - } - $comment->problem_state($state); + # don't update state unless it's an allowed state + if ( FixMyStreet::DB::Result::Problem->visible_states()->{$state} && + # For Oxfordshire, don't allow changes back to Open from other open states + !( $body->areas->{$AREA_ID_OXFORDSHIRE} && $state eq 'confirmed' && $p->is_open ) && + # Don't let it change between the (same in the front end) fixed states + !( $p->is_fixed && FixMyStreet::DB::Result::Problem->fixed_states()->{$state} ) ) { + + $comment->problem_state($state); + + # if the comment is older than the last update do not + # change the status of the problem as it's tricky to + # determine the right thing to do. Allow the same time in + # case report/update created at same time (in external + # system). Only do this if the report is currently visible. + if ( $comment->created >= $p->lastupdate && $p->state ne $state && $p->is_visible ) { + $p->state($state); } } |