diff options
Diffstat (limited to 'perllib/FixMyStreet/SendReport/Email.pm')
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 239bee715..654ed6b3a 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -7,8 +7,7 @@ BEGIN { extends 'FixMyStreet::SendReport'; } use mySociety::EmailUtil; sub build_recipient_list { - my $self = shift; - my $row = shift; + my ( $self, $row, $h ) = @_; my %recips; my $all_confirmed = 1; @@ -26,14 +25,14 @@ sub build_recipient_list { unless ($confirmed) { $all_confirmed = 0; - #$note = 'Council ' . $row->council . ' deleted' - #unless $note; + $note = 'Council ' . $row->council . ' deleted' + unless $note; $council_email = 'N/A' unless $council_email; - #$notgot{$council_email}{$row->category}++; - #$note{$council_email}{$row->category} = $note; + $self->unconfirmed_counts->{$council_email}{$row->category}++; + $self->unconfirmed_notes->{$council_email}{$row->category} = $note; } - push @{ $self->to }, [ $council_email, $self->councils->{ $council } ]; + push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{name} ]; $recips{$council_email} = 1; } @@ -41,24 +40,38 @@ sub build_recipient_list { return keys %recips; } +sub get_template { + my ( $self, $row ) = @_; + + my $template = 'submit.txt'; + $template = 'submit-brent.txt' if $row->council eq 2488 || $row->council eq 2237; + my $template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $template )->stringify; + $template_path = FixMyStreet->path_to( "templates", "email", "default", $template )->stringify + unless -e $template_path; + $template = Utils::read_file( $template_path ); + return $template; +} + sub send { my $self = shift; - my ( $row, $h, $to, $template, $recips, $nomail, $areas_info ) = @_; - - my @recips; + my ( $row, $h ) = @_; - @recips = $self->build_recipient_list( $row, $areas_info ); + my @recips = $self->build_recipient_list( $row, $h ); # on a staging server send emails to ourselves rather than the councils - if (mySociety::Config::get('STAGING_SITE')) { + if (mySociety::Config::get('STAGING_SITE') && !FixMyStreet->test_mode) { @recips = ( mySociety::Config::get('CONTACT_EMAIL') ); } - return unless @recips; + unless ( @recips ) { + $self->error( 'No recipients' ); + return 1; + } + my ($verbose, $nomail) = CronFns::options(); my $result = FixMyStreet::App->send_email_cron( { - _template_ => $template, + _template_ => $self->get_template( $row ), _parameters_ => $h, To => $self->to, From => [ $row->user->email, $row->name ], |