aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/send-reports12
-rw-r--r--perllib/FixMyStreet/Cobrand/Bexley.pm9
-rw-r--r--perllib/FixMyStreet/Queue/Item/Report.pm43
-rw-r--r--perllib/FixMyStreet/Script/Reports.pm82
-rw-r--r--perllib/FixMyStreet/SendReport.pm15
-rw-r--r--perllib/FixMyStreet/SendReport/Noop.pm5
-rw-r--r--t/cobrand/bexley.t10
-rw-r--r--t/cobrand/zurich.t3
-rw-r--r--t/cobrand/zurich_attachments.txt2
9 files changed, 95 insertions, 86 deletions
diff --git a/bin/send-reports b/bin/send-reports
index 81be691e7..9651c271c 100755
--- a/bin/send-reports
+++ b/bin/send-reports
@@ -17,6 +17,7 @@ BEGIN {
require "$d/../setenv.pl";
}
+use Getopt::Long::Descriptive;
use CronFns;
use FixMyStreet;
@@ -25,4 +26,13 @@ use FixMyStreet::Script::Reports;
my $site = CronFns::site(FixMyStreet->config('BASE_URL'));
CronFns::language($site);
-FixMyStreet::Script::Reports::send();
+my ($opts, $usage) = describe_options(
+ '%c %o',
+ ['verbose|v', 'more verbose output'],
+ ['nomail', 'do not send any email, print instead'],
+ ['debug', 'always try and send reports (no back-off skipping)'],
+ ['help|h', "print usage message and exit" ],
+);
+$usage->die if $opts->help;
+
+FixMyStreet::Script::Reports::send($opts->verbose, $opts->nomail, $opts->debug);
diff --git a/perllib/FixMyStreet/Cobrand/Bexley.pm b/perllib/FixMyStreet/Cobrand/Bexley.pm
index 74a7b5032..481926e72 100644
--- a/perllib/FixMyStreet/Cobrand/Bexley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bexley.pm
@@ -172,6 +172,12 @@ sub open311_post_send {
$p1_email = 1;
$outofhours_email = 1;
}
+ } elsif ($row->category eq 'Street cleaning and litter') {
+ my $reportType = $row->get_extra_field_value('reportType') || '';
+ if ($reportType eq 'Oil spillage' || $dangerous eq 'Yes') {
+ $p1_email = 1;
+ $outofhours_email = 1;
+ }
} elsif ($row->category eq 'Damage to kerb' || $row->category eq 'Damaged road' || $row->category eq 'Damaged pavement') {
$p1_email = 1;
$outofhours_email = 1;
@@ -181,7 +187,8 @@ sub open311_post_send {
}
my @to;
- push @to, email_list($emails->{p1}, 'Bexley P1 email') if $p1_email;
+ my $p1_email_to_use = ($contact->email =~ /^Confirm/) ? $emails->{p1confirm} : $emails->{p1};
+ push @to, email_list($p1_email_to_use, 'Bexley P1 email') if $p1_email;
push @to, email_list($emails->{lighting}, 'FixMyStreet Bexley Street Lighting') if $lighting{$row->category};
push @to, email_list($emails->{flooding}, 'FixMyStreet Bexley Flooding') if $flooding{$row->category};
push @to, email_list($emails->{outofhours}, 'Bexley out of hours') if $outofhours_email && _is_out_of_hours();
diff --git a/perllib/FixMyStreet/Queue/Item/Report.pm b/perllib/FixMyStreet/Queue/Item/Report.pm
index 1ef640fc4..4d0d62752 100644
--- a/perllib/FixMyStreet/Queue/Item/Report.pm
+++ b/perllib/FixMyStreet/Queue/Item/Report.pm
@@ -41,19 +41,17 @@ has h => ( is => 'rwp' );
has reporters => ( is => 'rwp' );
# Run parameters
+has verbose => ( is => 'ro');
has nomail => ( is => 'ro' );
-has debug_mode => ( is => 'ro' );
sub process {
my $self = shift;
FixMyStreet::DB->schema->cobrand($self->cobrand);
- if ($self->debug_mode) {
- $self->manager->debug_unsent_count++;
- print "\n";
+ if ($self->verbose) {
my $row = $self->report;
- $self->debug_print("state=" . $row->state . ", bodies_str=" . $row->bodies_str . ($row->cobrand? ", cobrand=" . $row->cobrand : ""), $row->id);
+ $self->log("state=" . $row->state . ", bodies_str=" . $row->bodies_str . ($row->cobrand? ", cobrand=" . $row->cobrand : ""));
}
# Cobranded and non-cobranded messages can share a database. In this case, the conf file
@@ -61,7 +59,7 @@ sub process {
# more than once if there are multiple vhosts running off the same database. The email_host
# call checks if this is the host that sends mail for this cobrand.
if (! $self->cobrand->email_host()) {
- $self->debug_print("skipping because this host does not send reports for cobrand " . $self->cobrand->moniker, $self->report->id);
+ $self->log("skipping because this host does not send reports for cobrand " . $self->cobrand->moniker);
return;
}
@@ -79,11 +77,11 @@ sub _check_abuse {
my $self = shift;
if ( $self->report->is_from_abuser) {
$self->report->update( { state => 'hidden' } );
- $self->debug_print("hiding because its sender is flagged as an abuser", $self->report->id);
+ $self->log("hiding because its sender is flagged as an abuser");
return;
} elsif ( $self->report->title =~ /app store test/i ) {
$self->report->update( { state => 'hidden' } );
- $self->debug_print("hiding because it is an app store test message", $self->report->id);
+ $self->log("hiding because it is an app store test message");
return;
}
return 1;
@@ -173,33 +171,25 @@ sub _create_reporters {
my @dear;
my %reporters = ();
- my $skip = 0;
while (my $body = $bodies->next) {
my $sender_info = $self->cobrand->get_body_sender( $body, $row->category );
my $sender = "FixMyStreet::SendReport::" . $sender_info->{method};
if ( ! exists $self->senders->{ $sender } ) {
- warn sprintf "No such sender [ $sender ] for body %s ( %d )", $body->name, $body->id;
+ $self->log(sprintf "No such sender [ $sender ] for body %s ( %d )", $body->name, $body->id);
next;
}
$reporters{ $sender } ||= $sender->new();
- if ( $reporters{ $sender }->should_skip( $row, $self->debug_mode ) ) {
- $skip = 1;
- $self->debug_print("skipped by sender " . $sender_info->{method} . " (might be due to previous failed attempts?)", $row->id);
- } else {
- $self->debug_print("OK, adding recipient body " . $body->id . ":" . $body->name . ", " . $sender_info->{method}, $row->id);
- push @dear, $body->name;
- $reporters{ $sender }->add_body( $body, $sender_info->{config} );
- }
+ $self->log("OK, adding recipient body " . $body->id . ":" . $body->name . ", " . $sender_info->{method});
+ push @dear, $body->name;
+ $reporters{ $sender }->add_body( $body, $sender_info->{config} );
}
unless ( keys %reporters ) {
die 'Report not going anywhere for ID ' . $row->id . '!';
}
- return if $skip;
-
my $h = $self->h;
$h->{bodies_name} = join(_(' and '), @dear);
if ($h->{category} eq _('Other')) {
@@ -228,7 +218,7 @@ sub _send {
my $result = -1;
for my $sender ( keys %{$self->reporters} ) {
- $self->debug_print("sending using " . $sender, $self->report->id);
+ $self->log("sending using " . $sender);
$sender = $self->reporters->{$sender};
my $res = $sender->send( $self->report, $self->h );
$result *= $res;
@@ -261,7 +251,7 @@ sub _post_send {
$self->h->{sent_confirm_id_ref} = $self->report->$send_confirmation_email;
$self->_send_report_sent_email;
}
- $self->debug_print("send successful: OK", $self->report->id);
+ $self->log("send successful: OK");
} else {
my @errors;
for my $sender ( keys %{$self->reporters} ) {
@@ -270,7 +260,7 @@ sub _post_send {
}
}
$self->report->update_send_failed( join( '|', @errors ) );
- $self->debug_print("send FAILED: " . join( '|', @errors ), $self->report->id);
+ $self->log("send FAILED: " . join( '|', @errors ));
}
}
@@ -297,9 +287,10 @@ sub _send_report_sent_email {
);
}
-sub debug_print {
- my $self = shift;
- $self->manager->debug_print(@_);
+sub log {
+ my ($self, $msg) = @_;
+ return unless $self->verbose;
+ STDERR->print("[fmsd] [" . $self->report->id . "] $msg\n");
}
1;
diff --git a/perllib/FixMyStreet/Script/Reports.pm b/perllib/FixMyStreet/Script/Reports.pm
index 2b558fdc0..3e9b2d693 100644
--- a/perllib/FixMyStreet/Script/Reports.pm
+++ b/perllib/FixMyStreet/Script/Reports.pm
@@ -7,69 +7,89 @@ use FixMyStreet::DB;
use FixMyStreet::Queue::Item::Report;
has verbose => ( is => 'ro' );
-has debug_mode => ( is => 'ro' );
-has debug_unsent_count => ( is => 'rw', default => 0 );
has unconfirmed_data => ( is => 'ro', default => sub { {} } );
has test_data => ( is => 'ro', default => sub { {} } );
# Static method, used by send-reports cron script and tests.
# Creates a manager object from provided data and processes it.
-sub send(;$) {
- my ($site_override) = @_;
- my $rs = FixMyStreet::DB->resultset('Problem');
-
- # Set up site, language etc.
- my ($verbose, $nomail, $debug_mode) = CronFns::options();
+sub send {
+ my ($verbose, $nomail, $debug) = @_;
my $manager = __PACKAGE__->new(
verbose => $verbose,
- debug_mode => $debug_mode,
);
- my $base_url = FixMyStreet->config('BASE_URL');
- my $site = $site_override || CronFns::site($base_url);
-
+ my $site = CronFns::site(FixMyStreet->config('BASE_URL'));
my $states = [ FixMyStreet::DB::Result::Problem::open_states() ];
$states = [ 'submitted', 'confirmed', 'in progress', 'feedback pending', 'external', 'wish' ] if $site eq 'zurich';
- my $unsent = $rs->search( {
+
+ # Devolved Noop categories (unlikely to be any, but still)
+ my @noop_params;
+ my $noop_cats = FixMyStreet::DB->resultset('Contact')->search({
+ 'body.can_be_devolved' => 1,
+ 'me.send_method' => 'Noop'
+ }, { join => 'body' });
+ while (my $cat = $noop_cats->next) {
+ push @noop_params, [
+ \[ "NOT regexp_split_to_array(bodies_str, ',') && ?", [ {} => [ $cat->body_id ] ] ],
+ category => { '!=' => $cat->category } ];
+ }
+
+ # Noop bodies
+ my @noop_bodies = FixMyStreet::DB->resultset('Body')->search({ send_method => 'Noop' })->all;
+ @noop_bodies = map { $_->id } @noop_bodies;
+ push @noop_params, \[ "NOT regexp_split_to_array(bodies_str, ',') && ?", [ {} => \@noop_bodies ] ];
+
+ my $params = {
state => $states,
whensent => undef,
bodies_str => { '!=', undef },
- } );
+ -and => \@noop_params,
+ };
+ if (!$debug) {
+ $params->{'-or'} = [
+ send_fail_count => 0,
+ { send_fail_count => 1, send_fail_timestamp => { '<', \"current_timestamp - '5 minutes'::interval" } },
+ { send_fail_timestamp => { '<', \"current_timestamp - '30 minutes'::interval" } },
+ ];
+ }
+
+ my $unsent = FixMyStreet::DB->resultset('Problem')->search($params);
- $manager->debug_print("starting to loop through unsent problem reports...");
+ $manager->log("starting to loop through unsent problem reports...");
+ my $unsent_count = 0;
while (my $row = $unsent->next) {
+ $unsent_count++;
my $item = FixMyStreet::Queue::Item::Report->new(
report => $row,
manager => $manager,
+ verbose => $verbose,
nomail => $nomail,
- debug_mode => $debug_mode,
);
$item->process;
}
- $manager->end_debug_line;
+ $manager->end_line($unsent_count);
$manager->end_summary_unconfirmed;
return $manager->test_data;
}
-sub end_debug_line {
- my $self = shift;
- return unless $self->debug_mode;
+sub end_line {
+ my ($self, $unsent_count) = @_;
+ return unless $self->verbose;
- print "\n";
- if ($self->debug_unsent_count) {
- $self->debug_print("processed all unsent reports (total: " . $self->debug_unsent_count . ")");
+ if ($unsent_count) {
+ $self->log("processed all unsent reports (total: $unsent_count)");
} else {
- $self->debug_print("no unsent reports were found (must have whensent=null and suitable bodies_str & state) -- nothing to send");
+ $self->log("no unsent reports were found (must have whensent=null and suitable bodies_str & state) -- nothing to send");
}
}
sub end_summary_unconfirmed {
my $self = shift;
- return unless $self->verbose || $self->debug_mode;
+ return unless $self->verbose;
my %unconfirmed_data = %{$self->unconfirmed_data};
print "Council email addresses that need checking:\n" if keys %unconfirmed_data;
@@ -102,14 +122,10 @@ sub end_summary_failures {
}
}
-sub debug_print {
- my $self = shift;
- return unless $self->debug_mode;
-
- my $msg = shift;
- my $id = shift || '';
- $id = "report $id: " if $id;
- print "[] $id$msg\n";
+sub log {
+ my ($self, $msg) = @_;
+ return unless $self->verbose;
+ STDERR->print("[fmsd] $msg\n");
}
1;
diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm
index 0d8bea304..c08a7ddbe 100644
--- a/perllib/FixMyStreet/SendReport.pm
+++ b/perllib/FixMyStreet/SendReport.pm
@@ -18,21 +18,6 @@ has 'error' => ( is => 'rw', isa => Str, default => '' );
has 'unconfirmed_data' => ( 'is' => 'rw', isa => HashRef, default => sub { {} } );
-sub should_skip {
- my $self = shift;
- my $row = shift;
- my $debug = shift;
-
- return 0 unless $row->send_fail_count;
- return 0 if $debug;
-
- my $now = DateTime->now( time_zone => FixMyStreet->local_time_zone );
- my $diff = $now - $row->send_fail_timestamp;
-
- my $backoff = $row->send_fail_count > 1 ? 30 : 5;
- return $diff->in_units( 'minutes' ) < $backoff;
-}
-
sub get_senders {
my $self = shift;
diff --git a/perllib/FixMyStreet/SendReport/Noop.pm b/perllib/FixMyStreet/SendReport/Noop.pm
index 60edda373..933291b7c 100644
--- a/perllib/FixMyStreet/SendReport/Noop.pm
+++ b/perllib/FixMyStreet/SendReport/Noop.pm
@@ -4,9 +4,4 @@ use Moo;
BEGIN { extends 'FixMyStreet::SendReport'; }
-# Always skip when using this method
-sub should_skip {
- return 1;
-}
-
1;
diff --git a/t/cobrand/bexley.t b/t/cobrand/bexley.t
index 55ee1278e..352e61389 100644
--- a/t/cobrand/bexley.t
+++ b/t/cobrand/bexley.t
@@ -34,13 +34,14 @@ my $mech = FixMyStreet::TestMech->new;
my $body = $mech->create_body_ok(2494, 'London Borough of Bexley', {
send_method => 'Open311', api_key => 'key', 'endpoint' => 'e', 'jurisdiction' => 'j' });
-$mech->create_contact_ok(body_id => $body->id, category => 'Abandoned and untaxed vehicles', email => "ABAN");
+$mech->create_contact_ok(body_id => $body->id, category => 'Abandoned and untaxed vehicles', email => "ConfirmABAN");
$mech->create_contact_ok(body_id => $body->id, category => 'Lamp post', email => "StreetLightingLAMP");
$mech->create_contact_ok(body_id => $body->id, category => 'Gulley covers', email => "GULL");
$mech->create_contact_ok(body_id => $body->id, category => 'Damaged road', email => "ROAD");
$mech->create_contact_ok(body_id => $body->id, category => 'Flooding in the road', email => "ConfirmFLOD");
$mech->create_contact_ok(body_id => $body->id, category => 'Flytipping', email => "UniformFLY");
$mech->create_contact_ok(body_id => $body->id, category => 'Dead animal', email => "ANIM");
+$mech->create_contact_ok(body_id => $body->id, category => 'Street cleaning and litter', email => "STREET");
my $category = $mech->create_contact_ok(body_id => $body->id, category => 'Something dangerous', email => "DANG");
$category->set_extra_metadata(group => 'Danger things');
$category->update;
@@ -51,6 +52,7 @@ FixMyStreet::override_config {
STAGING_FLAGS => { send_reports => 1, skip_checks => 0 },
COBRAND_FEATURES => { open311_email => { bexley => {
p1 => 'p1@bexley',
+ p1confirm => 'p1confirm@bexley',
lighting => 'thirdparty@notbexley.example.com,another@notbexley.example.com',
outofhours => 'outofhours@bexley,ooh2@bexley',
flooding => 'flooding@bexley',
@@ -71,15 +73,17 @@ FixMyStreet::override_config {
my $report;
foreach my $test (
- { category => 'Abandoned and untaxed vehicles', email => ['p1'], code => 'ABAN',
+ { category => 'Abandoned and untaxed vehicles', email => ['p1confirm'], code => 'ConfirmABAN',
extra => { 'name' => 'burnt', description => 'Was it burnt?', 'value' => 'Yes' } },
- { category => 'Abandoned and untaxed vehicles', code => 'ABAN',
+ { category => 'Abandoned and untaxed vehicles', code => 'ConfirmABAN',
extra => { 'name' => 'burnt', description => 'Was it burnt?', 'value' => 'No' } },
{ category => 'Dead animal', email => ['p1', 'outofhours', 'ooh2'], code => 'ANIM' },
{ category => 'Something dangerous', email => ['p1', 'outofhours', 'ooh2'], code => 'DANG',
extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'Yes' } },
{ category => 'Something dangerous', code => 'DANG',
extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'No' } },
+ { category => 'Street cleaning and litter', email => ['p1', 'outofhours', 'ooh2'], code => 'STREET',
+ extra => { 'name' => 'reportType', description => 'Type of report', 'value' => 'Oil spillage' } },
{ category => 'Gulley covers', email => ['p1', 'outofhours', 'ooh2'], code => 'GULL',
extra => { 'name' => 'reportType', description => 'Type of report', 'value' => 'Cover missing' } },
{ category => 'Gulley covers', code => 'GULL',
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
index 0a144de23..8c5acddca 100644
--- a/t/cobrand/zurich.t
+++ b/t/cobrand/zurich.t
@@ -31,7 +31,7 @@ my $sample_file = path(__FILE__)->parent->parent->child("app/controller/sample.j
ok $sample_file->exists, "sample file $sample_file exists";
sub send_reports_for_zurich {
- FixMyStreet::Script::Reports::send('zurich');
+ FixMyStreet::Script::Reports::send();
}
sub reset_report_state {
my ($report, $created) = @_;
@@ -50,6 +50,7 @@ sub reset_report_state {
my $UPLOAD_DIR = File::Temp->newdir();
FixMyStreet::override_config {
STAGING_FLAGS => { send_reports => 1 },
+ BASE_URL => 'https://www.zurich',
ALLOWED_COBRANDS => 'zurich',
MAPIT_URL => 'http://mapit.zurich/',
MAPIT_TYPES => [ 'O08' ],
diff --git a/t/cobrand/zurich_attachments.txt b/t/cobrand/zurich_attachments.txt
index 26b7eb8ca..e9b717618 100644
--- a/t/cobrand/zurich_attachments.txt
+++ b/t/cobrand/zurich_attachments.txt
@@ -12,7 +12,7 @@ Content-Transfer-Encoding: quoted-printable
Gr=C3=BCezi External Body,
-=C3=96ffentliche URL: http://www.example.org/report/REPORT_ID
+=C3=96ffentliche URL: https://www.zurich/report/REPORT_ID
Bei Fragen zu "Z=C3=BCri wie neu" wenden Sie sich bitte an =
gis-zentrum@zuerich.ch.=