aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/fixmystreet.com/showcouncilrates1
-rwxr-xr-xbin/update-all-reports3
-rwxr-xr-xbin/update-schema1
-rw-r--r--db/schema.sql1
-rw-r--r--db/schema_0035-bodies_str-tidying.sql10
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm9
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm11
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm19
-rw-r--r--t/app/model/problem.t4
9 files changed, 39 insertions, 20 deletions
diff --git a/bin/fixmystreet.com/showcouncilrates b/bin/fixmystreet.com/showcouncilrates
index 1dacae597..a3465c575 100755
--- a/bin/fixmystreet.com/showcouncilrates
+++ b/bin/fixmystreet.com/showcouncilrates
@@ -38,7 +38,6 @@ my $stats = dbh()->selectall_arrayref($query, { Slice => {} });
my @councils;
foreach my $row (@$stats) {
if ($row->{council}) {
- $row->{council} =~ s/\|.*//g;
my @council_ids = split(/,/, $row->{council});
push(@councils, @council_ids);
$row->{council} = \@council_ids;
diff --git a/bin/update-all-reports b/bin/update-all-reports
index f6cd34210..0627cedc2 100755
--- a/bin/update-all-reports
+++ b/bin/update-all-reports
@@ -57,8 +57,7 @@ while ( my @problem = $problems->next ) {
$problem{bodies} = 0;
} else {
# Add to bodies it was sent to
- (my $bodies = $problem{bodies_str}) =~ s/\|.*$//;
- @bodies = split( /,/, $bodies );
+ @bodies = split( /,/, $problem{bodies_str} );
$problem{bodies} = scalar @bodies;
}
foreach my $body ( @bodies ) {
diff --git a/bin/update-schema b/bin/update-schema
index 57d1d8ad3..dff2255d5 100755
--- a/bin/update-schema
+++ b/bin/update-schema
@@ -195,6 +195,7 @@ else {
# By querying the database schema, we can see where we're currently at
# (assuming schema change files are never half-applied, which should be the case)
sub get_db_version {
+ return '0035' if column_exists('problem', 'bodies_missing');
return '0034' if ! function_exists('ms_current_timestamp');
return '0033' if ! function_exists('angle_between');
return '0032' if table_exists('moderation_original_data');
diff --git a/db/schema.sql b/db/schema.sql
index 609a1445d..5d42d57cf 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -132,6 +132,7 @@ create table problem (
latitude double precision not null,
longitude double precision not null,
bodies_str text, -- the body(s) we'll report this problem to
+ bodies_missing text, -- the body(s) we had no contact details for
areas text not null, -- the mapit areas this location is in
category text not null default 'Other',
title text not null,
diff --git a/db/schema_0035-bodies_str-tidying.sql b/db/schema_0035-bodies_str-tidying.sql
new file mode 100644
index 000000000..c4c7badaf
--- /dev/null
+++ b/db/schema_0035-bodies_str-tidying.sql
@@ -0,0 +1,10 @@
+begin;
+
+alter table problem add bodies_missing text;
+
+update problem
+ set bodies_missing = split_part(bodies_str, '|', 2),
+ bodies_str = split_part(bodies_str, '|', 1)
+ where bodies_str like '%|%';
+
+commit;
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index b540a1961..e9332d852 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -884,12 +884,13 @@ sub process_report : Private {
} else {
# construct the bodies string:
# 'x,x' - x are body IDs that have this category
- # 'x,x|y' - x are body IDs that have this category, y body IDs with *no* contact
my $body_string = join( ',', map { $_->body_id } @contacts );
- $body_string .=
- '|' . join( ',', map { $_->id } @{ $c->stash->{missing_details_bodies} } )
- if $body_string && @{ $c->stash->{missing_details_bodies} };
$report->bodies_str($body_string);
+ # Record any body IDs which might have meant to match, but had no contact
+ if ($body_string && @{ $c->stash->{missing_details_bodies} }) {
+ my $missing = join( ',', map { $_->id } @{ $c->stash->{missing_details_bodies} } );
+ $report->bodies_missing($missing);
+ }
}
my @extra;
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index b3e907d92..88794ee52 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -104,6 +104,8 @@ __PACKAGE__->add_columns(
{ data_type => "integer", default_value => 0, is_nullable => 1 },
"subcategory",
{ data_type => "text", is_nullable => 1 },
+ "bodies_missing",
+ { data_type => "text", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->has_many(
@@ -132,8 +134,8 @@ __PACKAGE__->belongs_to(
);
-# Created by DBIx::Class::Schema::Loader v0.07035 @ 2014-07-31 15:57:02
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:EvD4sS1mdJJyI1muZ4TrCw
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-08-13 16:33:38
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Go+T9oFRfwQ1Ag89qPpF/g
# Add fake relationship to stored procedure table
__PACKAGE__->has_one(
@@ -402,7 +404,7 @@ sub check_for_errors {
$errors{bodies} = _('No council selected')
unless $self->bodies_str
- && $self->bodies_str =~ m/^(?:-1|[\d,]+(?:\|[\d,]+)?)$/;
+ && $self->bodies_str =~ m/^(?:-1|[\d,]+)$/;
if ( !$self->name || $self->name !~ m/\S/ ) {
$errors{name} = _('Please enter your name');
@@ -450,8 +452,7 @@ sub confirm {
sub bodies_str_ids {
my $self = shift;
return unless $self->bodies_str;
- (my $bodies = $self->bodies_str) =~ s/\|.*$//;
- my @bodies = split( /,/, $bodies );
+ my @bodies = split( /,/, $self->bodies_str );
return \@bodies;
}
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 0aa7c8b3a..da80e5b9c 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -320,15 +320,20 @@ sub send_reports {
$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(
+ my @bodies = split /,/, $row->bodies_str;
+ my $bodies = FixMyStreet::App->model("DB::Body")->search(
{ id => \@bodies },
{ order_by => 'name' },
);
- $missing = FixMyStreet::App->model("DB::Body")->find($missing) if $missing;
+
+ my $missing;
+ if ($row->bodies_missing) {
+ my @missing = FixMyStreet::App->model("DB::Body")->search(
+ { id => [ split /,/, $row->bodies_missing ] },
+ { order_by => 'name' }
+ )->get_column('name')->all;
+ $missing = join(' / ', @missing) if @missing;
+ }
my @dear;
my %reporters = ();
@@ -400,7 +405,7 @@ sub send_reports {
$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)
+ . 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)
. " ]\n\n";
}
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index 0a5f63b05..82569d72a 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -457,7 +457,8 @@ foreach my $test ( {
email_count => 1,
to => qr'Gloucestershire County Council" <2226@example',
dear => qr'Dear Gloucestershire County Council,',
- body => $body_ids{2226} . '|' . $body_ids{2649},
+ body => $body_ids{2226},
+ body_missing => $body_ids{2649},
missing => qr'problem might be the responsibility of Fife.*Council'ms,
}, {
%common,
@@ -529,6 +530,7 @@ foreach my $test ( {
$problem->discard_changes;
$problem->update( {
bodies_str => $test->{ body },
+ bodies_missing => $test->{ body_missing },
state => 'confirmed',
confirmed => \'current_timestamp',
whensent => $test->{ unset_whendef } ? undef : \'current_timestamp',