diff options
Diffstat (limited to 'bin/send-comments')
-rwxr-xr-x | bin/send-comments | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/bin/send-comments b/bin/send-comments index 232521447..fc2ab42bd 100755 --- a/bin/send-comments +++ b/bin/send-comments @@ -1,8 +1,8 @@ #!/usr/bin/env perl # send-comments: -# Send comments/updates on reports to councils -# In Open311 parlance these are 'service request udpates' and are sent using +# Send comments/updates on reports to bodies +# In Open311 parlance these are 'service request updates' and are sent using # mySociety's proposed extension to the Open311 Georeport v2 spec: # https://github.com/mysociety/fixmystreet/wiki/Open311-FMS---Proposed-differences-to-Open311 # @@ -33,17 +33,24 @@ use constant SEND_FAIL_RETRIES_CUTOFF => 3; use constant SEND_METHOD_EMAIL => 'email'; use constant SEND_METHOD_OPEN311 => 'Open311'; +use constant COUNCIL_ID_OXFORDSHIRE => 2237; + # Set up site, language etc. my ($verbose, $nomail) = CronFns::options(); my $base_url = mySociety::Config::get('BASE_URL'); my $site = CronFns::site($base_url); -my $councils = FixMyStreet::App->model('DB::Open311Conf')->search( { +my $bodies = FixMyStreet::App->model('DB::Body')->search( { send_method => SEND_METHOD_OPEN311, send_comments => 1, } ); -while ( my $council = $councils->next ) { +while ( my $body = $bodies->next ) { + + # Oxfordshire (OCC) is special: + # we do *receive* service_request_updates (aka comments) for OCC, but we never *send* them, so skip this pass + next if $body->areas->{+COUNCIL_ID_OXFORDSHIRE}; + my $use_extended = 0; my $comments = FixMyStreet::App->model('DB::Comment')->search( { 'me.whensent' => undef, @@ -52,7 +59,7 @@ while ( my $council = $councils->next ) { 'me.confirmed' => { '!=' => undef }, 'problem.whensent' => { '!=' => undef }, 'problem.external_id' => { '!=' => undef }, - 'problem.council' => { -like => '%' . $council->area_id .'%' }, + 'problem.bodies_str' => { -like => '%' . $body->id . '%' }, 'problem.send_method_used' => 'Open311', }, { @@ -60,25 +67,25 @@ while ( my $council = $councils->next ) { } ); - if ( $council->area_id == 2482 ) { + if ( $body->areas->{2482} ) { $use_extended = 1; } my %open311_conf = ( - endpoint => $council->endpoint, - jurisdiction => $council->jurisdiction, - api_key => $council->api_key, + endpoint => $body->endpoint, + jurisdiction => $body->jurisdiction, + api_key => $body->api_key, use_extended_updates => $use_extended, ); - if ( $council->send_extended_statuses ) { + if ( $body->send_extended_statuses ) { $open311_conf{extended_statuses} = 1; } my $o = Open311->new( %open311_conf ); - if ( $council->area_id =~ /2482/ ) { + if ( $body->areas->{2482} ) { my $endpoints = $o->endpoints; $endpoints->{update} = 'update.xml'; $endpoints->{service_request_updates} = 'update.xml'; @@ -88,9 +95,9 @@ while ( my $council = $councils->next ) { while ( my $comment = $comments->next ) { my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($comment->cobrand)->new(); - # actually this should be OK for any devolved endpoint if original Open311->can_be_devolved, presumably - if ( $cobrand->moniker eq "fixmybarangay") { - my $sender = $cobrand->get_council_sender( $council->area_id, undef, $comment->problem->category ); + # TODO actually this should be OK for any devolved endpoint if original Open311->can_be_devolved, presumably + if ( 0 ) { # Check can_be_devolved and do this properly if set + my $sender = $cobrand->get_body_sender( $body, $comment->problem->category ); my $config = $sender->{config}; $o = Open311->new( endpoint => $config->endpoint, @@ -104,7 +111,7 @@ while ( my $council = $councils->next ) { next if bromley_retry_timeout( $comment ); } - if ( $council->area_id == 2482 ) { + if ( $body->areas->{2482} ) { my $extra = $comment->extra; if ( !$extra ) { $extra = {}; |