diff options
author | Matthew Somerville <matthew@mysociety.org> | 2013-02-01 15:28:08 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2013-02-04 06:53:02 +0000 |
commit | 488a8f21a0c1bc2b9501c9d94d69db56cccd80ae (patch) | |
tree | 68becf501e9492466a80015e8ace9a7fb1557cfa /perllib/FixMyStreet/SendReport/Email.pm | |
parent | 3e0d12e8584d132b573f536ab5cd01e24241827b (diff) | |
parent | 28aa1dd7fb1c9bc93aa204afae67cf68fe36ee6b (diff) |
Merge remote branch 'origin/zurich'
Conflicts:
bin/open311-populate-service-list
bin/send-comments
bin/update-all-reports
conf/crontab.ugly
db/schema.sql
perllib/FixMyStreet/App/Controller/Admin.pm
perllib/FixMyStreet/App/Controller/Report/New.pm
perllib/FixMyStreet/App/Controller/Reports.pm
perllib/FixMyStreet/Cobrand/Default.pm
perllib/FixMyStreet/Cobrand/LichfieldDC.pm
perllib/FixMyStreet/DB/Result/Open311conf.pm
perllib/FixMyStreet/DB/Result/Problem.pm
perllib/FixMyStreet/DB/ResultSet/Problem.pm
perllib/FixMyStreet/SendReport.pm
perllib/FixMyStreet/SendReport/Email.pm
perllib/FixMyStreet/SendReport/Open311.pm
perllib/Open311/GetServiceRequestUpdates.pm
perllib/Open311/PopulateServiceList.pm
t/app/controller/report_new.t
t/app/controller/rss.t
templates/web/bromley/report/display.html
templates/web/default/admin/council_contacts.html
templates/web/default/common_header_tags.html
templates/web/default/dashboard/index.html
templates/web/default/front/stats.html
templates/web/default/report/_main.html
templates/web/default/report/update-form.html
templates/web/emptyhomes/index.html
templates/web/emptyhomes/report/display.html
templates/web/emptyhomes/report/new/councils_text_all.html
templates/web/emptyhomes/reports/body.html
templates/web/emptyhomes/reports/index.html
templates/web/fixmystreet/report/new/fill_in_details_form.html
templates/web/fixmystreet/report/update-form.html
web/cobrands/fixmystreet/fixmystreet.js
web/js/fixmystreet.js
Diffstat (limited to 'perllib/FixMyStreet/SendReport/Email.pm')
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index f26116bc4..1ff476da3 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -11,36 +11,36 @@ sub build_recipient_list { my %recips; my $all_confirmed = 1; - foreach my $council ( keys %{ $self->councils } ) { + foreach my $body ( @{ $self->bodies } ) { my $contact = FixMyStreet::App->model("DB::Contact")->find( { deleted => 0, - area_id => $council, + body_id => $body->id, category => $row->category } ); - my ($council_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note ); + my ($body_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note ); - $council_email = essex_contact($row->latitude, $row->longitude) if $council == 2225; - $council_email = oxfordshire_contact($row->latitude, $row->longitude) if $council == 2237 && $council_email eq 'SPECIAL'; + $body_email = essex_contact($row->latitude, $row->longitude) if $body->areas->{2225}; + $body_email = oxfordshire_contact($row->latitude, $row->longitude) if $body->areas->{2237} && $body_email eq 'SPECIAL'; unless ($confirmed) { $all_confirmed = 0; - $note = 'Council ' . $row->council . ' deleted' + $note = 'Body ' . $row->bodies_str . ' deleted' unless $note; - $council_email = 'N/A' unless $council_email; - $self->unconfirmed_counts->{$council_email}{$row->category}++; - $self->unconfirmed_notes->{$council_email}{$row->category} = $note; + $body_email = 'N/A' unless $body_email; + $self->unconfirmed_counts->{$body_email}{$row->category}++; + $self->unconfirmed_notes->{$body_email}{$row->category} = $note; } # see something uses council areas but doesn't send to councils so just use a # generic name here to minimise confusion if ( $row->cobrand eq 'seesomething' ) { - push @{ $self->to }, [ $council_email, 'See Something, Say Something' ]; + push @{ $self->to }, [ $body_email, 'See Something, Say Something' ]; } else { - push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{info}->{name} ]; + push @{ $self->to }, [ $body_email, $body->name ]; } - $recips{$council_email} = 1; + $recips{$body_email} = 1; } return () unless $all_confirmed; @@ -51,7 +51,7 @@ sub get_template { my ( $self, $row ) = @_; my $template = 'submit.txt'; - $template = 'submit-brent.txt' if $row->council eq 2488 || $row->council eq 2237; + $template = 'submit-brent.txt' if $row->bodies_str eq 2488 || $row->bodies_str eq 2237; my $template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $row->lang, $template )->stringify; $template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $template )->stringify unless -e $template_path; @@ -61,14 +61,19 @@ sub get_template { return $template; } +sub send_from { + my ( $self, $row ) = @_; + return [ $row->user->email, $row->name ]; +} + sub send { my $self = shift; my ( $row, $h ) = @_; 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') && !FixMyStreet->test_mode) { + # on a staging server send emails to ourselves rather than the bodies + if (mySociety::Config::get('STAGING_SITE') && !mySociety::Config::get('SEND_REPORTS_ON_STAGING') && !FixMyStreet->test_mode) { @recips = ( mySociety::Config::get('CONTACT_EMAIL') ); } @@ -83,7 +88,7 @@ sub send { _template_ => $self->get_template( $row ), _parameters_ => $h, To => $self->to, - From => [ $row->user->email, $row->name ], + From => $self->send_from( $row ), }, mySociety::Config::get('CONTACT_EMAIL'), \@recips, |