diff options
Diffstat (limited to 'perllib/FixMyStreet/SendReport')
-rw-r--r-- | perllib/FixMyStreet/SendReport/Barnet.pm | 16 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/EastHants.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 41 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/EmptyHomes.pm | 16 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/London.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/NI.pm | 40 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 25 |
7 files changed, 103 insertions, 39 deletions
diff --git a/perllib/FixMyStreet/SendReport/Barnet.pm b/perllib/FixMyStreet/SendReport/Barnet.pm index ecbe82872..9a92686ec 100644 --- a/perllib/FixMyStreet/SendReport/Barnet.pm +++ b/perllib/FixMyStreet/SendReport/Barnet.pm @@ -19,15 +19,15 @@ use constant MAX_LINE_LENGTH => 132; sub should_skip { my $self = shift; - my $problem = shift; + my $row = shift; my $council_name = 'Barnet'; my $err_msg = ""; - if ($problem->send_fail_count >= SEND_FAIL_RETRIES_CUTOFF) { + if ($row->send_fail_count >= SEND_FAIL_RETRIES_CUTOFF) { $council_name &&= " to $council_name"; - $err_msg = "skipped: problem id=" . $problem->id . " send$council_name has failed " - . $problem->send_fail_count . " times, cutoff is " . SEND_FAIL_RETRIES_CUTOFF; + $err_msg = "skipped: problem id=" . $row->id . " send$council_name has failed " + . $row->send_fail_count . " times, cutoff is " . SEND_FAIL_RETRIES_CUTOFF; $self->skipped( $err_msg ); @@ -52,7 +52,7 @@ EOF sub send { - my ( $self, $problem, $h, $to, $template, $recips, $nomail ) = @_; + my ( $self, $row, $h ) = @_; my %h = %$h; @@ -127,9 +127,9 @@ sub send { if ($result) { # currently not using this: get_EV_ORDER_GUID (maybe that's the customer number in the CRM) if (my $barnet_id = $result->get_EV_ORDER_NO()) { - $problem->external_id( $barnet_id ); - $problem->external_body( 'Barnet Borough Council' ); # better to use $problem->body()? - $problem->send_method_used('barnet'); + $row->external_id( $barnet_id ); + $row->external_body( 'Barnet Borough Council' ); # better to use $row->body()? + $row->send_method_used('barnet'); $return = 0; } else { my @returned_items = split /<item[^>]*>/, $result->get_ET_RETURN; diff --git a/perllib/FixMyStreet/SendReport/EastHants.pm b/perllib/FixMyStreet/SendReport/EastHants.pm index 681a9d4c4..beab9d55c 100644 --- a/perllib/FixMyStreet/SendReport/EastHants.pm +++ b/perllib/FixMyStreet/SendReport/EastHants.pm @@ -32,7 +32,7 @@ EOF sub send { return if mySociety::Config::get('STAGING_SITE'); - my ( $self, $row, $h, $to, $template, $recips, $nomail ) = @_; + my ( $self, $row, $h ) = @_; # FIXME: should not recreate this each time my $eh_service; 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 ], diff --git a/perllib/FixMyStreet/SendReport/EmptyHomes.pm b/perllib/FixMyStreet/SendReport/EmptyHomes.pm index 9453b4ca5..e1b914523 100644 --- a/perllib/FixMyStreet/SendReport/EmptyHomes.pm +++ b/perllib/FixMyStreet/SendReport/EmptyHomes.pm @@ -6,9 +6,7 @@ use namespace::autoclean; BEGIN { extends 'FixMyStreet::SendReport::Email'; } sub build_recipient_list { - my $self = shift; - my $row = shift; - my $areas_info = shift; + my ( $self, $row, $h ) = @_; my %recips; my $all_confirmed = 1; @@ -21,9 +19,6 @@ sub build_recipient_list { my ($council_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'; - unless ($confirmed) { $all_confirmed = 0; #$note = 'Council ' . $row->council . ' deleted' @@ -33,10 +28,10 @@ sub build_recipient_list { #$note{$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; - my $country = $areas_info->{$council}->{country}; + my $country = $self->councils->{$council}->{country}; if ($country eq 'W') { $recips{ 'shelter@' . mySociety::Config::get('EMAIL_DOMAIN') } = 1; } else { @@ -48,4 +43,9 @@ sub build_recipient_list { return keys %recips; } +sub get_template { + my ( $self, $row ) = @_; + return Utils::read_file( FixMyStreet->path_to( "templates", "email", "emptyhomes", $row->lang, "submit.txt" )->stringify ); +} + 1; diff --git a/perllib/FixMyStreet/SendReport/London.pm b/perllib/FixMyStreet/SendReport/London.pm index 58ecb2375..6e7951922 100644 --- a/perllib/FixMyStreet/SendReport/London.pm +++ b/perllib/FixMyStreet/SendReport/London.pm @@ -33,7 +33,7 @@ EOF sub send { return if mySociety::Config::get('STAGING_SITE'); - my ( $self, $row, $h, $to, $template, $recips, $nomail ) = @_; + my ( $self, $row, $h ) = @_; $h->{message} = construct_message( %$h ); my $phone = $h->{phone}; diff --git a/perllib/FixMyStreet/SendReport/NI.pm b/perllib/FixMyStreet/SendReport/NI.pm new file mode 100644 index 000000000..0783a385b --- /dev/null +++ b/perllib/FixMyStreet/SendReport/NI.pm @@ -0,0 +1,40 @@ +package FixMyStreet::SendReport::NI; + +use Moose; + +BEGIN { extends 'FixMyStreet::SendReport::Email'; } + +sub build_recipient_list { + my ( $self, $row, $h ) = @_; + my %recips; + + my $all_confirmed = 1; + foreach my $council ( keys %{ $self->councils } ) { + my $contact = FixMyStreet::App->model("DB::Contact")->find( { + deleted => 0, + area_id => $council, + category => $row->category + } ); + + my ($email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note ); + + unless ($confirmed) { + $all_confirmed = 0; + $email = 'N/A' unless $email; + } + + my $name = $self->councils->{$council}->{name}; + if ( $email =~ /^roads.([^@]*)\@drdni/ ) { + $name = "Roads Service (\u$1)"; + $h->{councils_name} = $name; + $row->external_body( 'Roads Service' ); + } + push @{ $self->to }, [ $email, $name ]; + $recips{$email} = 1; + } + + return () unless $all_confirmed; + return keys %recips; +} + +1; diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index b4380df02..56473cf5f 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -23,7 +23,7 @@ sub should_skip { sub send { my $self = shift; - my ( $row, $h, $to, $template, $recips, $nomail ) = @_; + my ( $row, $h ) = @_; my $result = -1; @@ -32,6 +32,7 @@ sub send { my $always_send_latlong = 1; my $send_notpinpointed = 0; + my $use_service_as_deviceid = 0; my $basic_desc = 0; @@ -54,6 +55,15 @@ sub send { $always_send_latlong = 0; $send_notpinpointed = 1; + $use_service_as_deviceid = 0; + + # make sure we have last_name attribute present in row's extra, so + # it is passed correctly to Bromley as attribute[] + if ( $row->cobrand ne 'bromley' ) { + my ( $firstname, $lastname ) = ( $row->user->name =~ /(\w+)\.?\s+(.+)/ ); + push @$extra, { name => 'last_name', value => $lastname }; + } + $basic_desc = 1; } @@ -65,12 +75,13 @@ sub send { } ); my $open311 = Open311->new( - jurisdiction => $conf->jurisdiction, - endpoint => $conf->endpoint, - api_key => $conf->api_key, - always_send_latlong => $always_send_latlong, - send_notpinpointed => $send_notpinpointed, - basic_description => $basic_desc, + jurisdiction => $conf->jurisdiction, + endpoint => $conf->endpoint, + api_key => $conf->api_key, + always_send_latlong => $always_send_latlong, + send_notpinpointed => $send_notpinpointed, + use_service_as_deviceid => $use_service_as_deviceid, + basic_description => $basic_desc, ); # non standard west berks end points |