diff options
Diffstat (limited to 'perllib')
20 files changed, 108 insertions, 126 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 8c37f0f2e..d5bce9283 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -569,7 +569,7 @@ sub search_reports : Path('search_reports') { -or => $query, }, { - -select => [ 'me.*', qw/problem.council problem.state/ ], + -select => [ 'me.*', qw/problem.bodies_str problem.state/ ], prefetch => [qw/user problem/], order_by => [\"(me.state='hidden')",\"(problem.state='hidden')",'me.created'] } diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index 00220deff..a355606f4 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -109,7 +109,7 @@ sub index : Path : Args(0) { $c->stash->{category} = $c->req->param('category'); my %where = ( - council => $council, # XXX This will break in a two tier council. Restriction needs looking at... + bodies_str => $council, # XXX This will break in a two tier council. Restriction needs looking at... 'problem.state' => [ FixMyStreet::DB::Result::Problem->visible_states() ], ); $where{areas} = { 'like', '%,' . $c->stash->{ward} . ',%' } diff --git a/perllib/FixMyStreet/App/Controller/JSON.pm b/perllib/FixMyStreet/App/Controller/JSON.pm index f3607341a..1a7c1915b 100644 --- a/perllib/FixMyStreet/App/Controller/JSON.pm +++ b/perllib/FixMyStreet/App/Controller/JSON.pm @@ -92,7 +92,7 @@ sub problems : Local { my @problems = $c->cobrand->problems->search( $query, { order_by => { -asc => 'confirmed' }, columns => [ - 'id', 'title', 'council', 'category', + 'id', 'title', 'bodies_str', 'category', 'detail', 'name', 'anonymous', 'confirmed', 'whensent', 'service', 'latitude', 'longitude', 'used_map', @@ -100,23 +100,13 @@ sub problems : Local { ] } ); - my @councils; foreach my $problem (@problems) { $problem->name( '' ) if $problem->anonymous == 1; $problem->service( 'Web interface' ) if $problem->service eq ''; - if ($problem->council) { - (my $council = $problem->council) =~ s/\|.*//g; - my @council_ids = split /,/, $council; - push(@councils, @council_ids); - $problem->council( \@council_ids ); - } - } - @councils = uniq @councils; - my $areas_info = mySociety::MaPit::call('areas', \@councils); - foreach my $problem (@problems) { - if ($problem->council) { - my @council_names = map { $areas_info->{$_}->{name} } @{$problem->council} ; - $problem->council( join(' and ', @council_names) ); + my $bodies = $problem->bodies; + if (keys %$bodies) { + my @body_names = map { $_->name } values %$bodies; + $problem->bodies_str( join(' and ', @body_names) ); } } diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm index b1e685c1c..62cdaffaf 100644 --- a/perllib/FixMyStreet/App/Controller/Open311.pm +++ b/perllib/FixMyStreet/App/Controller/Open311.pm @@ -164,11 +164,11 @@ sub get_services : Private { if ($lat || $lon) { my $area_types = $c->cobrand->area_types; - my $all_councils = mySociety::MaPit::call('point', + my $all_areas = mySociety::MaPit::call('point', "4326/$lon,$lat", type => $area_types); $categories = $categories->search( { - 'body.area_id' => [ keys %$all_councils ], + 'body.area_id' => [ keys %$all_areas ], }, { join => 'body' } ); } @@ -223,19 +223,11 @@ sub output_requests : Private { ); my @problemlist; - my @councils; while ( my $problem = $problems->next ) { my $id = $problem->id; $problem->service( 'Web interface' ) unless $problem->service; - if ($problem->council) { - (my $council = $problem->council) =~ s/\|.*//g; - my @council_ids = split(/,/, $council); - push(@councils, @council_ids); - $problem->council( \@council_ids ); - } - $problem->state( $statusmap{$problem->state} ); my $request = @@ -256,7 +248,7 @@ sub output_requests : Private { 'service_code' => [ $problem->category ], 'service_name' => [ $problem->category ], # 'service_notice' => [ {} ], - 'agency_responsible' => $problem->council , # FIXME Not according to Open311 v2 + 'agency_responsible' => $problem->bodies , # FIXME Not according to Open311 v2 # 'zipcode' => [ {} ], 'interface_used' => [ $problem->service ], # Not in Open311 v2 }; @@ -288,12 +280,12 @@ sub output_requests : Private { } push(@problemlist, $request); } - my $areas_info = mySociety::MaPit::call('areas', \@councils); + foreach my $request (@problemlist) { if ($request->{agency_responsible}) { - my @council_names = map { $areas_info->{$_}->{name} } @{$request->{agency_responsible}} ; + my @body_names = map { $_->name } values %{$request->{agency_responsible}} ; $request->{agency_responsible} = - [ {'recipient' => [ @council_names ] } ]; + [ {'recipient' => [ @body_names ] } ]; } } $c->forward( 'format_output', [ { @@ -319,7 +311,7 @@ sub get_requests : Private { service_request_id => [ '=', 'id' ], service_code => [ '=', 'category' ], status => [ 'IN', 'state' ], - agency_responsible => [ '~', 'council' ], + agency_responsible => [ '~', 'bodies_str' ], interface_used => [ '=', 'service' ], has_photo => [ '=', 'photo' ], ); diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 2c56cd182..41aee3869 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -147,7 +147,7 @@ sub format_problem_for_display : Private { $c->stash->{add_alert} = 1; } - $c->stash->{extra_name_info} = $problem->council && $problem->council eq '2482' ? 1 : 0; + $c->stash->{extra_name_info} = $problem->bodies_str && $problem->bodies_str eq '2482' ? 1 : 0; $c->forward('generate_map_tags'); @@ -187,11 +187,10 @@ sub delete :Local :Args(1) { return $c->res->redirect($uri) unless $c->user_exists; - my $council = $c->user->obj->from_body; - return $c->res->redirect($uri) unless $council; + my $body = $c->user->obj->from_body; + return $c->res->redirect($uri) unless $body; - my %councils = map { $_ => 1 } @{$p->councils}; - return $c->res->redirect($uri) unless $councils{$council}; + return $c->res->redirect($uri) unless $p->bodies->{$body}; $p->state('hidden'); $p->lastupdate( \'ms_current_timestamp()' ); diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index bb8f8f03f..0cb56d67a 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -587,7 +587,7 @@ sub setup_categories_and_bodies : Private { = $c # ->model('DB::Contact') # ->not_deleted # - ->search( { body => [ keys %bodies ] } ) + ->search( { body_id => [ keys %bodies ] } ) ->all; # variables to populate @@ -816,7 +816,7 @@ sub process_report : Private { if ( $c->cobrand->moniker eq 'emptyhomes' ) { $bodies = join( ',', @{ $c->stash->{bodies_to_list} } ) || -1; - $report->bodies( $bodies ); + $report->bodies_str( $bodies ); } elsif ( $first_area->{id} == COUNCIL_ID_BARNET ) { @@ -824,14 +824,14 @@ sub process_report : Private { unless ( exists Utils::barnet_categories()->{ $report->category } ) { $c->stash->{field_errors}->{category} = _('Please choose a category'); } - $report->bodies( $first_area->{id} ); + $report->bodies_str( $first_area->{id} ); } elsif ( $first_area->{id} != COUNCIL_ID_BROMLEY && $first_area->{type} eq 'LBO') { unless ( Utils::london_categories()->{ $report->category } ) { $c->stash->{field_errors}->{category} = _('Please choose a category'); } - $report->area( $first_area->{id} ); + $report->bodies_str( $first_area->{id} ); } elsif ( $report->category ) { @@ -842,14 +842,14 @@ sub process_report : Private { ->not_deleted # ->search( { - body => [ keys %$bodies ], + body_id => [ keys %$bodies ], category => $report->category } )->all; unless ( @contacts ) { $c->stash->{field_errors}->{category} = _('Please choose a category'); - $report->bodies( -1 ); + $report->bodies_str( -1 ); return 1; } @@ -860,7 +860,7 @@ sub process_report : Private { $body_string .= '|' . join( ',', @{ $c->stash->{missing_details_bodies} } ) if $body_string && @{ $c->stash->{missing_details_bodies} }; - $report->bodies($body_string); + $report->bodies_str($body_string); my @extra = (); my $metas = $contacts[0]->extra; @@ -897,7 +897,7 @@ sub process_report : Private { # If we're here, we've been submitted somewhere # where we have no contact information at all. - $report->bodies( -1 ); + $report->bodies_str( -1 ); } @@ -1016,7 +1016,7 @@ sub save_user_and_report : Private { $report->category( _('Other') ) unless $report->category; # Set unknown to DB unknown - $report->bodies( undef ) if $report->bodies eq '-1'; + $report->bodies_str( undef ) if $report->bodies_str eq '-1'; # if there is a Message Manager message ID, pass it back to the client view if ($c->cobrand->moniker eq 'fixmybarangay' && $c->req->param('external_source_id')=~/^\d+$/) { diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index c3843c9af..4467a7036 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -201,14 +201,14 @@ sub process_update : Private { if ( $params{state} ) { $params{state} = 'fixed - council' - if $params{state} eq 'fixed' && $c->user && $c->user->belongs_to_body( $update->problem->council ); + if $params{state} eq 'fixed' && $c->user && $c->user->belongs_to_body( $update->problem->bodies_str ); $update->problem_state( $params{state} ); } my @extra; # Next function fills this, but we don't need it here. # This is just so that the error checkign for these extra fields runs. # TODO Use extra here as it is used on reports. - $c->cobrand->process_extras( $c, $update->problem->council, \@extra ); + $c->cobrand->process_extras( $c, $update->problem->bodies_str, \@extra ); if ( $c->req->param('fms_extra_title') ) { my %extras = (); @@ -246,7 +246,7 @@ sub check_for_errors : Private { # they have to be an authority user to update the state if ( $c->req->param('state') ) { my $error = 0; - $error = 1 unless $c->user && $c->user->belongs_to_body( $c->stash->{update}->problem->council ); + $error = 1 unless $c->user && $c->user->belongs_to_body( $c->stash->{update}->problem->bodies_str ); my $state = $c->req->param('state'); $error = 1 unless ( grep { $state eq $_ } ( qw/confirmed closed fixed investigating planned/, 'in progress', 'fixed', 'fixed - user', 'fixed - council' ) ); diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index ec41dc17f..ec722fd6f 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -325,7 +325,7 @@ sub load_and_group_problems : Private { }; if ($c->stash->{ward}) { $where->{areas} = { 'like', '%,' . $c->stash->{ward}->{id} . ',%' }; - $where->{council} = [ + $where->{bodies_str} = [ undef, $c->stash->{council}->{id}, { 'like', $c->stash->{council}->{id} . ',%' }, @@ -336,7 +336,7 @@ sub load_and_group_problems : Private { $where->{'lower(external_body)'} = lc $c->stash->{council}->{name}; } elsif ($c->stash->{council}) { $where->{areas} = { 'like', '%,' . $c->stash->{council}->{id} . ',%' }; - $where->{council} = [ + $where->{bodies_str} = [ undef, $c->stash->{council}->{id}, { 'like', $c->stash->{council}->{id} . ',%' }, @@ -347,7 +347,7 @@ sub load_and_group_problems : Private { $where, { columns => [ - 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', + 'id', 'bodies_str', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', #{ duration => { extract => "epoch from current_timestamp-lastupdate" } }, #{ age => { extract => "epoch from current_timestamp-confirmed" } }, { confirmed => { extract => 'epoch from confirmed' } }, @@ -364,7 +364,7 @@ sub load_and_group_problems : Private { my ( %problems, @pins ); my $re_councils = join('|', keys %{$c->stash->{areas_info}}); - my @cols = ( 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'confirmed', 'whensent', 'lastupdate', 'photo' ); + my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'confirmed', 'whensent', 'lastupdate', 'photo' ); while ( my @problem = $problems->next ) { my %problem = zip @cols, @problem; $problem{is_fixed} = FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}}; @@ -374,18 +374,19 @@ sub load_and_group_problems : Private { add_row( \%problem, 0, \%problems, \@pins ); next; } - if ( !$problem{council} ) { - # Problem was not sent to any council, add to possible councils - $problem{councils} = 0; + if ( !$problem{bodies_str} ) { + # Problem was not sent to any body, add to possible councils XXX + $problem{bodies} = 0; while ($problem{areas} =~ /,($re_councils)(?=,)/g) { add_row( \%problem, $1, \%problems, \@pins ); } } else { - # Add to councils it was sent to - (my $council = $problem{council}) =~ s/\|.*$//; - my @council = split( /,/, $council ); - $problem{councils} = scalar @council; - foreach ( @council ) { + # Add to bodies it was sent to + # XXX Assumes body ID matches "council ID" + (my $bodies = $problem{bodies_str}) =~ s/\|.*$//; + my @bodies = split( /,/, $bodies ); + $problem{bodies} = scalar @bodies; + foreach ( @bodies ) { next if $_ != $c->stash->{council}->{id}; add_row( \%problem, $_, \%problems, \@pins ); } diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index baaa3b927..b275cfcf7 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -257,7 +257,7 @@ sub add_row : Private { my $hashref_restriction = $c->cobrand->site_restriction; my $base_url = $c->cobrand->base_url; - if ( $hashref_restriction && $hashref_restriction->{council} && $row->{council} && $row->{council} ne $hashref_restriction->{council} ) { + if ( $hashref_restriction && $hashref_restriction->{council} && $row->{bodies_str} && $row->{bodies_str} ne $hashref_restriction->{council} ) { $base_url = $c->config->{BASE_URL}; } my $url = $base_url . $link; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 994a245a0..2e3fae72d 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -600,10 +600,10 @@ Generate a set of options for council rss alerts. =cut sub council_rss_alert_options { - my ( $self, $all_councils, $c ) = @_; + my ( $self, $all_areas, $c ) = @_; my ( @options, @reported_to_options ); - foreach (values %$all_councils) { + foreach (values %$all_areas) { $_->{short_name} = $self->short_name( $_ ); ( $_->{id_name} = $_->{short_name} ) =~ tr/+/_/; push @options, { diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm index b3dbad089..51f368957 100644 --- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm +++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm @@ -12,7 +12,7 @@ sub council_url { return 'lichfielddc'; } # Different to councils parent due to this being a two-tier council. If we get # more, this can be genericised in the parent. sub problems_clause { - return { council => { like => '%2434%' } }; + return { bodies_str => { like => '%2434%' } }; } # FIXME - need to double check this is all correct @@ -27,10 +27,10 @@ sub disambiguate_location { } # If we ever link to a county problem report, needs to be to main FixMyStreet +# XXX Assumes body ID equals mapit area ID sub base_url_for_report { my ( $self, $report ) = @_; - my %councils = map { $_ => 1 } @{$report->councils}; - if ( $councils{2434} ) { + if ( $report->bodies->{2434} ) { return $self->base_url; } else { return FixMyStreet->config('BASE_URL'); diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm index e68d13715..2ed5bffe3 100644 --- a/perllib/FixMyStreet/Cobrand/UK.pm +++ b/perllib/FixMyStreet/Cobrand/UK.pm @@ -203,17 +203,17 @@ sub reports_body_check { sub council_rss_alert_options { my $self = shift; - my $all_councils = shift; - my $c = shift; + my $all_areas = shift; + my $c = shift; my %councils = map { $_ => 1 } @{$self->area_types}; - my $num_councils = scalar keys %$all_councils; + my $num_councils = scalar keys %$all_areas; my ( @options, @reported_to_options ); if ( $num_councils == 1 or $num_councils == 2 ) { my ($council, $ward); - foreach (values %$all_councils) { + foreach (values %$all_areas) { if ($councils{$_->{type}}) { $council = $_; $council->{short_name} = $self->short_name( $council ); @@ -252,7 +252,7 @@ sub council_rss_alert_options { } elsif ( $num_councils == 4 ) { # Two-tier council my ($county, $district, $c_ward, $d_ward); - foreach (values %$all_councils) { + foreach (values %$all_areas) { $_->{short_name} = $self->short_name( $_ ); ( $_->{id_name} = $_->{short_name} ) =~ tr/+/_/; if ($_->{type} eq 'CTY') { @@ -323,7 +323,7 @@ sub council_rss_alert_options { }; } else { - throw Error::Simple('An area with three tiers of council? Impossible! '. join('|',keys %$all_councils)); + throw Error::Simple('An area with three tiers of council? Impossible! '. join('|',keys %$all_areas)); } return ( \@options, @reported_to_options ? \@reported_to_options : undef ); diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index c7eaf8da0..2b4385a98 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -13,7 +13,7 @@ sub is_council { sub site_restriction { my $self = shift; - return { council => sprintf('%d', $self->council_id) }; + return { bodies_str => sprintf('%d', $self->council_id) }; } sub site_key { my $self = shift; @@ -27,7 +27,7 @@ sub restriction { # Different function to site_restriction due to two-tier use sub problems_clause { my $self = shift; - return { council => sprintf('%d', $self->council_id) }; + return { bodies_str => sprintf('%d', $self->council_id) }; } sub problems { @@ -54,7 +54,7 @@ sub enter_postcode_text { sub area_check { my ( $self, $params, $context ) = @_; - my $councils = $params->{all_councils}; + my $councils = $params->{all_areas}; my $council_match = defined $councils->{$self->council_id}; if ($council_match) { return 1; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index ae5815143..2d65c8789 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -24,7 +24,7 @@ __PACKAGE__->add_columns( { data_type => "double precision", is_nullable => 0 }, "longitude", { data_type => "double precision", is_nullable => 0 }, - "council", + "bodies_str", { data_type => "text", is_nullable => 1 }, "areas", { data_type => "text", is_nullable => 0 }, @@ -122,8 +122,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-10 15:33:48 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YZzkUjX7Dsxcsm4bXZjIYg +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-13 15:13:48 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:H2P3Og37G569nQdQA1IWaA # Add fake relationship to stored procedure table __PACKAGE__->has_one( @@ -333,9 +333,9 @@ sub check_for_errors { $errors{detail} = _('Please enter some details') unless $self->detail =~ m/\S/; - $errors{council} = _('No council selected') - unless $self->council - && $self->council =~ m/^(?:-1|[\d,]+(?:\|[\d,]+)?)$/; + $errors{bodies} = _('No council selected') + unless $self->bodies_str + && $self->bodies_str =~ m/^(?:-1|[\d,]+(?:\|[\d,]+)?)$/; if ( !$self->name || $self->name !~ m/\S/ ) { $errors{name} = _('Please enter your name'); @@ -388,18 +388,19 @@ sub confirm { return 1; } -=head2 councils +=head2 bodies -Returns an arrayref of councils to which a report was sent. +Returns an arrayref of bodies to which a report was sent. =cut -sub councils { +sub bodies($) { my $self = shift; - return [] unless $self->council; - (my $council = $self->council) =~ s/\|.*$//; - my @council = split( /,/, $council ); - return \@council; + return [] unless $self->bodies_str; + (my $bodies = $self->bodies_str) =~ s/\|.*$//; + my @bodies = split( /,/, $bodies ); + @bodies = FixMyStreet::App->model('DB::Body')->search({ id => \@bodies })->all; + return { map { $_->id => $_ } @bodies }; } =head2 url @@ -555,19 +556,18 @@ sub body { if ($problem->external_body) { $body = $problem->external_body; } else { - my $councils = $problem->councils; - my $areas_info = mySociety::MaPit::call('areas', $councils); + my $bodies = $problem->bodies; $body = join( _(' and '), map { - my $name = $areas_info->{$_}->{name}; + my $name = $_->name; if (mySociety::Config::get('AREA_LINKS_FROM_PROBLEMS')) { '<a href="' - . $c->uri_for( '/reports/' . $c->cobrand->short_name( $areas_info->{$_} ) ) + # XXX . $c->uri_for( '/reports/' . $c->cobrand->short_name( $areas_info->{$_} ) ) . '">' . $name . '</a>'; } else { $name; } - } @$councils + } values %$bodies ); } return $body; diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index 468df2654..be1f6578b 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -89,7 +89,7 @@ sub email_alerts ($) { } my $url = $cobrand->base_url( $row->{alert_cobrand_data} ); - if ( $hashref_restriction && $hashref_restriction->{council} && $row->{council} ne $hashref_restriction->{council} ) { + if ( $hashref_restriction && $hashref_restriction->{bodies_str} && $row->{bodies_str} ne $hashref_restriction->{bodies_str} ) { $url = mySociety::Config::get('BASE_URL'); } # this is currently only for new_updates @@ -166,7 +166,7 @@ sub email_alerts ($) { }; my $states = "'" . join( "', '", FixMyStreet::DB::Result::Problem::visible_states() ) . "'"; my %data = ( template => $template, data => '', alert_id => $alert->id, alert_email => $alert->user->email, lang => $alert->lang, cobrand => $alert->cobrand, cobrand_data => $alert->cobrand_data ); - my $q = "select problem.id, problem.council, problem.postcode, problem.geocode, problem.title from problem_find_nearby(?, ?, ?) as nearby, problem, users + my $q = "select problem.id, problem.bodies_str, problem.postcode, problem.geocode, problem.title from problem_find_nearby(?, ?, ?) as nearby, problem, users where nearby.problem_id = problem.id and problem.user_id = users.id and problem.state in ($states) @@ -183,7 +183,7 @@ sub email_alerts ($) { parameter => $row->{id}, } ); my $url = $cobrand->base_url( $alert->cobrand_data ); - if ( $hashref_restriction && $hashref_restriction->{council} && $row->{council} ne $hashref_restriction->{council} ) { + if ( $hashref_restriction && $hashref_restriction->{bodies_str} && $row->{bodies_str} ne $hashref_restriction->{bodies_str} ) { $url = mySociety::Config::get('BASE_URL'); } $data{data} .= $url . "/report/" . $row->{id} . " - $row->{title}\n\n"; diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 4d8004024..16eca144d 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, - bodies => { '!=', undef }, + bodies_str => { '!=', undef }, } ); my (%notgot, %note); @@ -292,7 +292,7 @@ sub send_reports { my ( $sender_count ); if ($site eq 'emptyhomes') { - my $body = $row->bodies; + 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}; @@ -302,7 +302,7 @@ sub send_reports { # XXX Needs locks! # XXX Only copes with at most one missing body - my ($bodies, $missing) = $row->bodies =~ /^([\d,]+)(?:\|(\d+))?/; + my ($bodies, $missing) = $row->bodies_str =~ /^([\d,]+)(?:\|(\d+))?/; my @bodies = split(/,/, $bodies); $bodies = FixMyStreet::App->model("DB::Body")->search({ id => \@bodies }); $missing = FixMyStreet::App->model("DB::Body")->find($missing); @@ -362,7 +362,7 @@ sub send_reports { if (mySociety::Config::get('STAGING_SITE')) { # 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 ) { + unless ( grep { $row->bodies_str eq $_ } @testing_bodies ) { %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|NI)/ } keys %reporters; unless (%reporters) { %reporters = ( 'FixMyStreet::SendReport::Email' => FixMyStreet::SendReport::Email->new() ); @@ -424,7 +424,7 @@ sub send_reports { my $unsent = FixMyStreet::App->model("DB::Problem")->search( { state => [ 'confirmed', 'fixed' ], whensent => undef, - bodies => { '!=', undef }, + bodies_str => { '!=', undef }, send_fail_count => { '>', 0 } } ); while (my $row = $unsent->next) { diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index a39760509..5277b639a 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -26,7 +26,7 @@ sub build_recipient_list { unless ($confirmed) { $all_confirmed = 0; - $note = 'Body ' . $row->bodies . ' deleted' + $note = 'Body ' . $row->bodies_str . ' deleted' unless $note; $body_email = 'N/A' unless $body_email; $self->unconfirmed_counts->{$body_email}{$row->category}++; @@ -45,7 +45,7 @@ sub get_template { my ( $self, $row ) = @_; my $template = 'submit.txt'; - $template = 'submit-brent.txt' if $row->bodies eq 2488 || $row->bodies eq 2237; + $template = 'submit-brent.txt' if $row->bodies_str eq 2488 || $row->bodies_str 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; diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index f0a76d0fb..c6d838998 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -40,7 +40,7 @@ sub send { my $revert = 0; # Extra bromley fields - if ( $row->bodies == 2482 ) { + if ( $row->bodies_str == 2482 ) { $revert = 1; @@ -90,12 +90,12 @@ sub send { ); # non standard west berks end points - if ( $row->bodies =~ /2619/ ) { + if ( $row->bodies_str =~ /2619/ ) { $open311->endpoints( { services => 'Services', requests => 'Requests' } ); } # required to get round issues with CRM constraints - if ( $row->bodies =~ /2218/ ) { + if ( $row->bodies_str =~ /2218/ ) { $row->user->name( $row->user->id . ' ' . $row->user->name ); $revert = 1; } @@ -124,7 +124,7 @@ sub send { } else { $result *= 1; # temporary fix to resolve some issues with west berks - if ( $row->bodies =~ /2619/ ) { + if ( $row->bodies_str =~ /2619/ ) { $result *= 0; } } diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index 7f81c0fc2..30807c4e2 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -519,11 +519,11 @@ sub get_ok_json { return decode_json( $res->content ); } -sub delete_problems_for_council { +sub delete_problems_for_body { my $mech = shift; - my $council = shift; + my $body = shift; - my $reports = FixMyStreet::App->model('DB::Problem')->search( { council => $council } ); + my $reports = FixMyStreet::App->model('DB::Problem')->search( { bodies_str => $body } ); if ( $reports ) { for my $r ( $reports->all ) { $r->comments->delete; @@ -532,8 +532,8 @@ sub delete_problems_for_council { } } -sub create_problems_for_council { - my ( $mech, $count, $council, $title, $params ) = @_; +sub create_problems_for_body { + my ( $mech, $count, $body, $title, $params ) = @_; my $dt = $params->{dt} || DateTime->now(); @@ -549,11 +549,11 @@ sub create_problems_for_council { while ($count) { my $default_params = { postcode => 'SW1A 1AA', - council => $council, + bodies_str => $body, areas => ',105255,11806,11828,2247,2504,', category => 'Other', - title => "$title Test $count for $council", - detail => "$title Test $count for $council Detail", + title => "$title Test $count for $body", + detail => "$title Test $count for $body Detail", used_map => 't', name => 'Test User', anonymous => 'f', diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index 81b50406b..4e64e350f 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -14,7 +14,7 @@ has verbose => ( is => 'ro', default => 0 ); sub fetch { my $self = shift; - my $councils = FixMyStreet::App->model('DB::Body')->search( + my $bodies = FixMyStreet::App->model('DB::Body')->search( { send_method => 'Open311', send_comments => 1, @@ -23,24 +23,24 @@ sub fetch { } ); - while ( my $council = $councils->next ) { + while ( my $body = $bodies->next ) { my $o = Open311->new( - endpoint => $council->endpoint, - api_key => $council->api_key, - jurisdiction => $council->jurisdiction, + endpoint => $body->endpoint, + api_key => $body->api_key, + jurisdiction => $body->jurisdiction, ); - if ( $council->area_id =~ /2482/ ) { + if ( $body->area_id == 2482 ) { my $endpoints = $o->endpoints; $endpoints->{update} = 'update.xml'; $endpoints->{service_request_updates} = 'update.xml'; $o->endpoints( $endpoints ); } - $self->suppress_alerts( $council->suppress_alerts ); - $self->system_user( $council->comment_user ); - $self->update_comments( $o, { areaid => $council->area_id }, ); + $self->suppress_alerts( $body->suppress_alerts ); + $self->system_user( $body->comment_user ); + $self->update_comments( $o, { areaid => $body->area_id }, ); } } @@ -83,7 +83,7 @@ sub update_comments { FixMyStreet::App->model('DB::Problem') ->search( { external_id => $request_id, - council => { like => '%' . $council_details->{areaid} . '%' }, + bodies_str => { like => '%' . $council_details->{areaid} . '%' }, } ); if (my $p = $problem->first) { |