aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--db/schema.sql1
-rw-r--r--db/schema_0030-add-body-name.sql7
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm25
-rw-r--r--perllib/FixMyStreet/Cobrand/UK.pm7
-rw-r--r--perllib/FixMyStreet/DB/Result/Body.pm6
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm42
-rw-r--r--perllib/FixMyStreet/SendReport.pm15
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm26
-rw-r--r--perllib/FixMyStreet/SendReport/EmptyHomes.pm23
-rw-r--r--perllib/FixMyStreet/SendReport/NI.pm8
-rw-r--r--perllib/FixMyStreet/SendReport/Open311.pm25
-rw-r--r--templates/email/default/submit-brent.txt2
-rw-r--r--templates/email/default/submit.txt2
-rw-r--r--templates/email/fiksgatami/nn/submit.txt2
-rw-r--r--templates/email/fiksgatami/submit.txt2
15 files changed, 104 insertions, 89 deletions
diff --git a/db/schema.sql b/db/schema.sql
index 549222b1a..9fd4ce332 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -419,6 +419,7 @@ create table admin_log (
create table body (
id serial primary key,
+ name text not null,
area_id integer not null unique,
endpoint text,
jurisdiction text,
diff --git a/db/schema_0030-add-body-name.sql b/db/schema_0030-add-body-name.sql
new file mode 100644
index 000000000..30ac26e98
--- /dev/null
+++ b/db/schema_0030-add-body-name.sql
@@ -0,0 +1,7 @@
+begin;
+
+ALTER TABLE body ADD name text;
+UPDATE body SET name='';
+ALTER table body ALTER COLUMN name SET NOT NULL;
+
+commit;
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index e13d915af..f6d2dfd5f 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -647,31 +647,26 @@ Get stats to display on the council reports page
sub get_report_stats { return 0; }
-sub get_council_sender {
- my ( $self, $area_id, $area_info, $category ) = @_;
+sub get_body_sender {
+ my ( $self, $body, $category ) = @_;
- my $send_method;
-
- my $council_config = FixMyStreet::App->model("DB::Body")->search( { area_id => $area_id } )->first;
- $send_method = $council_config->send_method if $council_config;
-
- if ( $council_config && $council_config->can_be_devolved ) {
+ if ( $body->can_be_devolved ) {
# look up via category
- my $config = FixMyStreet::App->model("DB::Contact")->search( { body_id => $area_id, category => $category } )->first;
+ my $config = FixMyStreet::App->model("DB::Contact")->search( { body_id => $body->id, category => $category } )->first;
if ( $config->send_method ) {
return { method => $config->send_method, config => $config };
} else {
- return { method => $send_method, config => $council_config };
+ return { method => $body->send_method, config => $body };
}
- } elsif ( $send_method ) {
- return { method => $send_method, config => $council_config };
+ } elsif ( $body->send_method ) {
+ return { method => $body->send_method, config => $body };
}
- return $self->_fallback_council_sender( $area_id, $area_info, $category );
+ return $self->_fallback_body_sender( $body, $category );
}
-sub _fallback_council_sender {
- my ( $self, $area_id, $area_info, $category ) = @_;
+sub _fallback_body_sender {
+ my ( $self, $body, $category ) = @_;
return { method => 'Email' };
};
diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm
index 4eee1869e..d5456d056 100644
--- a/perllib/FixMyStreet/Cobrand/UK.pm
+++ b/perllib/FixMyStreet/Cobrand/UK.pm
@@ -1,6 +1,7 @@
package FixMyStreet::Cobrand::UK;
use base 'FixMyStreet::Cobrand::Default';
+use mySociety::MaPit;
use mySociety::VotingArea;
sub path_to_web_templates {
@@ -31,8 +32,10 @@ sub disambiguate_location {
};
}
-sub _fallback_council_sender {
- my ( $self, $area_id, $area_info, $category ) = @_;
+sub _fallback_body_sender {
+ my ( $self, $body, $category ) = @_;
+
+ my $area_info = mySociety::MaPit::call('area', $body->area_id);
return { method => 'London' } if $area_info->{type} eq 'LBO';
return { method => 'NI' } if $area_info->{type} eq 'LGD';
return { method => 'Email' };
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm
index 6071ef33e..7f5777908 100644
--- a/perllib/FixMyStreet/DB/Result/Body.pm
+++ b/perllib/FixMyStreet/DB/Result/Body.pm
@@ -36,6 +36,8 @@ __PACKAGE__->add_columns(
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
"can_be_devolved",
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "name",
+ { data_type => "text", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("body_area_id_key", ["area_id"]);
@@ -58,8 +60,8 @@ __PACKAGE__->has_many(
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-13 12:34:57
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YiDf4mhoPlG5cnxCIrqZxw
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-13 12:36:19
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Yl1KHSUzPi7KDjMenUe8qw
# You can replace this text with custom code or comments, and it will be preserved on regeneration
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index bb826a5ca..4d8004024 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -228,7 +228,7 @@ sub send_reports {
my $unsent = FixMyStreet::App->model("DB::Problem")->search( {
state => [ 'confirmed', 'fixed' ],
whensent => undef,
- council => { '!=', undef },
+ bodies => { '!=', undef },
} );
my (%notgot, %note);
@@ -292,29 +292,28 @@ sub send_reports {
my ( $sender_count );
if ($site eq 'emptyhomes') {
- my $council = $row->council;
- my $areas_info = mySociety::MaPit::call('areas', $council);
+ my $body = $row->bodies;
+ $body = FixMyStreet::App->model("DB::Body")->find($body);
my $sender = "FixMyStreet::SendReport::EmptyHomes";
$reporters{ $sender } = $sender->new() unless $reporters{$sender};
- $reporters{ $sender }->add_council( $council, $areas_info->{$council} );
+ $reporters{ $sender }->add_body( $body );
} else {
# XXX Needs locks!
- my @all_councils = split /,|\|/, $row->council;
- my ($councils, $missing) = $row->council =~ /^([\d,]+)(?:\|([\d,]+))?/;
- my @councils = split(/,/, $councils);
- my $areas_info = mySociety::MaPit::call('areas', \@all_councils);
+ # XXX Only copes with at most one missing body
+ my ($bodies, $missing) = $row->bodies =~ /^([\d,]+)(?:\|(\d+))?/;
+ my @bodies = split(/,/, $bodies);
+ $bodies = FixMyStreet::App->model("DB::Body")->search({ id => \@bodies });
+ $missing = FixMyStreet::App->model("DB::Body")->find($missing);
my @dear;
- foreach my $council (@councils) {
- my $name = $areas_info->{$council}->{name};
-
- my $sender_info = $cobrand->get_council_sender( $council, $areas_info->{$council}, $row->category );
+ 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 council $name ( $council )";
+ warn "No such sender [ $sender ] for body $body->name ( $body->id )";
next;
}
$reporters{ $sender } ||= $sender->new();
@@ -323,8 +322,8 @@ sub send_reports {
$sending_skipped_by_method{ $sender }++ if
$reporters{ $sender }->skipped;
} else {
- push @dear, $name;
- $reporters{ $sender }->add_council( $council, $areas_info->{$council}, $sender_info->{config} );
+ push @dear, $body->name;
+ $reporters{ $sender }->add_body( $body, $sender_info->{config} );
}
}
@@ -336,7 +335,7 @@ sub send_reports {
$h{category_line} = sprintf(_("Category: %s"), $h{category}) . "\n\n";
}
- $h{councils_name} = join(_(' and '), @dear);
+ $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"
: '';
@@ -346,9 +345,8 @@ sub send_reports {
}
$h{missing} = '';
if ($missing) {
- my $name = $areas_info->{$missing}->{name};
$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.'), $name)
+ . 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";
}
@@ -362,9 +360,9 @@ sub send_reports {
next unless $sender_count;
if (mySociety::Config::get('STAGING_SITE')) {
- # on a staging server send emails to ourselves rather than the councils
- my @testing_councils = split( '\|', mySociety::Config::get('TESTING_COUNCILS') );
- unless ( grep { $row->council eq $_ } @testing_councils ) {
+ # on a staging server send emails to ourselves rather than the bodies
+ my @testing_bodies = split( '\|', mySociety::Config::get('TESTING_COUNCILS') );
+ unless ( grep { $row->bodies eq $_ } @testing_bodies ) {
%reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|NI)/ } keys %reporters;
unless (%reporters) {
%reporters = ( 'FixMyStreet::SendReport::Email' => FixMyStreet::SendReport::Email->new() );
@@ -426,7 +424,7 @@ sub send_reports {
my $unsent = FixMyStreet::App->model("DB::Problem")->search( {
state => [ 'confirmed', 'fixed' ],
whensent => undef,
- council => { '!=', undef },
+ bodies => { '!=', undef },
send_fail_count => { '>', 0 }
} );
while (my $row = $unsent->next) {
diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm
index 9ba507862..f8901c6f8 100644
--- a/perllib/FixMyStreet/SendReport.pm
+++ b/perllib/FixMyStreet/SendReport.pm
@@ -7,7 +7,8 @@ use Module::Pluggable
search_path => __PACKAGE__,
require => 1;
-has 'councils' => ( is => 'rw', isa => 'HashRef', default => sub { {} } );
+has 'body_config' => ( is => 'rw', isa => 'HashRef', default => sub { {} } );
+has 'bodies' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } );
has 'to' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } );
has 'success' => ( is => 'rw', isa => 'Bool', default => 0 );
has 'error' => ( is => 'rw', isa => 'Str', default => '' );
@@ -31,18 +32,18 @@ sub get_senders {
sub reset {
my $self = shift;
- $self->councils( {} );
+ $self->bodies( [] );
+ $self->body_config( {} );
$self->to( [] );
}
-sub add_council {
+sub add_body {
my $self = shift;
- my $council = shift;
- my $info = shift;
+ my $body = shift;
my $config = shift;
- $self->councils->{ $council } = { info => $info, config => $config };
+ push @{$self->bodies}, $body;
+ $self->body_config->{ $body->id } = $config;
}
-
1;
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;
}
}
diff --git a/templates/email/default/submit-brent.txt b/templates/email/default/submit-brent.txt
index c94e6e1e4..75a954765 100644
--- a/templates/email/default/submit-brent.txt
+++ b/templates/email/default/submit-brent.txt
@@ -1,6 +1,6 @@
Subject: FMS Problem Report: <?=$values['title']?>
-Dear <?=$values['councils_name']?>,
+Dear <?=$values['bodies_name']?>,
<?=$values['missing']?><?=$values['multiple']?>A user of
FixMyStreet has submitted the following report
diff --git a/templates/email/default/submit.txt b/templates/email/default/submit.txt
index a956b4add..6066a7b68 100644
--- a/templates/email/default/submit.txt
+++ b/templates/email/default/submit.txt
@@ -1,6 +1,6 @@
Subject: Problem Report: <?=$values['title']?>
-Dear <?=$values['councils_name']?>,
+Dear <?=$values['bodies_name']?>,
<?=$values['missing']?><?=$values['multiple']?>A user of
FixMyStreet has submitted the following report
diff --git a/templates/email/fiksgatami/nn/submit.txt b/templates/email/fiksgatami/nn/submit.txt
index 82849b0d5..52f519221 100644
--- a/templates/email/fiksgatami/nn/submit.txt
+++ b/templates/email/fiksgatami/nn/submit.txt
@@ -1,6 +1,6 @@
Subject: Problemrapport: <?=$values['title']?>
-Til <?=$values['councils_name']?>,
+Til <?=$values['bodies_name']?>,
<?=$values['missing']?><?=$values['multiple']?>Ein brukar av
FiksGataMi har sendt inn følgjande rapport om eit lokalt problem som
diff --git a/templates/email/fiksgatami/submit.txt b/templates/email/fiksgatami/submit.txt
index 8005f5c82..947729422 100644
--- a/templates/email/fiksgatami/submit.txt
+++ b/templates/email/fiksgatami/submit.txt
@@ -1,6 +1,6 @@
Subject: Problemrapport: <?=$values['title']?>
-Til <?=$values['councils_name']?>,
+Til <?=$values['bodies_name']?>,
<?=$values['missing']?><?=$values['multiple']?>En bruker av
FiksGataMi har sendt inn følgende rapport om et lokalt