aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-10-11 12:17:52 +0100
committerStruan Donald <struan@exo.org.uk>2011-10-11 12:17:52 +0100
commit3307cf922cbf0513ef99b874f241350b16a5e67e (patch)
treefc81181109370ba46e032d1e54b8c49feea195fa
parent19b9118729a036471759ad1a6519caaf0c3134c5 (diff)
if we have two conflicting existing contacts then skip the update
-rw-r--r--perllib/Open311/PopulateServiceList.pm16
-rw-r--r--t/open311/populate-service-list.t67
2 files changed, 78 insertions, 5 deletions
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index 2dfe7e5c4..f490607e4 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -83,8 +83,22 @@ sub process_service {
}
);
- my $contact = $contacts->first;
+ if ( $contacts->count() > 1 ) {
+ sprintf(
+ "Multiple contacts for service code %s, category %s - Skipping\n",
+ $self->_current_service->{service_code},
+ $self->_current_service->{service_name},
+ );
+
+ # best to not mark them as deleted as we don't know what we're doing
+ while ( my $contact = $contacts->next ) {
+ push @{ $self->found_contacts }, $contact->email;
+ }
+ return;
+ }
+
+ my $contact = $contacts->first;
if ( $contact ) {
$self->_handle_existing_contact( $contact );
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 83df47358..bdb7404f9 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -22,7 +22,7 @@ ok $processor, 'created object';
subtest 'check basic functionality' => sub {
FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
- my $service_list = get_xml_simple_object( get_standard_xml );
+ my $service_list = get_xml_simple_object( get_standard_xml() );
my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
area_id => 1
@@ -52,7 +52,7 @@ subtest 'check non open311 contacts marked as deleted' => sub {
}
);
- my $service_list = get_xml_simple_object( get_standard_xml );
+ my $service_list = get_xml_simple_object( get_standard_xml() );
my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
area_id => 1
@@ -87,7 +87,7 @@ subtest 'check email changed if matching category' => sub {
ok $contact, 'contact created';
- my $service_list = get_xml_simple_object( get_standard_xml );
+ my $service_list = get_xml_simple_object( get_standard_xml() );
my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
area_id => 1
@@ -124,7 +124,7 @@ subtest 'check category name changed if updated' => sub {
ok $contact, 'contact created';
- my $service_list = get_xml_simple_object( get_standard_xml );
+ my $service_list = get_xml_simple_object( get_standard_xml() );
my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
area_id => 1
@@ -144,6 +144,65 @@ subtest 'check category name changed if updated' => sub {
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();
+
+ my $contact = FixMyStreet::App->model('DB::Contact')->create(
+ {
+ area_id => 1,
+ email => 'existing@example.com',
+ category => 'Cans left out 24x7',
+ confirmed => 1,
+ deleted => 0,
+ editor => $0,
+ whenedited => \'ms_current_timestamp()',
+ note => 'test contact',
+ }
+ );
+
+ ok $contact, 'contact created';
+
+ my $contact2 = FixMyStreet::App->model('DB::Contact')->create(
+ {
+ area_id => 1,
+ email => '001',
+ category => 'Bins left out 24x7',
+ confirmed => 1,
+ deleted => 0,
+ editor => $0,
+ whenedited => \'ms_current_timestamp()',
+ note => 'test contact',
+ }
+ );
+
+ ok $contact2, 'contact created';
+
+ my $service_list = get_xml_simple_object( get_standard_xml() );
+
+ my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
+ area_id => 1
+ } );
+
+ my $processor = Open311::PopulateServiceList->new( council_list => [] );
+ $processor->_current_council( $council );
+ $processor->process_services( $service_list );
+
+ $contact->discard_changes;
+ is $contact->email, 'existing@example.com', 'first contact email unchanged';
+ is $contact->category, 'Cans left out 24x7', 'first contact category unchanged';
+ is $contact->confirmed, 1, 'first contact contact still confirmed';
+ is $contact->deleted, 0, 'first contact contact still not deleted';
+
+ $contact2->discard_changes;
+ is $contact2->email, '001', 'second contact email unchanged';
+ is $contact2->category, 'Bins left out 24x7', 'second contact category unchanged';
+ 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();
+ is $contact_count, 4, 'correct number of contacts';
+};
+
sub get_standard_xml {
return qq{<?xml version="1.0" encoding="utf-8"?>
<services>