diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Open311.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/LichfieldDC.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Body.pm | 19 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/BodyArea.pm | 32 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Body.pm | 17 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Barnet.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/TestMech.pm | 9 | ||||
-rw-r--r-- | perllib/Open311/GetServiceRequestUpdates.pm | 11 | ||||
-rw-r--r-- | perllib/Open311/PopulateServiceList.pm | 12 |
15 files changed, 123 insertions, 39 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index e64db0135..c9c3dc503 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -222,12 +222,15 @@ sub bodies : Path('bodies') : Args(0) { $c->stash->{edit_activity} = $edit_activity; - my $posted = $c->req->param('posted'); + my $posted = $c->req->param('posted') || ''; if ( $posted eq 'body' ) { $c->forward('check_token'); my $params = $c->forward('body_params'); - $c->model('DB::Body')->create( $params ); + my $body = $c->model('DB::Body')->create( $params ); + foreach ($c->req->params->{area_ids}) { + $c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } ); + } $c->stash->{updated} = _('New body added'); } @@ -350,6 +353,14 @@ sub update_contacts : Private { my $params = $c->forward( 'body_params' ); $c->stash->{body}->update( $params ); + my @current = $c->stash->{body}->body_areas->all; + my %current = map { $_->area_id => 1 } @current; + foreach ($c->req->params->{area_ids}) { + $c->model('DB::BodyArea')->find_or_create( { body => $c->stash->{body}, area_id => $_ } ); + delete $current{$_}; + } + # Remove any others + $c->stash->{body}->body_areas->search( { area_id => [ keys %current ] } )->delete; $c->stash->{updated} = _('Configuration updated - contacts will be generated automatically later'); } @@ -358,10 +369,9 @@ sub update_contacts : Private { sub body_params : Private { my ( $self, $c ) = @_; - my @fields = qw/name area_id endpoint jurisdiction api_key send_method send_comments suppress_alerts comment_user_id can_be_devolved/; + my @fields = qw/name endpoint jurisdiction api_key send_method send_comments suppress_alerts comment_user_id can_be_devolved/; my %defaults = map { $_ => '' } @fields; %defaults = ( %defaults, - area_id => undef, send_comments => 0, suppress_alerts => 0, comment_user_id => undef, @@ -398,7 +408,7 @@ sub lookup_body : Private { unless $body; $c->stash->{body} = $body; - my $example_postcode = mySociety::MaPit::call('area/example_postcode', $body->area_id); + my $example_postcode = mySociety::MaPit::call('area/example_postcode', $body->body_areas->first->area_id); if ($example_postcode && ! ref $example_postcode) { $c->stash->{example_pc} = $example_postcode; } diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index 3a66cf1e0..657751e5c 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -92,15 +92,18 @@ sub index : Path : Args(0) { # Set up the data for the dropdowns - my $council_detail = mySociety::MaPit::call('area', $body->area_id ); + # Just take the first area ID we find + my $area_id = $body->body_areas->first->area_id; + + my $council_detail = mySociety::MaPit::call('area', $area_id ); $c->stash->{council} = $council_detail; - my $children = mySociety::MaPit::call('area/children', $body->area_id, + my $children = mySociety::MaPit::call('area/children', $area_id, type => $c->cobrand->area_types_children, ); $c->stash->{children} = $children; - $c->stash->{all_areas} = { $body->area_id => $council_detail }; + $c->stash->{all_areas} = { $area_id => $council_detail }; $c->forward( '/report/new/setup_categories_and_bodies' ); # See if we've had anything from the dropdowns diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm index 62cdaffaf..3a6794325 100644 --- a/perllib/FixMyStreet/App/Controller/Open311.pm +++ b/perllib/FixMyStreet/App/Controller/Open311.pm @@ -168,8 +168,8 @@ sub get_services : Private { "4326/$lon,$lat", type => $area_types); $categories = $categories->search( { - 'body.area_id' => [ keys %$all_areas ], - }, { join => 'body' } ); + 'body_areas.area_id' => [ keys %$all_areas ], + }, { join => { 'body' => 'body_areas' } } ); } my @categories = $categories->search( undef, { diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 09e46ccef..c3525b2c9 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -580,7 +580,10 @@ sub setup_categories_and_bodies : Private { my $all_areas = $c->stash->{all_areas}; my $first_area = ( values %$all_areas )[0]; - my @bodies = $c->model('DB::Body')->search( { area_id => [ keys %$all_areas ] } )->all; + my @bodies = $c->model('DB::Body')->search( + { 'body_areas.area_id' => [ keys %$all_areas ] }, + { join => 'body_areas' } + )->all; my %bodies = map { $_->id => $_ } @bodies; my $first_body = ( values %bodies )[0]; diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 630409227..bf65fe1d5 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -99,7 +99,7 @@ sub ward : Path : Args(2) { $c, latitude => @$pins ? $pins->[0]{latitude} : 0, longitude => @$pins ? $pins->[0]{longitude} : 0, - area => $c->stash->{ward} ? $c->stash->{ward}->{id} : $c->stash->{body}->area_id, + area => $c->stash->{ward} ? $c->stash->{ward}->{id} : [ keys %{$c->stash->{body}->areas} ], pins => $pins, any_zoom => 1, ); @@ -109,7 +109,7 @@ sub ward : Path : Args(2) { # List of wards # Ignore external_body special body thing unless ($c->stash->{ward} || !$c->stash->{body}->id) { - my $children = mySociety::MaPit::call('area/children', [ $c->stash->{body}->area_id ], + my $children = mySociety::MaPit::call('area/children', [ $c->stash->{body}->body_areas->first->area_id ], type => $c->cobrand->area_types_children, ); unless ($children->{error}) { @@ -301,7 +301,7 @@ sub ward_check : Private { # Could be from RSS area, or body... my $parent_id; if ( $c->stash->{body} ) { - $parent_id = $c->stash->{body}->area_id; + $parent_id = $c->stash->{body}->body_areas->first->area_id; } else { $parent_id = $c->stash->{area}->{id}; } diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm index f9d5e3632..99797f9c9 100644 --- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm +++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm @@ -30,7 +30,7 @@ sub disambiguate_location { sub base_url_for_report { my ( $self, $report ) = @_; my $bodies = $report->bodies; - my %areas = map { $_->area_id => 1 } values %$bodies; + my %areas = map { %{$_->areas} } values %$bodies; if ( $areas{2434} ) { return $self->base_url; } else { diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm index 3ad58437e..ff613ffa8 100644 --- a/perllib/FixMyStreet/Cobrand/UK.pm +++ b/perllib/FixMyStreet/Cobrand/UK.pm @@ -34,7 +34,8 @@ sub disambiguate_location { sub _fallback_body_sender { my ( $self, $body, $category ) = @_; - my $area_info = mySociety::MaPit::call('area', $body->area_id); + my $first_area = $body->body_areas->first->area_id; + my $area_info = mySociety::MaPit::call('area', $first_area); return { method => 'London' } if $area_info->{type} eq 'LBO'; return { method => 'NI' } if $area_info->{type} eq 'LGD'; return { method => 'Email' }; @@ -43,11 +44,12 @@ sub _fallback_body_sender { sub process_extras { my $self = shift; my $ctx = shift; - my $area_id = shift; + my $body_id = shift; my $extra = shift; my $fields = shift || []; - if ( $area_id eq '2482' ) { + # XXX Hardcoded body ID matching mapit area ID + if ( $body_id eq '2482' ) { my @fields = ( 'fms_extra_title', @$fields ); for my $field ( @fields ) { my $value = $ctx->request->param( $field ); diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm index 73d763a6e..a4da74f80 100644 --- a/perllib/FixMyStreet/DB/Result/Body.pm +++ b/perllib/FixMyStreet/DB/Result/Body.pm @@ -18,8 +18,6 @@ __PACKAGE__->add_columns( is_nullable => 0, sequence => "body_id_seq", }, - "area_id", - { data_type => "integer", is_nullable => 0 }, "endpoint", { data_type => "text", is_nullable => 1 }, "jurisdiction", @@ -40,7 +38,12 @@ __PACKAGE__->add_columns( { data_type => "text", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); -__PACKAGE__->add_unique_constraint("body_area_id_key", ["area_id"]); +__PACKAGE__->has_many( + "body_areas", + "FixMyStreet::DB::Result::BodyArea", + { "foreign.body_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); __PACKAGE__->belongs_to( "comment_user", "FixMyStreet::DB::Result::User", @@ -66,8 +69,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-14 09:23:59 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tvTHtIa0GrtptadZYHEM1Q +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-14 17:54:33 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2Z3gCosNomCTcjrwWy/RNA sub url { my ( $self, $c ) = @_; @@ -75,4 +78,10 @@ sub url { return $c->uri_for( '/reports/' . $c->cobrand->short_name( $self ) ); } +sub areas { + my $self = shift; + my %ids = map { $_->area_id => 1 } $self->body_areas->all; + return \%ids; +} + 1; diff --git a/perllib/FixMyStreet/DB/Result/BodyArea.pm b/perllib/FixMyStreet/DB/Result/BodyArea.pm new file mode 100644 index 000000000..508203cc8 --- /dev/null +++ b/perllib/FixMyStreet/DB/Result/BodyArea.pm @@ -0,0 +1,32 @@ +use utf8; +package FixMyStreet::DB::Result::BodyArea; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; +__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn"); +__PACKAGE__->table("body_areas"); +__PACKAGE__->add_columns( + "body_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "area_id", + { data_type => "integer", is_nullable => 0 }, +); +__PACKAGE__->belongs_to( + "body", + "FixMyStreet::DB::Result::Body", + { id => "body_id" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-14 17:54:33 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jTU6Nu/MQEvg9o8Hf5YQUQ + + __PACKAGE__->set_primary_key(__PACKAGE__->columns); + +1; diff --git a/perllib/FixMyStreet/DB/ResultSet/Body.pm b/perllib/FixMyStreet/DB/ResultSet/Body.pm new file mode 100644 index 000000000..6802ed604 --- /dev/null +++ b/perllib/FixMyStreet/DB/ResultSet/Body.pm @@ -0,0 +1,17 @@ +package FixMyStreet::DB::ResultSet::Body; +use base 'DBIx::Class::ResultSet'; + +use strict; +use warnings; + +sub for_areas { + my ( $rs, @areas ) = @_; + + my $result = $rs->search( + { 'body_areas.area_id' => \@areas }, + { join => 'body_areas' } + ); + return $result; +} + +1; diff --git a/perllib/FixMyStreet/SendReport/Barnet.pm b/perllib/FixMyStreet/SendReport/Barnet.pm index 21d4a06a5..05ca20809 100644 --- a/perllib/FixMyStreet/SendReport/Barnet.pm +++ b/perllib/FixMyStreet/SendReport/Barnet.pm @@ -80,7 +80,7 @@ sub send { ? $h{query} : $nearest_postcode; # use given postcode if available # note: endpoint can be of form 'https://username:password@url' - my $body = FixMyStreet::App->model("DB::Body")->search( { area_id => COUNCIL_ID_BARNET} )->first; + my $body = FixMyStreet::App->model("DB::Body")->search( { 'body_areas.area_id' => COUNCIL_ID_BARNET }, { join => "body_areas" } )->first; if ($body and $body->endpoint) { $interface->set_proxy($body->endpoint); # Barnet web service doesn't like namespaces in the elements so use a prefix @@ -90,7 +90,7 @@ sub send { #$interface->outputxml(1); #$interface->no_dispatch(1); } else { - die "Barnet webservice FAIL: looks like you're missing some config data: no endpoint (URL) found for area_id=" . COUNCIL_ID_BARNET; + die "Barnet webservice FAIL: looks like you're missing some config data: no endpoint (URL) found for area ID " . COUNCIL_ID_BARNET; } eval { diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 5277b639a..b7c15a643 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -21,8 +21,8 @@ sub build_recipient_list { my ($body_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note ); - $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'; + $body_email = essex_contact($row->latitude, $row->longitude) if $body->areas->{2225}; + $body_email = oxfordshire_contact($row->latitude, $row->longitude) if $body->areas->{2237} && $body_email eq 'SPECIAL'; unless ($confirmed) { $all_confirmed = 0; diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index cc4e45f45..addbb1752 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -536,11 +536,18 @@ sub create_body_ok { my $self = shift; my ( $id, $name ) = @_; - my $params = { id => $id, area_id => $id, name => $name }; + my $params = { id => $id, name => $name }; my $body = FixMyStreet::App->model('DB::Body')->find_or_create($params); $body->update($params); # Make sure ok $body, "found/created user for $id $name"; + + FixMyStreet::App->model('DB::BodyArea')->find_or_create({ + area_id => $id, + body_id => $id, + }); + return $body; + } sub create_problems_for_body { diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index 875769eac..27cb21c3a 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -31,7 +31,7 @@ sub fetch { jurisdiction => $body->jurisdiction, ); - if ( $body->area_id == 2482 ) { + if ( $body->areas->{2482} ) { my $endpoints = $o->endpoints; $endpoints->{update} = 'update.xml'; $endpoints->{service_request_updates} = 'update.xml'; @@ -40,7 +40,7 @@ sub fetch { $self->suppress_alerts( $body->suppress_alerts ); $self->system_user( $body->comment_user ); - $self->update_comments( $o, { areaid => $body->area_id }, ); + $self->update_comments( $o, { areas => $body->areas }, ); } } @@ -55,7 +55,7 @@ sub update_comments { push @args, $self->start_date; push @args, $self->end_date; # default to asking for last 2 hours worth if not Bromley - } elsif ( $body_details->{areaid} != 2482 ) { + } elsif ( ! $body_details->{areas}->{2482} ) { my $end_dt = DateTime->now(); my $start_dt = $end_dt->clone; $start_dt->add( hours => -2 ); @@ -67,7 +67,7 @@ sub update_comments { my $requests = $open311->get_service_request_updates( @args ); unless ( $open311->success ) { - warn "Failed to fetch ServiceRequest Updates for " . $body_details->{areaid} . ":\n" . $open311->error + warn "Failed to fetch ServiceRequest Updates for " . join(",", keys %{$body_details->{areas}}) . ":\n" . $open311->error if $self->verbose; return 0; } @@ -83,7 +83,8 @@ sub update_comments { FixMyStreet::App->model('DB::Problem') ->search( { external_id => $request_id, - bodies_str => { like => '%' . $body_details->{areaid} . '%' }, + # XXX This assumes that areas will actually only be one area. + bodies_str => { like => '%' . join(",", keys %{$body_details->{areas}}) . '%' }, } ); if (my $p = $problem->first) { diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm index 8000378e3..bd90e10e9 100644 --- a/perllib/Open311/PopulateServiceList.pm +++ b/perllib/Open311/PopulateServiceList.pm @@ -42,8 +42,8 @@ sub process_body { my $list = $open311->get_service_list; unless ( $list ) { my $id = $self->_current_body->id; - my $area_id = $self->_current_body->area_id; - warn "Body $id for area $area_id - http://mapit.mysociety.org/area/$area_id.html - did not return a service list\n" + my $areas = join( ",", keys %{$self->_current_body->areas} ); + warn "Body $id for areas $areas - http://mapit.mysociety.org/areas/$areas.html - did not return a service list\n" if $self->verbose >= 1; return; } @@ -56,7 +56,7 @@ sub _check_endpoints { my $self = shift; # west berks end point not standard - if ( $self->_current_body->area_id == 2619 ) { + if ( $self->_current_body->areas->{2619} ) { $self->_current_open311->endpoints( { services => 'Services', @@ -82,7 +82,7 @@ sub process_services { sub process_service { my $self = shift; - my $category = $self->_current_body->area_id == 2218 ? + my $category = $self->_current_body->areas->{2218} ? $self->_current_service->{description} : $self->_current_service->{service_name}; @@ -226,7 +226,7 @@ sub _add_meta_to_contact { # we add these later on from bromley so don't list them here # as we don't want to display them - if ( $self->_current_body->area_id == 2482 ) { + if ( $self->_current_body->areas->{2482} ) { my %ignore = map { $_ => 1 } qw/ service_request_id_ext requested_datetime @@ -257,7 +257,7 @@ sub _normalize_service_name { # FIXME - at the moment it makes more sense to use the description # for cambridgeshire but need a more flexible way to set this - my $service_name = $self->_current_body->area_id == 2218 ? + my $service_name = $self->_current_body->areas->{2218} ? $self->_current_service->{description} : $self->_current_service->{service_name}; # remove trailing whitespace as it upsets db queries |