aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm27
-rw-r--r--perllib/FixMyStreet/SendReport.pm7
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;