@@ -, +, @@ --- .../search_for_data_inconsistencies.pl | 106 +++++++++++++----- 1 file changed, 76 insertions(+), 30 deletions(-) --- a/misc/maintenance/search_for_data_inconsistencies.pl +++ a/misc/maintenance/search_for_data_inconsistencies.pl @@ -29,37 +29,77 @@ use C4::Biblio qw( GetMarcFromKohaField ); use Getopt::Long; use Pod::Usage; -my %options = ( - 'branch' => 1, - 'auth' => 1, - 'status' => 1, - 'framework' => 1, - 'title' => 1, - 'age' => 1, - 'help' => 0, +our %options = ( + 'check-branch' => 0, + 'check-auth' => 0, + 'check-status' => 0, + 'check-framework' => 0, + 'check-title' => 0, + 'check-age' => 0, + 'skip-branch' => 1, + 'skip-auth' => 1, + 'skip-status' => 1, + 'skip-framework' => 1, + 'skip-title' => 1, + 'skip-age' => 1, + 'help' => 0, ); # Parse command line options GetOptions( - 'skip-branch' => sub { $options{'branch'} = 0 }, - 'skip-auth' => sub { $options{'auth'} = 0 }, - 'skip-status' => sub { $options{'status'} = 0 }, - 'skip-framework' => sub { $options{'framework'} = 0 }, - 'skip-title' => sub { $options{'title'} = 0 }, - 'skip-age' => sub { $options{'age'} = 0 }, - 'help' => sub { $options{'help'} = 1; }, -) or pod2usage(2); # Print usage if invalid options are provided + 'check-branch' => sub { $options{'check-branch'} = 1 }, + 'check-auth' => sub { $options{'check-auth'} = 1 }, + 'check-status' => sub { $options{'check-status'} = 1 }, + 'check-framework' => sub { $options{'check-framework'} = 1 }, + 'check-title' => sub { $options{'check-title'} = 1 }, + 'check-age' => sub { $options{'check-age'} = 1 }, + 'skip-branch' => sub { $options{'skip-branch'} = 0 }, + 'skip-auth' => sub { $options{'skip-auth'} = 0 }, + 'skip-status' => sub { $options{'skip-status'} = 0 }, + 'skip-framework' => sub { $options{'skip-framework'} = 0 }, + 'skip-title' => sub { $options{'skip-title'} = 0 }, + 'skip-age' => sub { $options{'skip-age'} = 0 }, + 'help' => sub { $options{'help'} = 1; }, +) or pod2usage(2); # Print usage if invalid options are provided + +# Call handle_invalid_options subroutine if invalid options are provided +Getopt::Long::Configure('pass_through'); +GetOptions( + '<>' => sub { + my ($opt_name) = @_; + handle_invalid_options($opt_name); + } +); # Print usage and exit if --help flag is provided pod2usage(1) if $options{'help'}; -# Run checks based on options -CheckItemsBranch() if $options{'branch'}; -CheckItemsAuthHeader() if $options{'auth'}; -CheckItemsStatus() if $options{'status'}; -CheckItemsFramework() if $options{'framework'}; -CheckItemsTitle() if $options{'title'}; -CheckAgeForCategory() if $options{'age'}; +# Run tests based on options +set_skip_options(); +CheckItemsBranch() if $options{'check-branch'} || $options{'skip-branch'}; +CheckItemsAuthHeader() if $options{'check-auth'} || $options{'skip-auth'}; +CheckItemsStatus() if $options{'check-status'} || $options{'skip-status'}; +CheckItemsFramework() if $options{'check-framework'} || $options{'skip-framework'}; +CheckItemsTitle() if $options{'check-title'} || $options{'skip-title'}; +CheckAgeForCategory() if $options{'check-age'} || $options{'skip-age'}; + +# Handle invalid options +sub handle_invalid_options { + my ($opt_name) = @_; + print "Invalid option provided: $opt_name\n"; + pod2usage(2); +} + +# Set skip options based on check options +sub set_skip_options { + my $has_check_option = grep { $options{$_} == 1 } grep { /^check-/ } keys %options; + if ($has_check_option) { + foreach my $key (keys %options) { + $options{$key} = 0 if $key =~ /^skip-/; + } + } + return %options; +} sub CheckItemsBranch { my $items = Koha::Items->search({ -or => { homebranch => undef, holdingbranch => undef }}); @@ -390,13 +430,19 @@ Catch data inconsistencies in Koha database: =head2 OPTIONS - --skip-branch Skip checking for items without home or holding library - --skip-auth Skip checking for authority records with invalid authority type - --skip-status Skip checking for bibliographic records and items without an item type or with an invalid item type - --skip-framework Skip checking for invalid values in fields where the framework limits to an authorized value category - --skip-title Skip checking for bibliographic records without a title - --skip-age Skip checking for patrons with invalid age for category - --help Print usage information + --check-branch Check for items without home or holding library + --check-auth Check for authority records with invalid authority type + --check-status Check for bibliographic records and items without an item type or with an invalid item type + --check-framework Check for invalid values in fields where the framework limits to an authorized value category + --check-title Check for bibliographic records without a title + --check-age Check for patrons with invalid age for category + --skip-branch Skip checking for items without home or holding library + --skip-auth Skip checking for authority records with invalid authority type + --skip-status Skip checking for bibliographic records and items without an item type or with an invalid item type + --skip-framework Skip checking for invalid values in fields where the framework limits to an authorized value category + --skip-title Skip checking for bibliographic records without a title + --skip-age Skip checking for patrons with invalid age for category + --help Print usage information Note: If no options are provided, all tests will be run. --