diff options
-rwxr-xr-x | bin/open311-populate-service-list | 6 | ||||
-rw-r--r-- | perllib/Open311/PopulateServiceList.pm | 17 |
2 files changed, 15 insertions, 8 deletions
diff --git a/bin/open311-populate-service-list b/bin/open311-populate-service-list index 99f8502a7..392b86dbd 100755 --- a/bin/open311-populate-service-list +++ b/bin/open311-populate-service-list @@ -9,6 +9,7 @@ use Getopt::Long::Descriptive; my ($opt, $usage) = describe_options( '%c %o', ['verbose|v', "print out all services as they are found"], + ['warn|w', "output warnings about any issues"], ['help', "print usage message and exit" ], ); print($usage->text), exit if $opt->help; @@ -16,6 +17,9 @@ print($usage->text), exit if $opt->help; my $council_list = FixMyStreet::App->model('DB::Open311conf')->search( { send_method => 'Open311' } ); -my $p = Open311::PopulateServiceList->new( council_list => $council_list, verbose => $opt->verbose? 1:0 ); +my $verbose = 0; +$verbose = 1 if $opt->warn; +$verbose = 2 if $opt->verbose; +my $p = Open311::PopulateServiceList->new( council_list => $council_list, verbose => $verbose ); $p->process_councils; diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm index 39502f3b1..b12d68972 100644 --- a/perllib/Open311/PopulateServiceList.pm +++ b/perllib/Open311/PopulateServiceList.pm @@ -41,7 +41,8 @@ sub process_council { my $list = $open311->get_service_list; unless ( $list ) { - warn "ERROR: no service list found for " . $self->_current_council->area_id . "\n"; + warn "ERROR: no service list found for " . $self->_current_council->area_id . "\n" + if $self->verbose >= 1; return; } $self->process_services( $list ); @@ -83,7 +84,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, @@ -123,7 +124,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 { @@ -141,7 +142,8 @@ 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; } } @@ -171,7 +173,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; } @@ -181,14 +184,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' ) { |