Lines 36-47
our %options = (
Link Here
|
36 |
'check-framework' => 0, |
36 |
'check-framework' => 0, |
37 |
'check-title' => 0, |
37 |
'check-title' => 0, |
38 |
'check-age' => 0, |
38 |
'check-age' => 0, |
39 |
'skip-branch' => 1, |
39 |
'check-loop' => 0, |
40 |
'skip-auth' => 1, |
40 |
'skip-branch' => 0, |
41 |
'skip-status' => 1, |
41 |
'skip-auth' => 0, |
42 |
'skip-framework' => 1, |
42 |
'skip-status' => 0, |
43 |
'skip-title' => 1, |
43 |
'skip-framework' => 0, |
44 |
'skip-age' => 1, |
44 |
'skip-title' => 0, |
|
|
45 |
'skip-age' => 0, |
46 |
'skip-loop' => 0, |
45 |
'help' => 0, |
47 |
'help' => 0, |
46 |
); |
48 |
); |
47 |
|
49 |
|
Lines 53-64
GetOptions(
Link Here
|
53 |
'check-framework' => sub { $options{'check-framework'} = 1 }, |
55 |
'check-framework' => sub { $options{'check-framework'} = 1 }, |
54 |
'check-title' => sub { $options{'check-title'} = 1 }, |
56 |
'check-title' => sub { $options{'check-title'} = 1 }, |
55 |
'check-age' => sub { $options{'check-age'} = 1 }, |
57 |
'check-age' => sub { $options{'check-age'} = 1 }, |
56 |
'skip-branch' => sub { $options{'skip-branch'} = 0 }, |
58 |
'check-loop' => sub { $options{'check-loop'} = 1 }, |
57 |
'skip-auth' => sub { $options{'skip-auth'} = 0 }, |
59 |
'skip-branch' => sub { $options{'skip-branch'} = 1 }, |
58 |
'skip-status' => sub { $options{'skip-status'} = 0 }, |
60 |
'skip-auth' => sub { $options{'skip-auth'} = 1 }, |
59 |
'skip-framework' => sub { $options{'skip-framework'} = 0 }, |
61 |
'skip-status' => sub { $options{'skip-status'} = 1 }, |
60 |
'skip-title' => sub { $options{'skip-title'} = 0 }, |
62 |
'skip-framework' => sub { $options{'skip-framework'} = 1 }, |
61 |
'skip-age' => sub { $options{'skip-age'} = 0 }, |
63 |
'skip-title' => sub { $options{'skip-title'} = 1 }, |
|
|
64 |
'skip-age' => sub { $options{'skip-age'} = 1 }, |
65 |
'skip-loop' => sub { $options{'skip-loop'} = 1 }, |
62 |
'help' => sub { $options{'help'} = 1; }, |
66 |
'help' => sub { $options{'help'} = 1; }, |
63 |
) or pod2usage(2); # Print usage if invalid options are provided |
67 |
) or pod2usage(2); # Print usage if invalid options are provided |
64 |
|
68 |
|
Lines 74-87
GetOptions(
Link Here
|
74 |
# Print usage and exit if --help flag is provided |
78 |
# Print usage and exit if --help flag is provided |
75 |
pod2usage(1) if $options{'help'}; |
79 |
pod2usage(1) if $options{'help'}; |
76 |
|
80 |
|
77 |
# Run tests based on options |
81 |
# Set skip options based on check options |
78 |
set_skip_options(); |
82 |
set_skip_options(); |
79 |
CheckItemsBranch() if $options{'check-branch'} || $options{'skip-branch'}; |
83 |
# Set all check options to 1 if none are provided, unless specified skip options |
80 |
CheckItemsAuthHeader() if $options{'check-auth'} || $options{'skip-auth'}; |
84 |
set_all_check_options_if_none_provided(); |
81 |
CheckItemsStatus() if $options{'check-status'} || $options{'skip-status'}; |
85 |
# Run checks based on options |
82 |
CheckItemsFramework() if $options{'check-framework'} || $options{'skip-framework'}; |
86 |
CheckItemsBranch() if $options{'check-branch'} && !$options{'skip-branch'}; |
83 |
CheckItemsTitle() if $options{'check-title'} || $options{'skip-title'}; |
87 |
CheckItemsAuthHeader() if $options{'check-auth'} && !$options{'skip-auth'}; |
84 |
CheckAgeForCategory() if $options{'check-age'} || $options{'skip-age'}; |
88 |
CheckItemsStatus() if $options{'check-status'} && !$options{'skip-status'}; |
|
|
89 |
CheckItemsFramework() if $options{'check-framework'} && !$options{'skip-framework'}; |
90 |
CheckItemsTitle() if $options{'check-title'} && !$options{'skip-title'}; |
91 |
CheckAgeForCategory() if $options{'check-age'} && !$options{'skip-age'}; |
92 |
CheckRelationshipsLoop() if $options{'check-loop'} && !$options{'skip-loop'}; |
85 |
|
93 |
|
86 |
# Handle invalid options |
94 |
# Handle invalid options |
87 |
sub handle_invalid_options { |
95 |
sub handle_invalid_options { |
Lines 92-106
sub handle_invalid_options {
Link Here
|
92 |
|
100 |
|
93 |
# Set skip options based on check options |
101 |
# Set skip options based on check options |
94 |
sub set_skip_options { |
102 |
sub set_skip_options { |
95 |
my $has_check_option = grep { $options{$_} == 1 } grep { /^check-/ } keys %options; |
103 |
# If at least one check option is provided, set all skip options to 0 |
|
|
104 |
my $has_check_option = grep { $options{$_} } grep { /^check-/ } keys %options; |
96 |
if ($has_check_option) { |
105 |
if ($has_check_option) { |
|
|
106 |
# if a least one skip option is provided, print a warning |
107 |
my $has_skip_option = grep { $options{$_} == 1 } grep { /^skip-/ } keys %options; |
108 |
if ($has_skip_option) { |
109 |
print("Warning : skip options are ignored when check options are provided\n") |
110 |
} |
111 |
# Set all skip options to 0 |
97 |
foreach my $key (keys %options) { |
112 |
foreach my $key (keys %options) { |
98 |
$options{$key} = 0 if $key =~ /^skip-/; |
113 |
if ($key =~ /^skip-/) { |
|
|
114 |
$options{$key} = 0; |
115 |
} |
99 |
} |
116 |
} |
100 |
} |
117 |
} |
101 |
return %options; |
118 |
return %options; |
102 |
} |
119 |
} |
103 |
|
120 |
|
|
|
121 |
# Set all check options to 1 if none are provided, considering skip options |
122 |
sub set_all_check_options_if_none_provided { |
123 |
my $any_check_option_provided = grep { $options{$_} } grep { /^check-/ } keys %options; |
124 |
if (!$any_check_option_provided) { |
125 |
foreach my $key (keys %options) { |
126 |
if ($key =~ /^check-/) { |
127 |
my $skip_key = $key; |
128 |
$skip_key =~ s/^check-/skip-/; |
129 |
# Set check option to 1 unless the corresponding skip option indicated |
130 |
$options{$key} = 1 unless $options{$skip_key}; |
131 |
} |
132 |
} |
133 |
} |
134 |
} |
135 |
|
104 |
sub CheckItemsBranch { |
136 |
sub CheckItemsBranch { |
105 |
my $items = Koha::Items->search({ -or => { homebranch => undef, holdingbranch => undef }}); |
137 |
my $items = Koha::Items->search({ -or => { homebranch => undef, holdingbranch => undef }}); |
106 |
if ( $items->count ) { new_section("Not defined items.homebranch and/or items.holdingbranch")} |
138 |
if ( $items->count ) { new_section("Not defined items.homebranch and/or items.holdingbranch")} |
Lines 486-491
sub CheckAgeForCategory {
Link Here
|
486 |
} |
518 |
} |
487 |
} |
519 |
} |
488 |
|
520 |
|
|
|
521 |
sub CheckRelationshipsLoop { |
522 |
my @loop_borrowers_relationships; |
523 |
my @guarantor_ids = Koha::Patron::Relationships->_resultset->get_column('guarantor_id')->all(); |
524 |
my @guarantee_ids = Koha::Patron::Relationships->_resultset->get_column('guarantee_id')->all(); |
525 |
|
526 |
foreach my $guarantor_id (@guarantor_ids) { |
527 |
foreach my $guarantee_id (@guarantee_ids) { |
528 |
if ( $guarantor_id == $guarantee_id ) { |
529 |
|
530 |
my $relation_guarantor_id; |
531 |
my $relation_guarantee_id; |
532 |
my $size_list; |
533 |
my $tmp_garantor_id = $guarantor_id; |
534 |
my @guarantor_ids; |
535 |
|
536 |
do { |
537 |
my @relationship_for_go = Koha::Patron::Relationships->search( |
538 |
{ |
539 |
-or => [ |
540 |
'guarantor_id' => { '=', $tmp_garantor_id }, |
541 |
] |
542 |
}, |
543 |
)->as_list; |
544 |
$size_list = scalar @relationship_for_go; |
545 |
|
546 |
foreach my $relation (@relationship_for_go) { |
547 |
$relation_guarantor_id = $relation->guarantor_id; |
548 |
unless ( grep { $_ == $relation_guarantor_id } @guarantor_ids ) { |
549 |
push @guarantor_ids, $relation_guarantor_id; |
550 |
} |
551 |
$relation_guarantee_id = $relation->guarantee_id; |
552 |
|
553 |
my @relationship_for_go = Koha::Patron::Relationships->search( |
554 |
{ |
555 |
-or => [ |
556 |
'guarantor_id' => { '=', $relation_guarantee_id }, |
557 |
] |
558 |
}, |
559 |
)->as_list; |
560 |
$size_list = scalar @relationship_for_go; |
561 |
|
562 |
if ( $guarantor_id == $relation_guarantee_id ) { |
563 |
last; |
564 |
} |
565 |
|
566 |
foreach my $relation (@relationship_for_go) { |
567 |
$relation_guarantor_id = $relation->guarantor_id; |
568 |
unless ( grep { $_ == $relation_guarantor_id } @guarantor_ids ) { |
569 |
push @guarantor_ids, $relation_guarantor_id; |
570 |
} |
571 |
$relation_guarantee_id = $relation->guarantee_id; |
572 |
|
573 |
if ( $guarantor_id == $relation_guarantee_id ) { |
574 |
last; |
575 |
} |
576 |
} |
577 |
if ( $guarantor_id == $relation_guarantee_id ) { |
578 |
last; |
579 |
} |
580 |
} |
581 |
|
582 |
$tmp_garantor_id = $relation_guarantee_id; |
583 |
} while ( $guarantor_id != $relation_guarantee_id && $size_list > 0 ); |
584 |
|
585 |
if ( $guarantor_id == $relation_guarantee_id ) { |
586 |
unless ( grep { join( "", sort @$_ ) eq join( "", sort @guarantor_ids ) } |
587 |
@loop_borrowers_relationships ) |
588 |
{ |
589 |
push @loop_borrowers_relationships, \@guarantor_ids; |
590 |
} |
591 |
} |
592 |
} |
593 |
} |
594 |
} |
595 |
|
596 |
if ( scalar @loop_borrowers_relationships > 0 ) { |
597 |
new_section("The list of guarantors who are also guarantee."); |
598 |
my $count = 0; |
599 |
foreach my $table (@loop_borrowers_relationships) { |
600 |
$count++; |
601 |
print "Loop $count, borrowers id : "; |
602 |
foreach my $borrower_id (@$table) { |
603 |
print "$borrower_id , "; |
604 |
} |
605 |
print "\n"; |
606 |
} |
607 |
new_hint("Relationships that form guarantor loops must be deleted"); |
608 |
} |
609 |
} |
610 |
|
489 |
sub new_section { |
611 |
sub new_section { |
490 |
my ( $name ) = @_; |
612 |
my ( $name ) = @_; |
491 |
say "\n== $name =="; |
613 |
say "\n== $name =="; |
Lines 517-538
Catch data inconsistencies in Koha database:
Link Here
|
517 |
* Bibliographic records without a title |
639 |
* Bibliographic records without a title |
518 |
* Invalid MARCXML in bibliographic records |
640 |
* Invalid MARCXML in bibliographic records |
519 |
* Patrons with invalid category types due to lower and upper age limits |
641 |
* Patrons with invalid category types due to lower and upper age limits |
|
|
642 |
* Relationships that form guarantor loops |
520 |
|
643 |
|
521 |
=head2 OPTIONS |
644 |
=head2 OPTIONS |
522 |
|
645 |
|
523 |
--check-branch Check for items without home or holding library |
646 |
--check-branch Check for items without home or holding library |
524 |
--check-auth Check for authority records with invalid authority type |
647 |
--check-auth Check for authority records with invalid authority type |
525 |
--check-status Check for bibliographic records and items without an item type or with an invalid item type |
648 |
--check-status Check for bibliographic records and items without an item type or with an invalid item type |
526 |
--check-framework Check for invalid values in fields where the framework limits to an authorized value category |
649 |
--check-framework Check for invalid values in fields where the framework limits to an authorized value category |
527 |
--check-title Check for bibliographic records without a title |
650 |
--check-title Check for bibliographic records without a title |
528 |
--check-age Check for patrons with invalid age for category |
651 |
--check-age Check for patrons with invalid age for category |
529 |
--skip-branch Skip checking for items without home or holding library |
652 |
--check-loop Check for relationships that form guarantor loops |
530 |
--skip-auth Skip checking for authority records with invalid authority type |
653 |
--skip-branch Skip checking for items without home or holding library |
531 |
--skip-status Skip checking for bibliographic records and items without an item type or with an invalid item type |
654 |
--skip-auth Skip checking for authority records with invalid authority type |
532 |
--skip-framework Skip checking for invalid values in fields where the framework limits to an authorized value category |
655 |
--skip-status Skip checking for bibliographic records and items without an item type or with an invalid item type |
533 |
--skip-title Skip checking for bibliographic records without a title |
656 |
--skip-framework Skip checking for invalid values in fields where the framework limits to an authorized value category |
534 |
--skip-age Skip checking for patrons with invalid age for category |
657 |
--skip-title Skip checking for bibliographic records without a title |
535 |
--help Print usage information |
658 |
--skip-age Skip checking for patrons with invalid age for category |
|
|
659 |
--skip-loop Skip checking for relationships that form guarantor loops |
660 |
--help Print usage information |
536 |
|
661 |
|
537 |
Note: If no options are provided, all tests will be run. |
662 |
Note: If no options are provided, all tests will be run. |
538 |
|
663 |
|
539 |
- |
|
|