diff options
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | perllib/Open311/PopulateServiceList.pm | 30 |
2 files changed, 23 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 85882f70e..d1f292dd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,9 @@ - Clearer name for navigation colours in SCSS. #2080 - Internal things: - Move send-comments code to package for testing. #2109 #2170 + - Open311 improvements: + - Set contact group only if handling cobrand has groups enabled. #2312 + * v2.4.1 (2nd October 2018) - New features: diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm index f10bdf7fb..d3f30d60c 100644 --- a/perllib/Open311/PopulateServiceList.pm +++ b/perllib/Open311/PopulateServiceList.pm @@ -11,6 +11,9 @@ has schema => ( is => 'ro', lazy => 1, default => sub { FixMyStreet::DB->schema- has _current_body => ( is => 'rw' ); has _current_open311 => ( is => 'rw' ); has _current_service => ( is => 'rw' ); +has _current_body_cobrand => ( is => 'ro', lazy => 1, default => sub { + return shift->_current_body->get_cobrand_handler; +} ); sub process_bodies { my $self = shift; @@ -160,10 +163,7 @@ sub _handle_existing_contact { $contact->update; } - if (my $group = $self->_current_service->{group}) { - $contact->set_extra_metadata(group => $group); - $contact->update; - } + $self->_set_contact_group($contact); push @{ $self->found_contacts }, $self->_current_service->{service_code}; } @@ -188,12 +188,6 @@ 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; @@ -205,6 +199,8 @@ sub _create_contact { $self->_add_meta_to_contact( $contact ); } + $self->_set_contact_group($contact); + if ( $contact ) { push @{ $self->found_contacts }, $self->_current_service->{service_code}; print "created contact for service code " . $self->_current_service->{service_code} . " for body @{[$self->_current_body->id]}\n" if $self->verbose >= 2; @@ -310,6 +306,20 @@ sub _normalize_service_name { return $service_name; } +sub _set_contact_group { + my ($self, $contact) = @_; + + if ($self->_current_body_cobrand && $self->_current_body_cobrand->call_hook('enable_category_groups')) { + if (my $group = $self->_current_service->{group}) { + $contact->set_extra_metadata(group => $group); + $contact->update; + } + } else { + $contact->unset_extra_metadata('group'); + $contact->update; + } +} + sub _delete_contacts_not_in_service_list { my $self = shift; |