aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2015-03-16 16:24:34 +0000
committerMatthew Somerville <matthew@mysociety.org>2015-03-16 19:10:16 +0000
commit72e7c2ac4b6a644ee2bb002915122648d97c56e0 (patch)
tree6cc0ff6e8386d0aa53ac6bcfcdca8f4ae1dfa2ac /perllib
parentd0a16157fbd10f8bdf1a07c77331504c61bf7f5d (diff)
[fixmystreet.com] Remove special NI code.
This is now handled by normal bodies in the admin. In order to remove references in send_reports, tidy up (unused) EmptyHomes code a bit.
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/Cobrand/EmptyHomes.pm6
-rw-r--r--perllib/FixMyStreet/Cobrand/UK.pm9
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm152
-rw-r--r--perllib/FixMyStreet/SendReport/NI.pm37
4 files changed, 76 insertions, 128 deletions
diff --git a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
index b87a1cf24..5052d91a7 100644
--- a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
+++ b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm
@@ -13,6 +13,12 @@ sub path_to_web_templates {
return [ FixMyStreet->path_to( 'templates/web', $self->moniker )->stringify ];
}
+sub _fallback_body_sender {
+ my ( $self, $body, $category ) = @_;
+
+ return { method => 'EmptyHomes' };
+};
+
=item
Return the base url for this cobranded site
diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm
index 33d3b4253..cd64de9c6 100644
--- a/perllib/FixMyStreet/Cobrand/UK.pm
+++ b/perllib/FixMyStreet/Cobrand/UK.pm
@@ -26,15 +26,6 @@ sub disambiguate_location {
};
}
-sub _fallback_body_sender {
- my ( $self, $body, $category ) = @_;
-
- my $first_area = $body->body_areas->first->area_id;
- my $area_info = mySociety::MaPit::call('area', $first_area);
- return { method => 'NI' } if $area_info->{type} eq 'LGD';
- return { method => 'Email' };
-}
-
sub process_extras {
my $self = shift;
my $ctx = shift;
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index cc0cc5242..7a50a3146 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -302,118 +302,106 @@ sub send_reports {
if ( $cobrand->allow_anonymous_reports &&
$row->user->email eq $cobrand->anonymous_account->{'email'}
) {
- $h{anonymous_report} = 1;
- $h{user_details} = _('This report was submitted anonymously');
- } else {
- $h{user_details} = sprintf(_('Name: %s'), $row->name) . "\n\n";
- $h{user_details} .= sprintf(_('Email: %s'), $row->user->email) . "\n\n";
- }
+ $h{anonymous_report} = 1;
+ $h{user_details} = _('This report was submitted anonymously');
+ } else {
+ $h{user_details} = sprintf(_('Name: %s'), $row->name) . "\n\n";
+ $h{user_details} .= sprintf(_('Email: %s'), $row->user->email) . "\n\n";
+ }
+
+ $h{easting_northing} = '';
if ($cobrand->can('process_additional_metadata_for_email')) {
$cobrand->process_additional_metadata_for_email($row, \%h);
}
+ # XXX Needs locks!
+ # XXX Only copes with at most one missing body
+ my ($bodies, $missing) = $row->bodies_str =~ /^([\d,]+)(?:\|(\d+))?/;
+ my @bodies = split(/,/, $bodies);
+ $bodies = FixMyStreet::App->model("DB::Body")->search(
+ { id => \@bodies },
+ { order_by => 'name' },
+ );
+ $missing = FixMyStreet::App->model("DB::Body")->find($missing) if $missing;
+
+ my @dear;
my %reporters = ();
- my ( $sender_count );
- if ($site eq 'emptyhomes') {
-
- my $body = $row->bodies_str;
- $body = FixMyStreet::App->model("DB::Body")->find($body);
- my $sender = "FixMyStreet::SendReport::EmptyHomes";
- $reporters{ $sender } = $sender->new() unless $reporters{$sender};
- $reporters{ $sender }->add_body( $body );
- $sender_count = 1;
+ while (my $body = $bodies->next) {
+ my $sender_info = $cobrand->get_body_sender( $body, $row->category );
+ my $sender = "FixMyStreet::SendReport::" . $sender_info->{method};
- } else {
-
- # XXX Needs locks!
- # XXX Only copes with at most one missing body
- my ($bodies, $missing) = $row->bodies_str =~ /^([\d,]+)(?:\|(\d+))?/;
- my @bodies = split(/,/, $bodies);
- $bodies = FixMyStreet::App->model("DB::Body")->search(
- { id => \@bodies },
- { order_by => 'name' },
- );
- $missing = FixMyStreet::App->model("DB::Body")->find($missing) if $missing;
- my @dear;
-
- while (my $body = $bodies->next) {
- my $sender_info = $cobrand->get_body_sender( $body, $row->category );
- my $sender = "FixMyStreet::SendReport::" . $sender_info->{method};
-
- if ( ! exists $senders->{ $sender } ) {
- warn "No such sender [ $sender ] for body $body->name ( $body->id )";
- next;
- }
- $reporters{ $sender } ||= $sender->new();
-
- if ( $reporters{ $sender }->should_skip( $row ) ) {
- debug_print("skipped by sender " . $sender_info->{method} . " (might be due to previous failed attempts?)", $row->id) if $debug_mode;
- } else {
- debug_print("OK, adding recipient body " . $body->id . ":" . $body->name . ", " . $body->send_method, $row->id) if $debug_mode;
- push @dear, $body->name;
- $reporters{ $sender }->add_body( $body, $sender_info->{config} );
- }
+ if ( ! exists $senders->{ $sender } ) {
+ warn "No such sender [ $sender ] for body $body->name ( $body->id )";
+ next;
}
+ $reporters{ $sender } ||= $sender->new();
- if ($h{category} eq _('Other')) {
- $h{category_footer} = _('this type of local problem');
- $h{category_line} = '';
+ if ( $reporters{ $sender }->should_skip( $row ) ) {
+ debug_print("skipped by sender " . $sender_info->{method} . " (might be due to previous failed attempts?)", $row->id) if $debug_mode;
} else {
- $h{category_footer} = "'" . $h{category} . "'";
- $h{category_line} = sprintf(_("Category: %s"), $h{category}) . "\n\n";
+ debug_print("OK, adding recipient body " . $body->id . ":" . $body->name . ", " . $body->send_method, $row->id) if $debug_mode;
+ push @dear, $body->name;
+ $reporters{ $sender }->add_body( $body, $sender_info->{config} );
}
- if ( $row->subcategory ) {
- $h{subcategory_line} = sprintf(_("Subcategory: %s"), $row->subcategory) . "\n\n";
- } else {
- $h{subcategory_line} = "\n\n";
- }
+ # If we are in the UK include eastings and northings, and nearest stuff
+ if ( $cobrand->country eq 'GB' && !$h{easting} ) {
+ my $coordsyst = 'G';
+ my $first_area = $body->body_areas->first->area_id;
+ my $area_info = mySociety::MaPit::call('area', $first_area);
+ $coordsyst = 'I' if $area_info->{type} eq 'LGD';
- $h{bodies_name} = join(_(' and '), @dear);
- if ($h{category} eq _('Other')) {
- $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to both councils covering the location of the problem, as the user did not categorise it; please ignore it if you're not the correct council to deal with the issue, or let us know what category of problem this is so we can add it to our system.") . " ]\n\n"
- : '';
- } else {
- $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to several councils covering the location of the problem, as the category selected is provided for all of them; please ignore it if you're not the correct council to deal with the issue.") . " ]\n\n"
- : '';
- }
- $h{missing} = '';
- if ($missing) {
- $h{missing} = '[ '
- . sprintf(_('We realise this problem might be the responsibility of %s; however, we don\'t currently have any contact details for them. If you know of an appropriate contact address, please do get in touch.'), $missing->name)
- . " ]\n\n";
- }
+ ( $h{easting}, $h{northing} ) = Utils::convert_latlon_to_en( $h{latitude}, $h{longitude}, $coordsyst );
- $sender_count = scalar @dear;
+ # email templates don't have conditionals so we need to format this here
+ $h{easting_northing} = "Easting/Northing";
+ $h{easting_northing} .= " (IE)" if $coordsyst eq 'I';
+ $h{easting_northing} .= ": $h{easting}/$h{northing}\n\n";
+ }
}
unless ( keys %reporters ) {
die 'Report not going anywhere for ID ' . $row->id . '!';
}
- if (! $sender_count) {
+ unless (@dear) {
debug_print("can't send because sender count is zero", $row->id) if $debug_mode;
next;
}
- # If we are in the UK include eastings and northings, and nearest stuff
- $h{easting_northing} = '';
- if ( $cobrand->country eq 'GB' ) {
+ if ($h{category} eq _('Other')) {
+ $h{category_footer} = _('this type of local problem');
+ $h{category_line} = '';
+ } else {
+ $h{category_footer} = "'" . $h{category} . "'";
+ $h{category_line} = sprintf(_("Category: %s"), $h{category}) . "\n\n";
+ }
- my $coordsyst = 'G';
- $coordsyst = 'I' if grep { /FixMyStreet::SendReport::NI/ } keys %reporters;
- ( $h{easting}, $h{northing} ) = Utils::convert_latlon_to_en( $h{latitude}, $h{longitude}, $coordsyst );
+ if ( $row->subcategory ) {
+ $h{subcategory_line} = sprintf(_("Subcategory: %s"), $row->subcategory) . "\n\n";
+ } else {
+ $h{subcategory_line} = "\n\n";
+ }
- # email templates don't have conditionals so we need to format this here
- $h{easting_northing} = "Easting/Northing";
- $h{easting_northing} .= " (IE)" if $coordsyst eq 'I';
- $h{easting_northing} .= ": $h{easting}/$h{northing}\n\n";
+ $h{bodies_name} = join(_(' and '), @dear);
+ if ($h{category} eq _('Other')) {
+ $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to both councils covering the location of the problem, as the user did not categorise it; please ignore it if you're not the correct council to deal with the issue, or let us know what category of problem this is so we can add it to our system.") . " ]\n\n"
+ : '';
+ } else {
+ $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to several councils covering the location of the problem, as the category selected is provided for all of them; please ignore it if you're not the correct council to deal with the issue.") . " ]\n\n"
+ : '';
+ }
+ $h{missing} = '';
+ if ($missing) {
+ $h{missing} = '[ '
+ . sprintf(_('We realise this problem might be the responsibility of %s; however, we don\'t currently have any contact details for them. If you know of an appropriate contact address, please do get in touch.'), $missing->name)
+ . " ]\n\n";
}
if (mySociety::Config::get('STAGING_SITE') && !mySociety::Config::get('SEND_REPORTS_ON_STAGING')) {
# on a staging server send emails to ourselves rather than the bodies
- %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|NI|EmptyHomes)/ } keys %reporters;
+ %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|EmptyHomes)/ } keys %reporters;
unless (%reporters) {
%reporters = ( 'FixMyStreet::SendReport::Email' => FixMyStreet::SendReport::Email->new() );
}
diff --git a/perllib/FixMyStreet/SendReport/NI.pm b/perllib/FixMyStreet/SendReport/NI.pm
deleted file mode 100644
index c60643566..000000000
--- a/perllib/FixMyStreet/SendReport/NI.pm
+++ /dev/null
@@ -1,37 +0,0 @@
-package FixMyStreet::SendReport::NI;
-
-use Moose;
-
-BEGIN { extends 'FixMyStreet::SendReport::Email'; }
-
-sub build_recipient_list {
- my ( $self, $row, $h ) = @_;
-
- my $all_confirmed = 1;
- foreach my $body ( @{ $self->bodies } ) {
- my $contact = FixMyStreet::App->model("DB::Contact")->find( {
- deleted => 0,
- body_id => $body->id,
- 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 = $body->name;
- if ( $email =~ /^roads.([^@]*)\@drdni/ ) {
- $name = "Roads Service (\u$1)";
- $h->{bodies_name} = $name;
- $row->external_body( 'Roads Service' );
- }
- push @{ $self->to }, [ $email, $name ];
- }
-
- return $all_confirmed && @{$self->to};
-}
-
-1;