aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-12-12 16:48:27 +0000
committerMatthew Somerville <matthew@mysociety.org>2012-12-15 00:11:05 +0000
commitfa4947c017af7599699892c1c3a647fc61f971ed (patch)
tree71cf677abe1891f40a79fa2a1e606929ad8f7640
parent07b07d90cf666a06cb071ceebcecbd21d91e6b60 (diff)
Rename area_id on Contacts table to body_id.
Add foreign key constraint from contacts to body.
-rw-r--r--db/schema.sql24
-rw-r--r--db/schema_0029-rename_contacts_area_id.sql25
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm18
-rw-r--r--perllib/FixMyStreet/App/Controller/Open311.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm12
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm2
-rw-r--r--perllib/FixMyStreet/DB/Result/Body.pm10
-rw-r--r--perllib/FixMyStreet/DB/Result/Contact.pm16
-rw-r--r--perllib/FixMyStreet/DB/Result/ContactsHistory.pm6
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm2
-rw-r--r--perllib/FixMyStreet/SendReport/EmptyHomes.pm2
-rw-r--r--perllib/FixMyStreet/SendReport/NI.pm2
-rw-r--r--perllib/FixMyStreet/SendReport/Open311.pm2
-rw-r--r--perllib/Open311/PopulateServiceList.pm6
-rw-r--r--t/app/controller/admin.t4
-rw-r--r--t/app/controller/dashboard.t4
-rw-r--r--t/app/controller/report_new.t14
-rw-r--r--t/app/controller/report_new_open311.t4
-rw-r--r--t/app/model/problem.t16
-rw-r--r--t/app/sendreport/email.t2
-rw-r--r--t/open311/populate-service-list.t40
21 files changed, 118 insertions, 95 deletions
diff --git a/db/schema.sql b/db/schema.sql
index a829e68db..549222b1a 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -32,24 +32,10 @@ create function ms_current_timestamp()
end;
' language 'plpgsql';
-
--- users, but call the table person rather than user so we don't have to quote
--- its name in every statement....
--- create table person (
--- id serial not null primary key,
--- name text,
--- email text not null,
--- password text,
--- website text,
--- numlogins integer not null default 0
--- );
---
--- create unique index person_email_idx on person(email);
-
--- Who to send problems for a specific MaPit area ID to
+-- The contact for a category within a particular body
create table contacts (
id serial primary key,
- area_id integer not null,
+ body_id integer not null references body(id),
category text not null default 'Other',
email text not null,
confirmed boolean not null,
@@ -74,7 +60,7 @@ create table contacts (
api_key text default '',
send_method text
);
-create unique index contacts_area_id_category_idx on contacts(area_id, category);
+create unique index contacts_body_id_category_idx on contacts(body_id, category);
-- History of changes to contacts - automatically updated
-- whenever contacts is changed, using trigger below.
@@ -82,7 +68,7 @@ create table contacts_history (
contacts_history_id serial not null primary key,
contact_id integer not null,
- area_id integer not null,
+ body_id integer not null,
category text not null default 'Other',
email text not null,
confirmed boolean not null,
@@ -101,7 +87,7 @@ create table contacts_history (
create function contacts_updated()
returns trigger as '
begin
- insert into contacts_history (contact_id, area_id, category, email, editor, whenedited, note, confirmed, deleted) values (new.id, new.area_id, new.category, new.email, new.editor, new.whenedited, new.note, new.confirmed, new.deleted);
+ insert into contacts_history (contact_id, body_id, category, email, editor, whenedited, note, confirmed, deleted) values (new.id, new.body_id, new.category, new.email, new.editor, new.whenedited, new.note, new.confirmed, new.deleted);
return new;
end;
' language 'plpgsql';
diff --git a/db/schema_0029-rename_contacts_area_id.sql b/db/schema_0029-rename_contacts_area_id.sql
new file mode 100644
index 000000000..e28f73802
--- /dev/null
+++ b/db/schema_0029-rename_contacts_area_id.sql
@@ -0,0 +1,25 @@
+begin;
+
+ALTER TABLE contacts RENAME area_id TO body_id;
+ALTER TABLE contacts_history RENAME area_id TO body_id;
+ALTER INDEX contacts_area_id_category_idx RENAME TO contacts_body_id_category_idx;
+
+ALTER TABLE contacts ADD CONSTRAINT contacts_body_id_fkey
+ FOREIGN KEY (body_id) REFERENCES body(id);
+
+DROP TRIGGER contacts_update_trigger ON contacts;
+DROP TRIGGER contacts_insert_trigger ON contacts;
+DROP FUNCTION contacts_updated();
+create function contacts_updated()
+ returns trigger as '
+ begin
+ insert into contacts_history (contact_id, body_id, category, email, editor, whenedited, note, confirmed, deleted) values (new.id, new.body_id, new.category, new.email, new.editor, new.whenedited, new.note, new.confirmed, new.deleted);
+ return new;
+ end;
+' language 'plpgsql';
+create trigger contacts_update_trigger after update on contacts
+ for each row execute procedure contacts_updated();
+create trigger contacts_insert_trigger after insert on contacts
+ for each row execute procedure contacts_updated();
+
+commit;
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index fcbde1bd9..8c37f0f2e 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -233,15 +233,15 @@ sub council_list : Path('council_list') : Args(0) {
my $contacts = $c->model('DB::Contact')->search(
undef,
{
- select => [ 'area_id', { count => 'id' }, { count => \'case when deleted then 1 else null end' },
+ select => [ 'body_id', { count => 'id' }, { count => \'case when deleted then 1 else null end' },
{ count => \'case when confirmed then 1 else null end' } ],
- as => [qw/area_id c deleted confirmed/],
- group_by => [ 'area_id' ],
+ as => [qw/body_id c deleted confirmed/],
+ group_by => [ 'body_id' ],
result_class => 'DBIx::Class::ResultClass::HashRefInflator'
}
);
- my %council_info = map { $_->{area_id} => $_ } $contacts->all;
+ my %council_info = map { $_->{body_id} => $_ } $contacts->all;
my @no_info = grep { !$council_info{$_} } @councils_ids;
my @one_plus_deleted = grep { $council_info{$_} && $council_info{$_}->{deleted} } @councils_ids;
@@ -294,7 +294,7 @@ sub update_contacts : Private {
my $contact = $c->model('DB::Contact')->find_or_new(
{
- area_id => $c->stash->{area_id},
+ body_id => $c->stash->{area_id},
category => $category,
}
);
@@ -328,7 +328,7 @@ sub update_contacts : Private {
my $contacts = $c->model('DB::Contact')->search(
{
- area_id => $c->stash->{area_id},
+ body_id => $c->stash->{area_id},
category => { -in => \@categories },
}
);
@@ -390,7 +390,7 @@ sub display_contacts : Private {
my $area_id = $c->stash->{area_id};
my $contacts = $c->model('DB::Contact')->search(
- { area_id => $area_id },
+ { body_id => $area_id },
{ order_by => ['category'] }
);
@@ -450,7 +450,7 @@ sub council_edit : Path('council_edit') : Args(2) {
my $contact = $c->model('DB::Contact')->search(
{
- area_id => $area_id,
+ body_id => $area_id,
category => $category
}
)->first;
@@ -459,7 +459,7 @@ sub council_edit : Path('council_edit') : Args(2) {
my $history = $c->model('DB::ContactsHistory')->search(
{
- area_id => $area_id,
+ body_id => $area_id,
category => $category
},
{
diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm
index 040b0d3e6..54faf906a 100644
--- a/perllib/FixMyStreet/App/Controller/Open311.pm
+++ b/perllib/FixMyStreet/App/Controller/Open311.pm
@@ -168,7 +168,7 @@ sub get_services : Private {
"4326/$lon,$lat",
type => $area_types);
$categories = $categories->search( {
- area_id => [ keys %$all_councils ],
+ body_id => [ keys %$all_councils ],
} );
}
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 823b38e02..57cf1de49 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -584,7 +584,7 @@ sub setup_categories_and_councils : Private {
= $c #
->model('DB::Contact') #
->not_deleted #
- ->search( { area_id => [ keys %$all_councils ] } ) #
+ ->search( { body_id => [ keys %$all_councils ] } ) #
->all;
# variables to populate
@@ -600,7 +600,7 @@ sub setup_categories_and_councils : Private {
# add all areas found to the list
foreach (@contacts) {
- $area_ids_to_list{ $_->area_id } = 1;
+ $area_ids_to_list{ $_->body_id } = 1;
}
# set our own categories
@@ -638,7 +638,7 @@ sub setup_categories_and_councils : Private {
my %seen;
foreach my $contact (@contacts) {
- $area_ids_to_list{ $contact->area_id } = 1;
+ $area_ids_to_list{ $contact->body_id } = 1;
unless ( $seen{$contact->category} ) {
push @category_options, $contact->category;
@@ -839,7 +839,7 @@ sub process_report : Private {
->not_deleted #
->search(
{
- area_id => [ keys %$councils ],
+ body_id => [ keys %$councils ],
category => $report->category
}
)->all;
@@ -853,7 +853,7 @@ sub process_report : Private {
# construct the council string:
# 'x,x' - x are council IDs that have this category
# 'x,x|y,y' - x are council IDs that have this category, y council IDs with *no* contact
- my $council_string = join( ',', map { $_->area_id } @contacts );
+ my $council_string = join( ',', map { $_->body_id } @contacts );
$council_string .=
'|' . join( ',', @{ $c->stash->{missing_details_councils} } )
if $council_string && @{ $c->stash->{missing_details_councils} };
@@ -879,7 +879,7 @@ sub process_report : Private {
$report->non_public( 1 );
}
- $c->cobrand->process_extras( $c, $contacts[0]->area_id, \@extra );
+ $c->cobrand->process_extras( $c, $contacts[0]->body_id, \@extra );
if ( @extra ) {
$c->stash->{report_meta} = { map { $_->{name} => $_ } @extra };
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 808959784..e13d915af 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -657,7 +657,7 @@ sub get_council_sender {
if ( $council_config && $council_config->can_be_devolved ) {
# look up via category
- my $config = FixMyStreet::App->model("DB::Contact")->search( { area_id => $area_id, category => $category } )->first;
+ my $config = FixMyStreet::App->model("DB::Contact")->search( { body_id => $area_id, category => $category } )->first;
if ( $config->send_method ) {
return { method => $config->send_method, config => $config };
} else {
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm
index 76835cbde..6071ef33e 100644
--- a/perllib/FixMyStreet/DB/Result/Body.pm
+++ b/perllib/FixMyStreet/DB/Result/Body.pm
@@ -50,10 +50,16 @@ __PACKAGE__->belongs_to(
on_update => "CASCADE",
},
);
+__PACKAGE__->has_many(
+ "contacts",
+ "FixMyStreet::DB::Result::Contact",
+ { "foreign.body_id" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-12 16:29:16
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:7G4lkjrgUBXKmadSuK8emA
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-13 12:34:57
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YiDf4mhoPlG5cnxCIrqZxw
# You can replace this text with custom code or comments, and it will be preserved on regeneration
diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm
index 0fef2f56b..b9bfd8610 100644
--- a/perllib/FixMyStreet/DB/Result/Contact.pm
+++ b/perllib/FixMyStreet/DB/Result/Contact.pm
@@ -18,8 +18,8 @@ __PACKAGE__->add_columns(
is_nullable => 0,
sequence => "contacts_id_seq",
},
- "area_id",
- { data_type => "integer", is_nullable => 0 },
+ "body_id",
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
"category",
{ data_type => "text", default_value => "Other", is_nullable => 0 },
"email",
@@ -48,11 +48,17 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
-__PACKAGE__->add_unique_constraint("contacts_area_id_category_idx", ["area_id", "category"]);
+__PACKAGE__->add_unique_constraint("contacts_body_id_category_idx", ["body_id", "category"]);
+__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-10 15:33:48
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:T1jcv40rbTqZbwDziGTYCA
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-13 12:34:33
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:imXq3EtrC0FrQwj+E2xfBw
__PACKAGE__->filter_column(
extra => {
diff --git a/perllib/FixMyStreet/DB/Result/ContactsHistory.pm b/perllib/FixMyStreet/DB/Result/ContactsHistory.pm
index deb00fb95..7126d91c9 100644
--- a/perllib/FixMyStreet/DB/Result/ContactsHistory.pm
+++ b/perllib/FixMyStreet/DB/Result/ContactsHistory.pm
@@ -20,7 +20,7 @@ __PACKAGE__->add_columns(
},
"contact_id",
{ data_type => "integer", is_nullable => 0 },
- "area_id",
+ "body_id",
{ data_type => "integer", is_nullable => 0 },
"category",
{ data_type => "text", default_value => "Other", is_nullable => 0 },
@@ -40,8 +40,8 @@ __PACKAGE__->add_columns(
__PACKAGE__->set_primary_key("contacts_history_id");
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dN2ueIDoP3d/+Mg1UDqsMw
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-12 16:37:16
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sxflEBBn0Mn0s3MroWnWFA
# You can replace this text with custom code or comments, and it will be preserved on regeneration
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index b69436dd7..0aa5348e7 100644
--- a/perllib/FixMyStreet/SendReport/Email.pm
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -15,7 +15,7 @@ sub build_recipient_list {
my $contact = FixMyStreet::App->model("DB::Contact")->find( {
deleted => 0,
- area_id => $council,
+ body_id => $council,
category => $row->category
} );
diff --git a/perllib/FixMyStreet/SendReport/EmptyHomes.pm b/perllib/FixMyStreet/SendReport/EmptyHomes.pm
index 4a6f058fe..4eea72540 100644
--- a/perllib/FixMyStreet/SendReport/EmptyHomes.pm
+++ b/perllib/FixMyStreet/SendReport/EmptyHomes.pm
@@ -13,7 +13,7 @@ sub build_recipient_list {
foreach my $council ( keys %{ $self->councils } ) {
my $contact = FixMyStreet::App->model("DB::Contact")->find( {
deleted => 0,
- area_id => $council,
+ body_id => $council,
category => 'Empty property',
} );
diff --git a/perllib/FixMyStreet/SendReport/NI.pm b/perllib/FixMyStreet/SendReport/NI.pm
index 810ee60e2..482df7e90 100644
--- a/perllib/FixMyStreet/SendReport/NI.pm
+++ b/perllib/FixMyStreet/SendReport/NI.pm
@@ -12,7 +12,7 @@ sub build_recipient_list {
foreach my $council ( keys %{ $self->councils } ) {
my $contact = FixMyStreet::App->model("DB::Contact")->find( {
deleted => 0,
- area_id => $council,
+ body_id => $council,
category => $row->category
} );
diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm
index 8d7a418af..e2620f3b9 100644
--- a/perllib/FixMyStreet/SendReport/Open311.pm
+++ b/perllib/FixMyStreet/SendReport/Open311.pm
@@ -70,7 +70,7 @@ sub send {
# FIXME: we've already looked this up before
my $contact = FixMyStreet::App->model("DB::Contact")->find( {
deleted => 0,
- area_id => $conf->area_id,
+ body_id => $conf->area_id,
category => $row->category
} );
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index 8637e8431..65737d7c4 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -88,7 +88,7 @@ sub process_service {
print $self->_current_service->{service_code} . ': ' . $category . "\n" if $self->verbose >= 2;
my $contacts = FixMyStreet::App->model( 'DB::Contact')->search(
{
- area_id => $self->_current_council->area_id,
+ body_id => $self->_current_council->area_id,
-OR => [
email => $self->_current_service->{service_code},
category => $category,
@@ -168,7 +168,7 @@ sub _create_contact {
$contact = FixMyStreet::App->model( 'DB::Contact')->create(
{
email => $self->_current_service->{service_code},
- area_id => $self->_current_council->area_id,
+ body_id => $self->_current_council->area_id,
category => $service_name,
confirmed => 1,
deleted => 0,
@@ -272,7 +272,7 @@ sub _delete_contacts_not_in_service_list {
my $found_contacts = FixMyStreet::App->model( 'DB::Contact')->search(
{
email => { -not_in => $self->found_contacts },
- area_id => $self->_current_council->area_id,
+ body_id => $self->_current_council->area_id,
deleted => 0,
}
);
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index 644e488b2..71a391c59 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -151,12 +151,12 @@ $mech->content_contains("$host/around");
subtest 'check contact creation' => sub {
my $contact = FixMyStreet::App->model('DB::Contact')->search(
- { area_id => 2650, category => [ 'test category', 'test/category' ] }
+ { body_id => 2650, category => [ 'test category', 'test/category' ] }
);
$contact->delete_all;
my $history = FixMyStreet::App->model('DB::ContactsHistory')->search(
- { area_id => 2650, category => [ 'test category', 'test/category' ] }
+ { body_id => 2650, category => [ 'test category', 'test/category' ] }
);
$history->delete_all;
diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t
index 945f7a9d7..307943abd 100644
--- a/t/app/controller/dashboard.t
+++ b/t/app/controller/dashboard.t
@@ -44,7 +44,7 @@ $mech->submit_form_ok( {
$mech->content_contains( 'City of Edinburgh' );
-FixMyStreet::App->model('DB::Contact')->search( { area_id => $test_council } )
+FixMyStreet::App->model('DB::Contact')->search( { body_id => $test_council } )
->delete;
delete_problems();
@@ -53,7 +53,7 @@ my @cats = qw( Grafitti Litter Potholes Other );
for my $contact ( @cats ) {
FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => $test_council,
+ body_id => $test_council,
category => $contact,
email => "$contact\@example.org",
confirmed => 1,
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 77afb071c..92943bde9 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -39,43 +39,43 @@ FixMyStreet::App->model('DB::Contact')->search( {
} )->delete;
my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'Street lighting',
email => 'highways@example.com',
} );
my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2226, # Gloucestershire
+ body_id => 2226, # Gloucestershire
category => 'Potholes',
email => 'potholes@example.com',
} );
my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2326, # Cheltenham
+ body_id => 2326, # Cheltenham
category => 'Trees',
email => 'trees@example.com',
} );
my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2482, # Bromley
+ body_id => 2482, # Bromley
category => 'Trees',
email => 'trees@example.com',
} );
my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'Trees',
email => 'trees@example.com',
} );
my $contact6 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2434, # Lichfield
+ body_id => 2434, # Lichfield
category => 'Trees',
email => 'trees@example.com',
} );
my $contact7 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2240, # Lichfield
+ body_id => 2240, # Lichfield
category => 'Street lighting',
email => 'highways@example.com',
} );
diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t
index 4b009c746..e9ada9f41 100644
--- a/t/app/controller/report_new_open311.t
+++ b/t/app/controller/report_new_open311.t
@@ -24,7 +24,7 @@ my %contact_params = (
# Let's make some contacts to send things to!
my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'Street lighting',
email => '100',
extra => [ { description => 'Lamppost number', code => 'number', required => 'True' },
@@ -35,7 +35,7 @@ my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
} );
my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'Graffiti Removal',
email => '101',
} );
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index 9aa52c3cf..baec6baf0 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -361,36 +361,36 @@ FixMyStreet::App->model('DB::Contact')->search( {
} )->delete;
my @contacts;
for my $contact ( {
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'potholes',
email => 'test@example.org',
}, {
- area_id => 2226, # Gloucestershire
+ body_id => 2226, # Gloucestershire
category => 'potholes',
email => '2226@example.org',
}, {
- area_id => 2326, # Cheltenham
+ body_id => 2326, # Cheltenham
category => 'potholes',
email => '2326@example.org',
}, {
- area_id => 2434, # Lichfield
+ body_id => 2434, # Lichfield
category => 'potholes',
email => 'trees@example.com',
}, {
- area_id => 2240, # Staffordshire
+ body_id => 2240, # Staffordshire
category => 'potholes',
email => 'highways@example.com',
}, {
- area_id => 14279, # Ballymoney
+ body_id => 14279, # Ballymoney
category => 'Street lighting',
email => 'roads.western@drdni.example.org',
}, {
- area_id => 14279, # Ballymoney
+ body_id => 14279, # Ballymoney
category => 'Graffiti',
email => 'highways@example.com',
}, {
confirmed => 0,
- area_id => 2636, # Isle of Wight
+ body_id => 2636, # Isle of Wight
category => 'potholes',
email => '2636@example.com',
} ) {
diff --git a/t/app/sendreport/email.t b/t/app/sendreport/email.t
index f0e1f153a..04b3854cc 100644
--- a/t/app/sendreport/email.t
+++ b/t/app/sendreport/email.t
@@ -16,7 +16,7 @@ my $e = FixMyStreet::SendReport::Email->new();
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
email => 'council@example.com',
- area_id => 1000,
+ body_id => 1000,
category => 'category',
confirmed => 1,
deleted => 0,
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 8c23e6465..ec6c175f9 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -20,7 +20,7 @@ ok $processor, 'created object';
subtest 'check basic functionality' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $service_list = get_xml_simple_object( get_standard_xml() );
@@ -32,16 +32,16 @@ subtest 'check basic functionality' => sub {
$processor->_current_council( $council );
$processor->process_services( $service_list );
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 3, 'correct number of contacts';
};
subtest 'check non open311 contacts marked as deleted' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $contact = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => 'contact@example.com',
category => 'An old category',
confirmed => 1,
@@ -62,19 +62,19 @@ subtest 'check non open311 contacts marked as deleted' => sub {
$processor->_current_council( $council );
$processor->process_services( $service_list );
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 4, 'correct number of contacts';
- $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1, deleted => 1 } )->count();
+ $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1, deleted => 1 } )->count();
is $contact_count, 1, 'correct number of deleted contacts';
};
subtest 'check email changed if matching category' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $contact = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => '009',
category => 'Cans left out 24x7',
confirmed => 1,
@@ -102,16 +102,16 @@ subtest 'check email changed if matching category' => sub {
is $contact->confirmed, 1, 'contact still confirmed';
is $contact->deleted, 0, 'contact still not deleted';
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 3, 'correct number of contacts';
};
subtest 'check category name changed if updated' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $contact = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,
@@ -140,16 +140,16 @@ subtest 'check category name changed if updated' => sub {
is $contact->confirmed, 1, 'contact still confirmed';
is $contact->deleted, 0, 'contact still not deleted';
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 3, 'correct number of contacts';
};
subtest 'check conflicting contacts not changed' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $contact = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => 'existing@example.com',
category => 'Cans left out 24x7',
confirmed => 1,
@@ -164,7 +164,7 @@ subtest 'check conflicting contacts not changed' => sub {
my $contact2 = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,
@@ -199,7 +199,7 @@ subtest 'check conflicting contacts not changed' => sub {
is $contact2->confirmed, 1, 'second contact contact still confirmed';
is $contact2->deleted, 0, 'second contact contact still not deleted';
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 4, 'correct number of contacts';
};
@@ -225,7 +225,7 @@ subtest 'check meta data population' => sub {
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,
@@ -409,7 +409,7 @@ for my $test (
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
{
- area_id => 1,
+ body_id => 1,
email => '100',
category => 'Cans left out 24x7',
confirmed => 1,
@@ -487,7 +487,7 @@ subtest 'check attribute ordering' => sub {
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,
@@ -593,7 +593,7 @@ subtest 'check bromely skip code' => sub {
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,