aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-12-19 14:51:01 +0000
committerMatthew Somerville <matthew@mysociety.org>2012-12-19 14:51:01 +0000
commit83eda5d0eaa433c3b033cfa9a2a94d4dae652ffe (patch)
treea52a99ce60c21612df848aa1ef4d5cc05af0f66b
parent87ffec227a0383ee200aecd04fbc6adb6213a831 (diff)
Don't try and set empty area IDs.
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm18
1 files changed, 11 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 676e735dd..0fd98733f 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -233,9 +233,11 @@ sub bodies : Path('bodies') : Args(0) {
my $params = $c->forward('body_params');
my $body = $c->model('DB::Body')->create( $params );
my $area_ids = $c->req->params->{area_ids};
- $area_ids = [ $area_ids ] unless ref $area_ids;
- foreach (@$area_ids) {
- $c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } );
+ if ($area_ids) {
+ $area_ids = [ $area_ids ] unless ref $area_ids;
+ foreach (@$area_ids) {
+ $c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } );
+ }
}
$c->stash->{updated} = _('New body added');
@@ -374,10 +376,12 @@ sub update_contacts : Private {
my @current = $c->stash->{body}->body_areas->all;
my %current = map { $_->area_id => 1 } @current;
my $area_ids = $c->req->params->{area_ids};
- $area_ids = [ $area_ids ] unless ref $area_ids;
- foreach (@$area_ids) {
- $c->model('DB::BodyArea')->find_or_create( { body => $c->stash->{body}, area_id => $_ } );
- delete $current{$_};
+ if ($area_ids) {
+ $area_ids = [ $area_ids ] unless ref $area_ids;
+ foreach (@$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;