diff options
author | Struan Donald <struan@exo.org.uk> | 2012-12-18 12:40:00 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2012-12-18 12:40:00 +0000 |
commit | 6be9cff9ac5c5749b379e2fa7ac57e1e3e5d3146 (patch) | |
tree | 7b1bf6dc601d6af562478fc57f447d32bb16429b | |
parent | 2428ba9316e73bb3ec6ba58975545b438a8c4b83 (diff) |
In cases where we have two tier councils the TESTING_COUNCILS
mechanism could get confused as the council entry in the
problem table did not match one of the entries in TESTING_COUNCILS.
This code fixes that and should handle any combination of councils
in that field
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 27 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport.pm | 7 |
2 files changed, 33 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index bb826a5ca..aa123496e 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -363,8 +363,33 @@ sub send_reports { if (mySociety::Config::get('STAGING_SITE')) { # on a staging server send emails to ourselves rather than the councils + # however, we can configure a list of councils that we use non email + # delivery, e.g. Open311, for testing purposes. For those we want to + # send using the non email method and for everyone else we want to use + # email my @testing_councils = split( '\|', mySociety::Config::get('TESTING_COUNCILS') ); - unless ( grep { $row->council eq $_ } @testing_councils ) { + + # we only care about non missing councils so we get the missing ones + # and then essentially throw them away as we're not going to have + # configured them to do anything. + my %councils = map { $_ => 1 } @{ $row->councils }; + + # We now take the councils that we have contact details for and if any of them + # are in the list of testing councils we look a bit harder otherwise we throw + # away all the non email delivery methods + if ( grep { $councils{ $_ } } @testing_councils ) { + my %tc = map { $_ => 1 } @testing_councils; + my @non_matching = grep { !$tc{$_} } keys %councils; + for my $sender ( keys %reporters ) { + next if $sender =~ /FixMyStreet::SendReport::(Email|NI)/; + for my $council ( @non_matching ) { + $reporters{$sender}->delete_council( $council ); + } + } + if ( @non_matching ) { + $reporters{'FixMyStreet::SendReport::Email'} = FixMyStreet::SendReport::Email->new(); + } + } else { %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|NI)/ } keys %reporters; unless (%reporters) { %reporters = ( 'FixMyStreet::SendReport::Email' => FixMyStreet::SendReport::Email->new() ); diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm index 9ba507862..f679d826e 100644 --- a/perllib/FixMyStreet/SendReport.pm +++ b/perllib/FixMyStreet/SendReport.pm @@ -44,5 +44,12 @@ sub add_council { $self->councils->{ $council } = { info => $info, config => $config }; } +sub delete_council { + my $self = shift; + my $council = shift; + + delete $self->councils->{$council}; +} + 1; |