diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/open311-populate-service-list | 8 | ||||
-rw-r--r-- | bin/open311-update-reports | 21 | ||||
-rwxr-xr-x | bin/send-comments | 26 | ||||
-rwxr-xr-x | bin/update-all-reports | 37 | ||||
-rwxr-xr-x | bin/zurich-overdue-alert | 83 |
5 files changed, 122 insertions, 53 deletions
diff --git a/bin/open311-populate-service-list b/bin/open311-populate-service-list index dc8fa3f7b..be1ace3b9 100755 --- a/bin/open311-populate-service-list +++ b/bin/open311-populate-service-list @@ -14,13 +14,13 @@ my ($opt, $usage) = describe_options( ); print($usage->text), exit if $opt->help; -my $council_list = FixMyStreet::App->model('DB::Open311conf')->search( { - area_id => { '!=', 2237 }, # XXX Until Oxfordshire does do so +my $bodies = FixMyStreet::App->model('DB::Body')->search( { + id => { '!=', 2237 }, # XXX Until Oxfordshire does do so send_method => 'Open311' } ); my $verbose = 0; $verbose = 1 if $opt->warn; $verbose = 2 if $opt->verbose; -my $p = Open311::PopulateServiceList->new( council_list => $council_list, verbose => $verbose ); +my $p = Open311::PopulateServiceList->new( bodies => $bodies, verbose => $verbose ); -$p->process_councils; +$p->process_bodies; diff --git a/bin/open311-update-reports b/bin/open311-update-reports deleted file mode 100644 index 41c9c4546..000000000 --- a/bin/open311-update-reports +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use Open311::GetUpdates; -use FixMyStreet::App; - -# FIXME - make this configurable and/or better -my $system_user = FixMyStreet::App->model('DB::User')->find_or_create( - { - email => FixMyStreet::App->config->{'CONTACT_EMAIL'}, - name => 'System User', - } -); - -my $council_list = FixMyStreet::App->model('DB::Open311conf'); - -my $update = Open311::GetUpdates->new( - council_list => $council_list, - system_user => $system_user -)->get_updates; diff --git a/bin/send-comments b/bin/send-comments index d2b057996..4f654fe20 100755 --- a/bin/send-comments +++ b/bin/send-comments @@ -1,7 +1,7 @@ #!/usr/bin/env perl # send-comments: -# Send comments/updates on reports to councils +# Send comments/updates on reports to bodies # In Open311 parlance these are 'service request udpates' 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 @@ -40,16 +40,16 @@ 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 $council->area_id == COUNCIL_ID_OXFORDSHIRE; + next if $body->areas->{COUNCIL_ID_OXFORDSHIRE}; my $use_extended = 0; my $comments = FixMyStreet::App->model('DB::Comment')->search( { @@ -59,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', }, { @@ -67,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'; @@ -97,7 +97,7 @@ while ( my $council = $councils->next ) { # 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 ); + my $sender = $cobrand->get_body_sender( $body, $comment->problem->category ); my $config = $sender->{config}; $o = Open311->new( endpoint => $config->endpoint, @@ -111,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 = {}; diff --git a/bin/update-all-reports b/bin/update-all-reports index b8e47f2e7..d0146dd47 100755 --- a/bin/update-all-reports +++ b/bin/update-all-reports @@ -18,46 +18,53 @@ use List::MoreUtils qw(zip); my $fourweeks = 4*7*24*60*60; +# Age problems from when they're confirmed, except on Zurich +# where they appear as soon as they're created. +my $age_column = 'confirmed'; +if ( FixMyStreet->config('BASE_URL') =~ /zurich/ ) { + $age_column = 'created'; +} + my $problems = FixMyStreet::App->model("DB::Problem")->search( { state => [ FixMyStreet::DB::Result::Problem->visible_states() ], }, { columns => [ - 'id', 'council', 'state', 'areas', + 'id', 'bodies_str', 'state', 'areas', { duration => { extract => "epoch from current_timestamp-lastupdate" } }, - { age => { extract => "epoch from current_timestamp-confirmed" } }, + { age => { extract => "epoch from current_timestamp-$age_column" } }, ] } ); $problems = $problems->cursor; # Raw DB cursor for speed my ( %fixed, %open ); -my @cols = ( 'id', 'council', 'state', 'areas', 'duration', 'age' ); +my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'duration', 'age' ); while ( my @problem = $problems->next ) { my %problem = zip @cols, @problem; - my @areas; - if ( !$problem{council} ) { - # Problem was not sent to any council, add to all areas - @areas = grep { $_ } split( /,/, $problem{areas} ); - $problem{councils} = 0; + my @bodies; + if ( !$problem{bodies_str} ) { + # Problem was not sent to any bodies, add to all areas + @bodies = grep { $_ } split( /,/, $problem{areas} ); + $problem{bodies} = 0; } else { - # Add to councils it was sent to - (my $council = $problem{council}) =~ s/\|.*$//; - @areas = split( /,/, $council ); - $problem{councils} = scalar @areas; + # Add to bodies it was sent to + (my $bodies = $problem{bodies_str}) =~ s/\|.*$//; + @bodies = split( /,/, $bodies ); + $problem{bodies} = scalar @bodies; } - foreach my $council ( @areas ) { + foreach my $body ( @bodies ) { my $duration_str = ( $problem{duration} > 2 * $fourweeks ) ? 'old' : 'new'; my $type = ( $problem{duration} > 2 * $fourweeks ) ? 'unknown' : ($problem{age} > $fourweeks ? 'older' : 'new'); if (FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}} || FixMyStreet::DB::Result::Problem->closed_states()->{$problem{state}}) { # Fixed problems are either old or new - $fixed{$council}{$duration_str}++; + $fixed{$body}{$duration_str}++; } else { # Open problems are either unknown, older, or new - $open{$council}{$type}++ if $problem{state} eq 'confirmed'; + $open{$body}{$type}++ if $problem{state} eq 'confirmed'; } } } diff --git a/bin/zurich-overdue-alert b/bin/zurich-overdue-alert new file mode 100755 index 000000000..aa9f6fe60 --- /dev/null +++ b/bin/zurich-overdue-alert @@ -0,0 +1,83 @@ +#!/usr/bin/env perl + +# zurich-overdue-alert: +# Send email alerts to administrators for overdue admin activities. +# +# Copyright (c) 2012 UK Citizens Online Democracy. All rights reserved. +# Email: matthew@mysociety.org. WWW: http://www.mysociety.org + +use strict; +use warnings; +require 5.8.0; + +use DateTime; +use CronFns; +use FixMyStreet::App; + +my ($verbose, $nomail) = CronFns::options(); + +# Only run on working days +my $now = DateTime->now(); +exit if FixMyStreet::Cobrand::Zurich::is_public_holiday($now) or FixMyStreet::Cobrand::Zurich::is_weekend($now); + +my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('zurich')->new(); +my %bodies = map { $_->id => $_ } FixMyStreet::App->model("DB::Body")->all; + +loop_through( 'alert-moderation-overdue.txt', 0, 1, [ 'unconfirmed', 'confirmed' ] ); +loop_through( 'alert-overdue.txt', 1, 5, 'in progress' ); + +sub loop_through { + my ( $template, $include_parent, $days, $states ) = @_; + + my $reports = FixMyStreet::App->model("DB::Problem")->search( { + state => $states, + whensent => { '<', FixMyStreet::Cobrand::Zurich::sub_days( $now, $days ) }, + bodies_str => { '!=', undef }, + } ); + + my %to_send = (); + while (my $row = $reports->next) { + $to_send{$row->bodies_str} .= '* ' . $row->id . ": '" . $row->title . "'\n\n"; + } + + my $template_path = FixMyStreet->path_to( "templates", "email", "zurich", $template )->stringify; + $template = Utils::read_file( $template_path ); + + foreach my $body_id (keys %to_send) { + send_alert( $template, $body_id, $to_send{$body_id}, $include_parent ); + } +} + +sub send_alert { + my ( $template, $body_id, $data, $include_parent ) = @_; + + my $body = $bodies{$body_id}; + my $body_email = $body->endpoint; + + my $h = { + data => $data, + admin_url => $cobrand->admin_base_url, + }; + + my $env_to = [ $body_email ]; + my $to = [ [ $body_email, $body->name ] ]; + if ( $include_parent ) { + my $parent = $body->parent; + my $parent_email = $parent->endpoint; + push @$env_to, $parent_email; + push @$to, [ $parent_email, $parent->name ]; + } + + my $result = FixMyStreet::App->send_email_cron( + { + _template_ => $template, + _parameters_ => $h, + To => $to, + From => [ FixMyStreet->config('CONTACT_EMAIL'), FixMyStreet->config('CONTACT_NAME') ], + }, + FixMyStreet->config('CONTACT_EMAIL'), + $env_to, + $nomail + ); +} + |