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

(-)a/misc/maintenance/search_for_data_inconsistencies.pl (-67 / +54 lines)
Lines 27-89 use Koha::Items; Link Here
27
use Koha::ItemTypes;
27
use Koha::ItemTypes;
28
use Koha::Patrons;
28
use Koha::Patrons;
29
use C4::Biblio qw( GetMarcFromKohaField );
29
use C4::Biblio qw( GetMarcFromKohaField );
30
use Getopt::Long;
31
use Pod::Usage;
30
32
31
# %methods hash defines options and their corresponding subroutines
33
my %options = (
32
# Each numeric key represents an option, and its associated subroutine reference defines the action to be taken
34
    'branch'    => 1,
33
# Option 1: CheckItemsBranch - Check for items without home or holding library
35
    'auth'      => 1,
34
# Option 2: CheckItemsAuthHeader - Check for authority records with invalid authority type
36
    'status'    => 1,
35
# Option 3: CheckItemsStatus - Check for bibliographic records and items without an item type or with an invalid item type
37
    'framework' => 1,
36
# Option 4: CheckItemsFramework - Check for invalid values in fields where the framework limits to an authorized value category
38
    'title'     => 1,
37
# Option 5: CheckItemsTitle - Check for bibliographic records without a title
39
    'age'       => 1,
38
# Option 6: CheckAgeForCategory - Check for patrons with invalid age for category
40
    'help'      => 0,
39
# Option 7: CheckRelationshipsLoop - Check for relationships or dependencies between borrowers in a loop
40
41
my %methods = (
42
    1 => \&CheckItemsBranch,
43
    2 => \&CheckItemsAuthHeader,
44
    3 => \&CheckItemsStatus,
45
    4 => \&CheckItemsFramework,
46
    5 => \&CheckItemsTitle,
47
    6 => \&CheckAgeForCategory,
48
);
41
);
49
42
50
my @methods_to_run;
43
# Parse command line options
44
GetOptions(
45
    'skip-branch'    => sub { $options{'branch'} = 0 },
46
    'skip-auth'      => sub { $options{'auth'} = 0 },
47
    'skip-status'    => sub { $options{'status'} = 0 },
48
    'skip-framework' => sub { $options{'framework'} = 0 },
49
    'skip-title'     => sub { $options{'title'} = 0 },
50
    'skip-age'       => sub { $options{'age'} = 0 },
51
    'help'           => sub { $options{'help'} = 1; },
52
) or pod2usage(2); # Print usage if invalid options are provided
51
53
52
if ( @ARGV == 0 ) {
54
# Print usage and exit if --help flag is provided
55
pod2usage(1) if $options{'help'};
53
56
54
    # If no arguments are provided, add all methods to the list
57
# Run checks based on options
55
    @methods_to_run = keys %methods;
58
CheckItemsBranch()    if $options{'branch'};
56
}
59
CheckItemsAuthHeader() if $options{'auth'};
57
else {
60
CheckItemsStatus()    if $options{'status'};
58
    foreach my $arg (@ARGV) {
61
CheckItemsFramework() if $options{'framework'};
59
        if ( $arg =~ /^(\d+)$/ ) {
62
CheckItemsTitle()     if $options{'title'};
60
            my $method_number = $1;
63
CheckAgeForCategory() if $options{'age'};
61
            if ( $method_number >= 1 && $method_number <= 7 ) {
62
                push @methods_to_run, $method_number;
63
            }
64
            else {
65
                print "Invalid method number: $method_number\n";
66
            }
67
        }
68
        else {
69
            print "Invalid argument: $arg\n";
70
        }
71
    }
72
}
73
64
74
foreach my $choice (@methods_to_run) {
75
    if ( $choice =~ /^\d+$/ && $choice >= 1 && $choice <= 7 ) {
76
        if ( exists $methods{$choice} ) {
77
            $methods{$choice}->();
78
        }
79
        else {
80
            print "Method $choice not found\n";
81
        }
82
    }
83
    else {
84
        print "Invalid choice: $choice\n";
85
    }
86
}
87
65
88
sub CheckItemsBranch {
66
sub CheckItemsBranch {
89
    my $items = Koha::Items->search({ -or => { homebranch => undef, holdingbranch => undef }});
67
    my $items = Koha::Items->search({ -or => { homebranch => undef, holdingbranch => undef }});
Lines 394-418 sub new_hint { Link Here
394
    say "=> $name";
372
    say "=> $name";
395
}
373
}
396
374
397
=head1 NAME
398
399
search_for_data_inconsistencies.pl
400
375
401
=head1 SYNOPSIS
376
=head1 SYNOPSIS
402
377
403
    perl search_for_data_inconsistencies.pl
378
search_for_data_inconsistencies.pl [options]
379
380
=head2 DESCRIPTION
381
382
Catch data inconsistencies in Koha database:
383
384
    * Items with undefined homebranch and/or holdingbranch
385
    * Authorities with undefined authtypecodes/authority types
386
    * Item types:
387
        * if item types are defined at item level (item-level_itypes=specific item),
388
            then items.itype must be set else biblioitems.itemtype must be set
389
        * Item types defined in items or biblioitems must be defined in the itemtypes table
390
    * Bibliographic records without a title
391
    * Invalid MARCXML in bibliographic records
392
    * Patrons with invalid category types due to lower and upper age limits
404
393
405
=head1 DESCRIPTION
394
=head2 OPTIONS
406
395
407
Catch data inconsistencies in Koha database
396
  --skip-branch      Skip checking for items without home or holding library
397
  --skip-auth        Skip checking for authority records with invalid authority type
398
  --skip-status      Skip checking for bibliographic records and items without an item type or with an invalid item type
399
  --skip-framework   Skip checking for invalid values in fields where the framework limits to an authorized value category
400
  --skip-title       Skip checking for bibliographic records without a title
401
  --skip-age         Skip checking for patrons with invalid age for category
402
  --help             Print usage information
408
403
409
* Items with undefined homebranch and/or holdingbranch
404
Note: If no options are provided, all tests will be run.
410
* Authorities with undefined authtypecodes/authority types
411
* Item types:
412
  * if item types are defined at item level (item-level_itypes=specific item),
413
    then items.itype must be set else biblioitems.itemtype must be set
414
  * Item types defined in items or biblioitems must be defined in the itemtypes table
415
* Invalid MARCXML in bibliographic records
416
* Patrons with invalid category types due to lower and upper age limits
417
405
418
=cut
406
=cut
419
- 

Return to bug 36027