aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2017-10-31 15:29:35 +0000
committerDave Arter <davea@mysociety.org>2017-12-05 09:56:30 +0000
commit2281b1eccb9c9ff8bc9b8644edc71ca8febda6c4 (patch)
treeecf23a7ba9ab9ece3a893d83ccf1054d63377177
parent6c2290663217efd2aab807448b321868866e0bc5 (diff)
Store group on Contacts in Open311 PopulateServiceList
-rw-r--r--perllib/Open311/PopulateServiceList.pm14
-rw-r--r--t/open311/populate-service-list.t9
2 files changed, 22 insertions, 1 deletions
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index dbd0d1c68..e8d06efdf 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -156,7 +156,13 @@ sub _handle_existing_contact {
if ( $contact and lc($metadata) eq 'true' ) {
$self->_add_meta_to_contact( $contact );
} elsif ( $contact and $contact->extra and lc($metadata) eq 'false' ) {
- $contact->update( { extra => undef } );
+ $contact->set_extra_fields();
+ $contact->update;
+ }
+
+ if (my $group = $self->_current_service->{group}) {
+ $contact->set_extra_metadata(group => $group);
+ $contact->update;
}
push @{ $self->found_contacts }, $self->_current_service->{service_code};
@@ -182,6 +188,12 @@ sub _create_contact {
);
};
+ if (my $group = $self->_current_service->{group}) {
+ $contact->set_extra_metadata(group => $group);
+ $contact->update;
+ }
+
+
if ( $@ ) {
warn "Failed to create contact for service code " . $self->_current_service->{service_code} . " for body @{[$self->_current_body->id]}: $@\n"
if $self->verbose >= 1;
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 04740a9e8..7d4f491c6 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -39,6 +39,15 @@ subtest 'check basic functionality' => sub {
my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->count();
is $contact_count, 3, 'correct number of contacts';
+
+ for my $test (
+ { code => "001", group => "sanitation" },
+ { code => "002", group => "street" },
+ { code => "003", group => "street" },
+ ) {
+ my $contact = FixMyStreet::DB->resultset('Contact')->search( { body_id => 1, email => $test->{code} } )->first;
+ is $contact->get_extra->{group}, $test->{group}, "Group set correctly";
+ }
};
subtest 'check non open311 contacts marked as deleted' => sub {