View | Details | Raw Unified | Return to bug 36027
Collapse All | Expand All

(-)a/misc/maintenance/search_for_data_inconsistencies.pl (-31 / +76 lines)
Lines 29-65 use C4::Biblio qw( GetMarcFromKohaField ); Link Here
29
use Getopt::Long;
29
use Getopt::Long;
30
use Pod::Usage;
30
use Pod::Usage;
31
31
32
my %options = (
32
our %options = (
33
    'branch'    => 1,
33
    'check-branch'    => 0,
34
    'auth'      => 1,
34
    'check-auth'      => 0,
35
    'status'    => 1,
35
    'check-status'    => 0,
36
    'framework' => 1,
36
    'check-framework' => 0,
37
    'title'     => 1,
37
    'check-title'     => 0,
38
    'age'       => 1,
38
    'check-age'       => 0,
39
    'help'      => 0,
39
    'skip-branch'     => 1,
40
    'skip-auth'       => 1,
41
    'skip-status'     => 1,
42
    'skip-framework'  => 1,
43
    'skip-title'      => 1,
44
    'skip-age'        => 1,
45
    'help'            => 0,
40
);
46
);
41
47
42
# Parse command line options
48
# Parse command line options
43
GetOptions(
49
GetOptions(
44
    'skip-branch'    => sub { $options{'branch'} = 0 },
50
    'check-branch'    => sub { $options{'check-branch'}    = 1 },
45
    'skip-auth'      => sub { $options{'auth'} = 0 },
51
    'check-auth'      => sub { $options{'check-auth'}      = 1 },
46
    'skip-status'    => sub { $options{'status'} = 0 },
52
    'check-status'    => sub { $options{'check-status'}    = 1 },
47
    'skip-framework' => sub { $options{'framework'} = 0 },
53
    'check-framework' => sub { $options{'check-framework'} = 1 },
48
    'skip-title'     => sub { $options{'title'} = 0 },
54
    'check-title'     => sub { $options{'check-title'}     = 1 },
49
    'skip-age'       => sub { $options{'age'} = 0 },
55
    'check-age'       => sub { $options{'check-age'}       = 1 },
50
    'help'           => sub { $options{'help'} = 1; },
56
    'skip-branch'     => sub { $options{'skip-branch'}     = 0 },
51
) or pod2usage(2); # Print usage if invalid options are provided
57
    'skip-auth'       => sub { $options{'skip-auth'}       = 0 },
58
    'skip-status'     => sub { $options{'skip-status'}     = 0 },
59
    'skip-framework'  => sub { $options{'skip-framework'}  = 0 },
60
    'skip-title'      => sub { $options{'skip-title'}      = 0 },
61
    'skip-age'        => sub { $options{'skip-age'}        = 0 },
62
    'help'            => sub { $options{'help'}            = 1; },
63
) or pod2usage(2);    # Print usage if invalid options are provided
64
65
# Call handle_invalid_options subroutine if invalid options are provided
66
Getopt::Long::Configure('pass_through');
67
GetOptions(
68
    '<>' => sub {
69
        my ($opt_name) = @_;
70
        handle_invalid_options($opt_name);
71
    }
72
);
52
73
53
# Print usage and exit if --help flag is provided
74
# Print usage and exit if --help flag is provided
54
pod2usage(1) if $options{'help'};
75
pod2usage(1) if $options{'help'};
55
76
56
# Run checks based on options
77
# Run tests based on options
57
CheckItemsBranch()    if $options{'branch'};
78
set_skip_options();
58
CheckItemsAuthHeader() if $options{'auth'};
79
CheckItemsBranch()     if $options{'check-branch'}    || $options{'skip-branch'};
59
CheckItemsStatus()    if $options{'status'};
80
CheckItemsAuthHeader() if $options{'check-auth'}      || $options{'skip-auth'};
60
CheckItemsFramework() if $options{'framework'};
81
CheckItemsStatus()     if $options{'check-status'}    || $options{'skip-status'};
61
CheckItemsTitle()     if $options{'title'};
82
CheckItemsFramework()  if $options{'check-framework'} || $options{'skip-framework'};
62
CheckAgeForCategory() if $options{'age'};
83
CheckItemsTitle()      if $options{'check-title'}     || $options{'skip-title'};
84
CheckAgeForCategory()  if $options{'check-age'}       || $options{'skip-age'};
85
86
# Handle invalid options
87
sub handle_invalid_options {
88
    my ($opt_name) = @_;
89
    print "Invalid option provided: $opt_name\n";
90
    pod2usage(2);
91
}
92
93
# Set skip options based on check options
94
sub set_skip_options {
95
    my $has_check_option = grep { $options{$_} == 1 } grep { /^check-/ } keys %options;
96
    if ($has_check_option) {
97
        foreach my $key (keys %options) {
98
            $options{$key} = 0 if $key =~ /^skip-/;
99
        }
100
    }
101
    return %options;
102
}
63
103
64
sub CheckItemsBranch {
104
sub CheckItemsBranch {
65
    my $items = Koha::Items->search({ -or => { homebranch => undef, holdingbranch => undef }});
105
    my $items = Koha::Items->search({ -or => { homebranch => undef, holdingbranch => undef }});
Lines 390-402 Catch data inconsistencies in Koha database: Link Here
390
430
391
=head2 OPTIONS
431
=head2 OPTIONS
392
432
393
  --skip-branch      Skip checking for items without home or holding library
433
  --check-branch      Check for items without home or holding library
394
  --skip-auth        Skip checking for authority records with invalid authority type
434
  --check-auth        Check for authority records with invalid authority type
395
  --skip-status      Skip checking for bibliographic records and items without an item type or with an invalid item type
435
  --check-status      Check for bibliographic records and items without an item type or with an invalid item type
396
  --skip-framework   Skip checking for invalid values in fields where the framework limits to an authorized value category
436
  --check-framework   Check for invalid values in fields where the framework limits to an authorized value category
397
  --skip-title       Skip checking for bibliographic records without a title
437
  --check-title       Check for bibliographic records without a title
398
  --skip-age         Skip checking for patrons with invalid age for category
438
  --check-age         Check for patrons with invalid age for category
399
  --help             Print usage information
439
  --skip-branch       Skip checking for items without home or holding library
440
  --skip-auth         Skip checking for authority records with invalid authority type
441
  --skip-status       Skip checking for bibliographic records and items without an item type or with an invalid item type
442
  --skip-framework    Skip checking for invalid values in fields where the framework limits to an authorized value category
443
  --skip-title        Skip checking for bibliographic records without a title
444
  --skip-age          Skip checking for patrons with invalid age for category
445
  --help              Print usage information
400
446
401
Note: If no options are provided, all tests will be run.
447
Note: If no options are provided, all tests will be run.
402
448
403
- 

Return to bug 36027