diff options
Diffstat (limited to 'perllib/FixMyStreet/SendReport')
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 26 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/EmptyHomes.pm | 23 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/NI.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 25 |
4 files changed, 45 insertions, 37 deletions
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 0aa5348e7..a39760509 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -11,30 +11,30 @@ 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, - body_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->area_id == 2225; + $body_email = oxfordshire_contact($row->latitude, $row->longitude) if $body->area_id == 2237 && $body_email eq 'SPECIAL'; unless ($confirmed) { $all_confirmed = 0; - $note = 'Council ' . $row->council . ' deleted' + $note = 'Body ' . $row->bodies . ' 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; } - push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{info}->{name} ]; - $recips{$council_email} = 1; + push @{ $self->to }, [ $body_email, $body->name ]; + $recips{$body_email} = 1; } return () unless $all_confirmed; @@ -45,7 +45,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 eq 2488 || $row->bodies 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,7 +61,7 @@ sub send { my @recips = $self->build_recipient_list( $row, $h ); - # on a staging server send emails to ourselves rather than the councils + # on a staging server send emails to ourselves rather than the bodies if (mySociety::Config::get('STAGING_SITE') && !FixMyStreet->test_mode) { @recips = ( mySociety::Config::get('CONTACT_EMAIL') ); } diff --git a/perllib/FixMyStreet/SendReport/EmptyHomes.pm b/perllib/FixMyStreet/SendReport/EmptyHomes.pm index 4eea72540..b29c1fd3c 100644 --- a/perllib/FixMyStreet/SendReport/EmptyHomes.pm +++ b/perllib/FixMyStreet/SendReport/EmptyHomes.pm @@ -3,6 +3,8 @@ package FixMyStreet::SendReport::EmptyHomes; use Moose; use namespace::autoclean; +use mySociety::MaPit; + BEGIN { extends 'FixMyStreet::SendReport::Email'; } sub build_recipient_list { @@ -10,28 +12,29 @@ 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, - body_id => $council, + body_id => $body->id, category => 'Empty property', } ); - my ($council_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note ); + my ($body_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note ); unless ($confirmed) { $all_confirmed = 0; - #$note = 'Council ' . $row->council . ' deleted' + #$note = 'Council ' . $row->body . ' deleted' #unless $note; - $council_email = 'N/A' unless $council_email; - #$notgot{$council_email}{$row->category}++; - #$note{$council_email}{$row->category} = $note; + $body_email = 'N/A' unless $body_email; + #$notgot{$body_email}{$row->category}++; + #$note{$body_email}{$row->category} = $note; } - push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{ info }->{name} ]; - $recips{$council_email} = 1; + push @{ $self->to }, [ $body_email, $body->name ]; + $recips{$body_email} = 1; - my $country = $self->councils->{$council}->{country}; + my $area_info = mySociety::MaPit::call('area', $body->area_id); + my $country = $area_info->{country}; if ($country eq 'W') { $recips{ 'shelter@' . mySociety::Config::get('EMAIL_DOMAIN') } = 1; } else { diff --git a/perllib/FixMyStreet/SendReport/NI.pm b/perllib/FixMyStreet/SendReport/NI.pm index 482df7e90..e0ea24f9c 100644 --- a/perllib/FixMyStreet/SendReport/NI.pm +++ b/perllib/FixMyStreet/SendReport/NI.pm @@ -9,10 +9,10 @@ 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, - body_id => $council, + body_id => $body->id, category => $row->category } ); @@ -23,10 +23,10 @@ sub build_recipient_list { $email = 'N/A' unless $email; } - my $name = $self->councils->{$council}->{info}->{name}; + my $name = $body->name; if ( $email =~ /^roads.([^@]*)\@drdni/ ) { $name = "Roads Service (\u$1)"; - $h->{councils_name} = $name; + $h->{bodies_name} = $name; $row->external_body( 'Roads Service' ); } push @{ $self->to }, [ $email, $name ]; diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index e2620f3b9..f0a76d0fb 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -27,8 +27,8 @@ sub send { my $result = -1; - foreach my $council ( keys %{ $self->councils } ) { - my $conf = $self->councils->{$council}->{config}; + foreach my $body ( @{ $self->bodies } ) { + my $conf = $self->body_config->{ $body->id }; my $always_send_latlong = 1; my $send_notpinpointed = 0; @@ -36,8 +36,13 @@ sub send { my $basic_desc = 0; + # To rollback temporary changes made by this function + my $revert = 0; + # Extra bromley fields - if ( $row->council =~ /2482/ ) { + if ( $row->bodies == 2482 ) { + + $revert = 1; my $extra = $row->extra; if ( $row->used_map || ( !$row->used_map && !$row->postcode ) ) { @@ -70,7 +75,7 @@ sub send { # FIXME: we've already looked this up before my $contact = FixMyStreet::App->model("DB::Contact")->find( { deleted => 0, - body_id => $conf->area_id, + body_id => $body->id, category => $row->category } ); @@ -85,26 +90,26 @@ sub send { ); # non standard west berks end points - if ( $row->council =~ /2619/ ) { + if ( $row->bodies =~ /2619/ ) { $open311->endpoints( { services => 'Services', requests => 'Requests' } ); } # required to get round issues with CRM constraints - if ( $row->council =~ /2218/ ) { + if ( $row->bodies =~ /2218/ ) { $row->user->name( $row->user->id . ' ' . $row->user->name ); + $revert = 1; } if ($row->cobrand eq 'fixmybarangay') { # FixMyBarangay endpoints expect external_id as an attribute $row->extra( [ { 'name' => 'external_id', 'value' => $row->id } ] ); + $revert = 1; } my $resp = $open311->send_service_request( $row, $h, $contact->email ); # make sure we don't save user changes from above - if ( $row->council =~ /2218/ || $row->council =~ /2482/ || $row->cobrand eq 'fixmybarangay') { - $row->discard_changes(); - } + $row->discard_changes() if $revert; if ( $resp ) { $row->external_id( $resp ); @@ -119,7 +124,7 @@ sub send { } else { $result *= 1; # temporary fix to resolve some issues with west berks - if ( $row->council =~ /2619/ ) { + if ( $row->bodies =~ /2619/ ) { $result *= 0; } } |