diff options
Diffstat (limited to 'perllib/Open311/PopulateServiceList.pm')
-rw-r--r-- | perllib/Open311/PopulateServiceList.pm | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm index 7b5f4c7fe..e8ae56833 100644 --- a/perllib/Open311/PopulateServiceList.pm +++ b/perllib/Open311/PopulateServiceList.pm @@ -21,6 +21,7 @@ sub process_councils { while ( my $council = $self->council_list->next ) { next unless $council->endpoint; + next unless lc($council->send_method) eq 'open311'; $self->_current_council( $council ); $self->process_council; } @@ -40,7 +41,9 @@ sub process_council { my $list = $open311->get_service_list; unless ( $list ) { - warn "ERROR: no service list found for " . $self->_current_council->area_id . "\n"; + my $id = $self->_current_council->area_id; + warn "Council $id - http://mapit.mysociety.org/area/$id.html - did not return a service list\n" + if $self->verbose >= 1; return; } $self->process_services( $list ); @@ -82,7 +85,7 @@ sub process_service { $self->_current_service->{description} : $self->_current_service->{service_name}; - print $self->_current_service->{service_code} . ': ' . $category . "\n" if $self->verbose; + 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, @@ -122,7 +125,7 @@ sub _handle_existing_contact { my $service_name = $self->_normalize_service_name; - print $self->_current_council->area_id . " already has a contact for service code " . $self->_current_service->{service_code} . "\n" if $self->verbose; + print $self->_current_council->area_id . " already has a contact for service code " . $self->_current_service->{service_code} . "\n" if $self->verbose >= 2; if ( $contact->deleted || $service_name ne $contact->category || $self->_current_service->{service_code} ne $contact->email ) { eval { @@ -140,11 +143,18 @@ sub _handle_existing_contact { }; if ( $@ ) { - warn "Failed to update contact for service code " . $self->_current_service->{service_code} . " for council @{[$self->_current_council->area_id]}: $@\n"; + warn "Failed to update contact for service code " . $self->_current_service->{service_code} . " for council @{[$self->_current_council->area_id]}: $@\n" + if $self->verbose >= 1; return; } } + if ( $contact and lc( $self->_current_service->{metadata} ) eq 'true' ) { + $self->_add_meta_to_contact( $contact ); + } elsif ( $contact and $contact->extra and lc( $self->_current_service->{metadata} ) eq 'false' ) { + $contact->update( { extra => undef } ); + } + push @{ $self->found_contacts }, $self->_current_service->{service_code}; } @@ -170,7 +180,8 @@ sub _create_contact { }; if ( $@ ) { - warn "Failed to create contact for service code " . $self->_current_service->{service_code} . " for council @{[$self->_current_council->area_id]}: $@\n"; + warn "Failed to create contact for service code " . $self->_current_service->{service_code} . " for council @{[$self->_current_council->area_id]}: $@\n" + if $self->verbose >= 1; return; } @@ -180,14 +191,14 @@ sub _create_contact { if ( $contact ) { push @{ $self->found_contacts }, $self->_current_service->{service_code}; - print "created contact for service code " . $self->_current_service->{service_code} . " for council @{[$self->_current_council->area_id]}\n" if $self->verbose; + print "created contact for service code " . $self->_current_service->{service_code} . " for council @{[$self->_current_council->area_id]}\n" if $self->verbose >= 2; } } sub _add_meta_to_contact { my ( $self, $contact ) = @_; - print "Fetching meta data for $self->_current_service->{service_code}\n" if $self->verbose; + print "Fetching meta data for $self->_current_service->{service_code}\n" if $self->verbose >= 2; my $meta_data = $self->_current_open311->get_service_meta_info( $self->_current_service->{service_code} ); if ( ref $meta_data->{ attributes }->{ attribute } eq 'HASH' ) { @@ -196,6 +207,14 @@ sub _add_meta_to_contact { ]; } + if ( ! $meta_data->{attributes}->{attribute} ) { + warn sprintf( "Empty meta data for %s at %s", + $self->_current_service->{service_code}, + $self->_current_council->endpoint ) + if $self->verbose; + return; + } + # turn the data into something a bit more friendly to use my @meta = # remove trailing colon as we add this when we display so we don't want 2 |