diff options
Diffstat (limited to 'bin/send-reports')
-rwxr-xr-x | bin/send-reports | 75 |
1 files changed, 57 insertions, 18 deletions
diff --git a/bin/send-reports b/bin/send-reports index 16f6bd8c0..7ccdf1dc4 100755 --- a/bin/send-reports +++ b/bin/send-reports @@ -30,6 +30,17 @@ use mySociety::Web qw(ent); use Open311; +# specific council numbers +use constant COUNCIL_ID_EAST_HANTS => 2330; + +use constant MAX_LINE_LENGTH => 132; + +# send_method config values found in by-area config data, for selecting to appropriate method +use constant SEND_METHOD_EMAIL => 'email'; +use constant SEND_METHOD_OPEN311 => 'open311'; +use constant SEND_METHOD_EAST_HANTS => 'easthants'; +use constant SEND_METHOD_LONDON => 'london'; + # Set up site, language etc. my ($verbose, $nomail) = CronFns::options(); my $base_url = mySociety::Config::get('BASE_URL'); @@ -56,8 +67,10 @@ while (my $row = $unsent->next) { next; } - my $send_email = 0; - my $send_web = 0; + # Due to multiple councils, it's possible to want to send both by email *and* another method + # NB: might need to revist this if multiple councils have custom send methods + my $send_email = 0; + my $send_method = 0; # Template variables for the email my $email_base_url = $cobrand->base_url_for_emails($row->cobrand_data); @@ -118,6 +131,7 @@ while (my $row = $unsent->next) { push @to, [ $council_email, $name ]; @recips = ($council_email); + $send_method = 0; $send_email = 1; $template = Utils::read_file("$FindBin::Bin/../templates/email/emptyhomes/" . $row->lang . "/submit.txt"); @@ -133,15 +147,37 @@ while (my $row = $unsent->next) { foreach my $council (@councils) { my $name = $areas_info->{$council}->{name}; push @dear, $name; - if ($council == 2330) { # E. Hants have a web service - $send_web = 'easthants'; + + # look in the DB to determine if there is a special handler for this council (e.g., open311, or custom) + my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $council} )->first; + $send_method = $council_config->send_method if $council_config; + if ($council == COUNCIL_ID_EAST_HANTS) { # E. Hants have a web service + $send_method = SEND_METHOD_EAST_HANTS; # TODO: delete? should be in the db $h{category} = 'Customer Services' if $h{category} eq 'Other'; - } elsif ( my $endpoint = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $council, endpoint => { '!=', '' } } )->first ) { - push @open311_councils, $endpoint; - $send_web = 'open311'; - } elsif ($areas_info->{$council}->{type} eq 'LBO') { # London - $send_web = 'london'; - } else { + } + + # if council lookup provided no explicit send_method, maybe there's some other criterion for setting it: + if (! $send_method) { + if ($areas_info->{$council}->{type} eq 'LBO') { # London + $send_method = SEND_METHOD_LONDON; + } + } + $send_email = 1 unless $send_method; # default to email if nothing explicit was provided + + # currently: open311 without an endpoint is useless, so check the endpoint is set + if ($send_method eq SEND_METHOD_OPEN311) { + if ($council_config->endpoint) { + if ($send_method eq SEND_METHOD_OPEN311) { + push @open311_councils, $council_config; + } + } else { + print "Warning: no endpoint specified in config data for council=$council (will try email instead)\n"; + $send_method = 0; + $send_email = 1; + } + } + + if ($send_email) { my $contact = FixMyStreet::App->model("DB::Contact")->find( { deleted => 0, area_id => $council, @@ -160,7 +196,6 @@ while (my $row = $unsent->next) { } push @to, [ $council_email, $name ]; $recips{$council_email} = 1; - $send_email = 1; } } @recips = keys %recips; @@ -199,15 +234,19 @@ while (my $row = $unsent->next) { } - unless ($send_email || $send_web) { + unless ($send_method) { die 'Report not going anywhere for ID ' . $row->id . '!'; } if (mySociety::Config::get('STAGING_SITE')) { # on a staging server send emails to ourselves rather than the councils - @recips = ( mySociety::Config::get('CONTACT_EMAIL') ); - $send_web = 0; - $send_email = 1; + # ...webservice calls will only go through if explictly allowed here: + my @testing_councils = (); + unless (grep {$row->council eq $_} @testing_councils) { + @recips = ( mySociety::Config::get('CONTACT_EMAIL') ); + $send_method = 0; + $send_email = 1; + } } elsif ($site eq 'emptyhomes') { my $council = $row->council; my $country = $areas_info->{$council}->{country}; @@ -243,17 +282,17 @@ while (my $row = $unsent->next) { ); } - if ($send_web eq 'easthants') { + if ($send_method eq SEND_METHOD_EAST_HANTS) { $h{message} = construct_easthants_message(%h); if (!$nomail) { $result *= post_easthants_message(%h); } - } elsif ($send_web eq 'london') { + } elsif ($send_method eq SEND_METHOD_LONDON) { $h{message} = construct_london_message(%h); if (!$nomail) { $result *= post_london_report( $row, %h ); } - } elsif ($send_web eq 'open311') { + } elsif ($send_method eq SEND_METHOD_OPEN311) { foreach my $conf ( @open311_councils ) { print 'posting to end point for ' . $conf->area_id . "\n" if $verbose; |