diff options
author | Struan Donald <struan@exo.org.uk> | 2012-04-04 17:49:01 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2012-04-04 17:49:01 +0100 |
commit | 1abeb30e2c2d707834708b4d65b9bcf98e4bb084 (patch) | |
tree | 0978acf6e1ec1f08fde8fa3ceb0a171003765888 | |
parent | 70d59a30b5c2c59b1a3380cd2ab039931abaa158 (diff) |
implement skipping sending at adding council level and not at
the sending level
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 34 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 16 |
3 files changed, 37 insertions, 18 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 9e4c63902..a9469dc0a 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -250,9 +250,6 @@ sub send_reports { next; } - my $send_email = 0; - my $send_web = 0; - # Template variables for the email my $email_base_url = $cobrand->base_url_for_emails($row->cobrand_data); my %h = map { $_ => $row->$_ } qw/id title detail name category latitude longitude used_map/; @@ -291,7 +288,7 @@ sub send_reports { } my %reporters = (); - my (@to, @recips, $template, $areas_info ); + my (@to, @recips, $template, $areas_info, $sender_count ); if ($site eq 'emptyhomes') { my $council = $row->council; @@ -313,15 +310,20 @@ sub send_reports { foreach my $council (@councils) { my $name = $areas_info->{$council}->{name}; - push @dear, $name; + my $sender = $cobrand->get_council_sender( $council, $areas_info->{$council} ); $sender = "FixMyStreet::SendReport::$sender"; + if ( ! exists $senders->{ $sender } ) { warn "No such sender [ $sender ] for council $name ( $council )"; next; } - $reporters{ $sender } = $sender->new() unless $reporters{$sender}; - $reporters{ $sender }->add_council( $council, $name ); + $reporters{ $sender } ||= $sender->new(); + + unless ( $reporters{ $sender }->should_skip( $row ) ) { + push @dear, $name; + $reporters{ $sender }->add_council( $council, $name ); + } } $template = 'submit.txt'; @@ -355,19 +357,23 @@ sub send_reports { . " ]\n\n"; } + $sender_count = scalar @dear; } - unless ($send_email || $send_web || keys %reporters ) { + unless ( keys %reporters ) { die 'Report not going anywhere for ID ' . $row->id . '!'; } + next unless $sender_count; + if (mySociety::Config::get('STAGING_SITE')) { # on a staging server send emails to ourselves rather than the councils - $send_web = 0; - $send_email = 1; - %reporters = ( - 'FixMyStreet::SendReport::Email' => $reporters{ 'FixMyStreet::SendReport::Email' } - ); + my @testing_councils = split( '\|', mySociety::Config::get('TESTING_COUNCILS') ); + unless ( grep { $row->council eq $_ } @testing_councils ) { + %reporters = ( + 'FixMyStreet::SendReport::Email' => $reporters{ 'FixMyStreet::SendReport::Email' } + ); + } } # Multiply results together, so one success counts as a success. @@ -387,7 +393,7 @@ sub send_reports { } else { my @errors; for my $sender ( keys %reporters ) { - unless ( $reporters{ $sender }->sucess ) { + unless ( $reporters{ $sender }->success ) { push @errors, $reporters{ $sender }->error; } } diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm index e3b0b389c..426e8eefe 100644 --- a/perllib/FixMyStreet/SendReport.pm +++ b/perllib/FixMyStreet/SendReport.pm @@ -12,6 +12,11 @@ has 'to' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } ); has 'success' => ( is => 'rw', isa => 'Bool', default => 0 ); has 'error' => ( is => 'rw', isa => 'Str', default => '' ); + +sub should_skip { + return 0; +} + sub get_senders { my $self = shift; diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index 56138b75b..56c4aa381 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -9,6 +9,17 @@ use FixMyStreet::App; use mySociety::Config; use Open311; +sub should_skip { + my $self = shift; + my $row = shift; + + if ( $row->send_fail_count > 0 ) { + if ( bromley_retry_timeout($row) ) { + return 1; + } + } +} + sub send { return if mySociety::Config::get('STAGING_SITE'); my $self = shift; @@ -17,14 +28,11 @@ sub send { my $result = -1; foreach my $council ( keys %{ $self->councils } ) { - my $conf = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $self->councils->{ $council }, endpoint => { '!=', '' } } )->first; + my $conf = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $council, endpoint => { '!=', '' } } )->first; #print 'posting to end point for ' . $conf->area_id . "\n" if $verbose; # Extra bromley fields if ( $row->council =~ /2482/ ) { - if ( $row->send_fail_count > 0 ) { - next if bromley_retry_timeout( $row ); - } my $extra = $row->extra; push @$extra, { name => 'northing', value => $h->{northing} }; |