Bugzilla – Attachment 161953 Details for
Bug 36027
search_for_data_inconsistencies.pl - make each section optional
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36027: search_for_data_inconsistencies.pl - make each section optional
Bug-36027-searchfordatainconsistenciespl---make-ea.patch (text/plain), 30.15 KB, created by
Phan Tung Bui
on 2024-02-08 20:26:20 UTC
(
hide
)
Description:
Bug 36027: search_for_data_inconsistencies.pl - make each section optional
Filename:
MIME Type:
Creator:
Phan Tung Bui
Created:
2024-02-08 20:26:20 UTC
Size:
30.15 KB
patch
obsolete
>From 9ee90d2fcf60ac14e376b16c7cc4d05b1f41c00f Mon Sep 17 00:00:00 2001 >From: Phan Tung Bui <phan-tung.bui@inlibro.com> >Date: Thu, 8 Feb 2024 15:16:32 -0500 >Subject: [PATCH] Bug 36027: search_for_data_inconsistencies.pl - make each > section optional > >--- > .../search_for_data_inconsistencies.pl | 612 ++++++++++-------- > 1 file changed, 354 insertions(+), 258 deletions(-) > >diff --git a/misc/maintenance/search_for_data_inconsistencies.pl b/misc/maintenance/search_for_data_inconsistencies.pl >index 9fc8a329ac..bd26c6daf3 100755 >--- a/misc/maintenance/search_for_data_inconsistencies.pl >+++ b/misc/maintenance/search_for_data_inconsistencies.pl >@@ -29,57 +29,66 @@ use Koha::Patrons; > use C4::Biblio qw( GetMarcFromKohaField ); > use Data::Dumper; > >- >+# %methods hash defines options and their corresponding subroutines >+# Each numeric key represents an option, and its associated subroutine reference defines the action to be taken >+# Option 1: CheckItemsBranch - Check for items without home or holding library >+# Option 2: CheckItemsAuthHeader - Check for authority records with invalid authority type >+# Option 3: CheckItemsStatus - Check for bibliographic records and items without an item type or with an invalid item type >+# Option 4: CheckItemsFramework - Check for invalid values in fields where the framework limits to an authorized value category >+# Option 5: CheckItemsTitle - Check for bibliographic records without a title >+# Option 6: CheckRelationshipsLoop - Check for relationships or dependencies between borrowers in a loop > > my %methods = ( >- 1 => \&CheckItemsBranch, >- 2 => \&CheckItemsAuthHeader, >- 3 => \&CheckItemsStatus, >- 4 => \&CheckItemsFramework, >- 5 => \&CheckItemsTitle >+1 => \&CheckItemsBranch, >+2 => \&CheckItemsAuthHeader, >+3 => \&CheckItemsStatus, >+4 => \&CheckItemsFramework, >+5 => \&CheckItemsTitle, >+6 => \&CheckRelationshipsLoop, > ); > >-say " >- 1 : Check for items without home or holding library >- 2 : Check for authority records with invalid authority type >- 3 : Check for bibliographic records and items without an item type or with an invalid item type >- 4 : Check for invalid values in fields where the framework limits to an authorized value category >- 5 : Check for bibliographic records without a title"; >- >- >-print "Choose method(s) to run (1-5, separated by spaces): "; >-my $choices_str = <STDIN>; >-chomp($choices_str); >- >-# Split the input string into an array of choices >-my @choices = split(/\s+/, $choices_str); >- >+my @methods_to_run; >+ >+if (@ARGV == 0) { >+ # If no arguments are provided, add all methods to the list >+ @methods_to_run = keys %methods; >+} else { >+ foreach my $arg (@ARGV) { >+ if ($arg =~ /^(\d+)$/) { >+ my $method_number = $1; >+ if ($method_number >= 1 && $method_number <= 6) { >+ push @methods_to_run, $method_number; >+ } else { >+ print "Invalid method number: $method_number\n"; >+ } >+ } else { >+ print "Invalid argument: $arg\n"; >+ } >+ } >+} > >-# Run selected methods >-foreach my $choice (@choices) { >- if ($choice =~ /^\d+$/ && $choice >= 1 && $choice <= 5) { >+foreach my $choice (@methods_to_run) { >+ if ($choice =~ /^\d+$/ && $choice >= 1 && $choice <= 6) { > if (exists $methods{$choice}) { >+ print "\n"; > $methods{$choice}->(); >- } else { >+ } else { > print "Method $choice not found\n"; > } >- } else { >+ } else { > print "Invalid choice: $choice\n"; > } > } > >- >- >- > sub CheckItemsBranch { > my $items = Koha::Items->search({ -or => { homebranch => undef, holdingbranch => undef }}); > if ( $items->count ) { new_section("Not defined items.homebranch and/or items.holdingbranch")} > while ( my $item = $items->next ) { > if ( not $item->homebranch and not $item->holdingbranch ) { > new_item(sprintf "Item with itemnumber=%s does not have homebranch and holdingbranch defined", $item->itemnumber); >- } elsif ( not $item->homebranch ) { >+ } elsif ( not $item->homebranch ) { > new_item(sprintf "Item with itemnumber=%s does not have homebranch defined", $item->itemnumber); >- } else { >+ } else { > new_item(sprintf "Item with itemnumber=%s does not have holdingbranch defined", $item->itemnumber); > } > } >@@ -94,294 +103,381 @@ sub CheckItemsAuthHeader { > while ( my $authority = $authorities->next ) { > new_item(sprintf "Authority with authid=%s does not have a code defined (%s)", $authority->authid, $authority->authtypecode); > } >- if ( $authorities->count ) {new_hint("Go to 'Home ⺠Administration ⺠Authority types' to define them")} >-} >- >-sub CheckItemsStatus { >- if ( C4::Context->preference('item-level_itypes') ) { >- my $items_without_itype = Koha::Items->search( { -or => [itype => undef,itype => ''] } ); >- if ( $items_without_itype->count ) { >- new_section("Items do not have itype defined"); >- while ( my $item = $items_without_itype->next ) { >- if (defined $item->biblioitem->itemtype && $item->biblioitem->itemtype ne '' ) { >- new_item( >+ if ( $authorities->count ) {new_hint("Go to 'Home ⺠Administration ⺠Authority types' to define them")}; >+ }; >+ >+ sub CheckItemsStatus { >+ if ( C4::Context->preference('item-level_itypes') ) { >+ my $items_without_itype = Koha::Items->search( { -or => [itype => undef,itype => ''] } ); >+ if ( $items_without_itype->count ) { >+ new_section("Items do not have itype defined"); >+ while ( my $item = $items_without_itype->next ) { >+ if (defined $item->biblioitem->itemtype && $item->biblioitem->itemtype ne '' ) { >+ new_item( > sprintf "Item with itemnumber=%s does not have a itype value, biblio's item type will be used (%s)", > $item->itemnumber, $item->biblioitem->itemtype >- ); >- } else { >- new_item( >+ ); >+ } else { >+ new_item( > sprintf "Item with itemnumber=%s does not have a itype value, additionally no item type defined for biblionumber=%s", > $item->itemnumber, $item->biblioitem->biblionumber >- ); >- } >+ ); >+ } >+ } >+ new_hint("The system preference item-level_itypes expects item types to be defined at item level"); > } >- new_hint("The system preference item-level_itypes expects item types to be defined at item level"); >- } >- } >- else { >- my $biblioitems_without_itemtype = Koha::Biblioitems->search( { itemtype => undef } ); >- if ( $biblioitems_without_itemtype->count ) { >- new_section("Biblioitems do not have itemtype defined"); >- while ( my $biblioitem = $biblioitems_without_itemtype->next ) { >- new_item( >+ }else{ >+ my $biblioitems_without_itemtype = Koha::Biblioitems->search( { itemtype => undef } ); >+ if ( $biblioitems_without_itemtype->count ) { >+ new_section("Biblioitems do not have itemtype defined"); >+ while ( my $biblioitem = $biblioitems_without_itemtype->next ) { >+ new_item( > sprintf "Biblioitem with biblioitemnumber=%s does not have a itemtype value", > $biblioitem->biblioitemnumber >- ); >+ ); >+ } >+ new_hint("The system preference item-level_itypes expects item types to be defined at biblio level"); > } >- new_hint("The system preference item-level_itypes expects item types to be defined at biblio level"); > } >- } >- >- my @itemtypes = Koha::ItemTypes->search->get_column('itemtype'); >- if ( C4::Context->preference('item-level_itypes') ) { >- my $items_with_invalid_itype = Koha::Items->search( { -and => [itype => { not_in => \@itemtypes }, itype => { '!=' => '' }] } ); >- if ( $items_with_invalid_itype->count ) { >- new_section("Items have invalid itype defined"); >- while ( my $item = $items_with_invalid_itype->next ) { >- new_item( >+ >+ my @itemtypes = Koha::ItemTypes->search->get_column('itemtype'); >+ if ( C4::Context->preference('item-level_itypes') ) { >+ my $items_with_invalid_itype = Koha::Items->search( { -and => [itype => { not_in => \@itemtypes }, itype => { '!=' => '' }] } ); >+ if ( $items_with_invalid_itype->count ) { >+ new_section("Items have invalid itype defined"); >+ while ( my $item = $items_with_invalid_itype->next ) { >+ new_item( > sprintf "Item with itemnumber=%s, biblionumber=%s does not have a valid itype value (%s)", > $item->itemnumber, $item->biblionumber, $item->itype >- ); >+ ); >+ } >+ new_hint("The items must have a itype value that is defined in the item types of Koha (Home ⺠Administration ⺠Item types administration)"); > } >- new_hint("The items must have a itype value that is defined in the item types of Koha (Home ⺠Administration ⺠Item types administration)"); >- } >- } >- else { >- my $biblioitems_with_invalid_itemtype = Koha::Biblioitems->search( >+ }else{ >+ my $biblioitems_with_invalid_itemtype = Koha::Biblioitems->search( > { itemtype => { not_in => \@itemtypes } } >- ); >- if ( $biblioitems_with_invalid_itemtype->count ) { >- new_section("Biblioitems do not have itemtype defined"); >- while ( my $biblioitem = $biblioitems_with_invalid_itemtype->next ) { >- new_item( >+ ); >+ if ( $biblioitems_with_invalid_itemtype->count ) { >+ new_section("Biblioitems do not have itemtype defined"); >+ while ( my $biblioitem = $biblioitems_with_invalid_itemtype->next ) { >+ new_item( > sprintf "Biblioitem with biblioitemnumber=%s does not have a valid itemtype value", > $biblioitem->biblioitemnumber >- ); >+ ); >+ } >+ new_hint("The biblioitems must have a itemtype value that is defined in the item types of Koha (Home ⺠Administration ⺠Item types administration)"); > } >- new_hint("The biblioitems must have a itemtype value that is defined in the item types of Koha (Home ⺠Administration ⺠Item types administration)"); >- } >- } >- >- my ( @decoding_errors, @ids_not_in_marc ); >- my $biblios = Koha::Biblios->search; >- my ( $biblio_tag, $biblio_subfield ) = C4::Biblio::GetMarcFromKohaField( "biblio.biblionumber" ); >- my ( $biblioitem_tag, $biblioitem_subfield ) = C4::Biblio::GetMarcFromKohaField( "biblioitems.biblioitemnumber" ); >- while ( my $biblio = $biblios->next ) { >- my $record = eval{$biblio->metadata->record;}; >- if ($@) { >- push @decoding_errors, $@; >- next; >- } >- my ( $biblionumber, $biblioitemnumber ); >- if ( $biblio_tag < 10 ) { >- my $biblio_control_field = $record->field($biblio_tag); >- $biblionumber = $biblio_control_field->data if $biblio_control_field; >- } else { >- $biblionumber = $record->subfield( $biblio_tag, $biblio_subfield ); >- } >- if ( $biblioitem_tag < 10 ) { >- my $biblioitem_control_field = $record->field($biblioitem_tag); >- $biblioitemnumber = $biblioitem_control_field->data if $biblioitem_control_field; >- } else { >- $biblioitemnumber = $record->subfield( $biblioitem_tag, $biblioitem_subfield ); > } >- if ( $biblionumber != $biblio->biblionumber ) { >- push @ids_not_in_marc, >- { >+ >+ my ( @decoding_errors, @ids_not_in_marc ); >+ my $biblios = Koha::Biblios->search; >+ my ( $biblio_tag, $biblio_subfield ) = C4::Biblio::GetMarcFromKohaField( "biblio.biblionumber" ); >+ my ( $biblioitem_tag, $biblioitem_subfield ) = C4::Biblio::GetMarcFromKohaField( "biblioitems.biblioitemnumber" ); >+ while ( my $biblio = $biblios->next ) { >+ my $record = eval{$biblio->metadata->record;}; >+ if ($@) { >+ push @decoding_errors, $@; >+ next; >+ } >+ my ( $biblionumber, $biblioitemnumber ); >+ if ( $biblio_tag < 10 ) { >+ my $biblio_control_field = $record->field($biblio_tag); >+ $biblionumber = $biblio_control_field->data if $biblio_control_field; >+ } else { >+ $biblionumber = $record->subfield( $biblio_tag, $biblio_subfield ); >+ } >+ if ( $biblioitem_tag < 10 ) { >+ my $biblioitem_control_field = $record->field($biblioitem_tag); >+ $biblioitemnumber = $biblioitem_control_field->data if $biblioitem_control_field; >+ } else { >+ $biblioitemnumber = $record->subfield( $biblioitem_tag, $biblioitem_subfield ); >+ } >+ if ( $biblionumber != $biblio->biblionumber ) { >+ push @ids_not_in_marc, >+ { > biblionumber => $biblio->biblionumber, > biblionumber_in_marc => $biblionumber, >- }; >- } >- if ( $biblioitemnumber != $biblio->biblioitem->biblioitemnumber ) { >- push @ids_not_in_marc, >- { >+ }; >+ } >+ if ( $biblioitemnumber != $biblio->biblioitem->biblioitemnumber ) { >+ push @ids_not_in_marc, >+ { > biblionumber => $biblio->biblionumber, > biblioitemnumber => $biblio->biblioitem->biblioitemnumber, > biblioitemnumber_in_marc => $biblionumber, >- }; >+ }; >+ } > } >- } >- if ( @decoding_errors ) { >- new_section("Bibliographic records have invalid MARCXML"); >- new_item($_) for @decoding_errors; >- new_hint("The bibliographic records must have a valid MARCXML or you will face encoding issues or wrong displays"); >- } >- if (@ids_not_in_marc) { >- new_section("Bibliographic records have MARCXML without biblionumber or biblioitemnumber"); >- for my $id (@ids_not_in_marc) { >- if ( exists $id->{biblioitemnumber} ) { >- new_item( >+ if ( @decoding_errors ) { >+ new_section("Bibliographic records have invalid MARCXML"); >+ new_item($_) for @decoding_errors; >+ new_hint("The bibliographic records must have a valid MARCXML or you will face encoding issues or wrong displays"); >+ } >+ if (@ids_not_in_marc) { >+ new_section("Bibliographic records have MARCXML without biblionumber or biblioitemnumber"); >+ for my $id (@ids_not_in_marc) { >+ if ( exists $id->{biblioitemnumber} ) { >+ new_item( > sprintf(q{Biblionumber %s has biblioitemnumber '%s' but should be '%s' in %s$%s}, >- $id->{biblionumber}, >- $id->{biblioitemnumber}, >- $id->{biblioitemnumber_in_marc}, >- $biblioitem_tag, >- $biblioitem_subfield, >+ $id->{biblionumber}, >+ $id->{biblioitemnumber}, >+ $id->{biblioitemnumber_in_marc}, >+ $biblioitem_tag, >+ $biblioitem_subfield, > ) >- ); >- } >- else { >- new_item( >+ ); >+ }else{ >+ new_item( > sprintf(q{Biblionumber %s has '%s' in %s$%s}, >- $id->{biblionumber}, >- $id->{biblionumber_in_marc}, >- $biblio_tag, >- $biblio_subfield, >+ $id->{biblionumber}, >+ $id->{biblionumber_in_marc}, >+ $biblio_tag, >+ $biblio_subfield, > ) >- ); >+ ); >+ } > } >+ new_hint("The bibliographic records must have the biblionumber and biblioitemnumber in MARCXML"); > } >- new_hint("The bibliographic records must have the biblionumber and biblioitemnumber in MARCXML"); > } >-} >- >-sub CheckItemsFramework { >- my @framework_codes = Koha::BiblioFrameworks->search()->get_column('frameworkcode'); >- push @framework_codes,""; # The default is not stored in frameworks, we need to force it >- >- my $invalid_av_per_framework = {}; >- foreach my $frameworkcode ( @framework_codes ) { >- # We are only checking fields that are mapped to DB fields >- my $msss = Koha::MarcSubfieldStructures->search({ >+ >+ sub CheckItemsFramework { >+ my @framework_codes = Koha::BiblioFrameworks->search()->get_column('frameworkcode'); >+ push @framework_codes,""; # The default is not stored in frameworks, we need to force it >+ >+ my $invalid_av_per_framework = {}; >+ foreach my $frameworkcode ( @framework_codes ) { >+ # We are only checking fields that are mapped to DB fields >+ my $msss = Koha::MarcSubfieldStructures->search({ > frameworkcode => $frameworkcode, > authorised_value => { >- '!=' => [ -and => ( undef, '' ) ] >+ '!=' => [ -and => ( undef, '' ) ] > }, > kohafield => { >- '!=' => [ -and => ( undef, '' ) ] >- } >+ '!=' => [ -and => ( undef, '' ) ] >+ } > }); > while ( my $mss = $msss->next ) { > my $kohafield = $mss->kohafield; > my $av = $mss->authorised_value; > next if grep {$_ eq $av} qw( branches itemtypes cn_source ); # internal categories >- >+ > my $avs = Koha::AuthorisedValues->search_by_koha_field( >- { >- frameworkcode => $frameworkcode, >- kohafield => $kohafield, >- } >- ); >- my $tmp_kohafield = $kohafield; >- if ( $tmp_kohafield =~ /^biblioitems/ ) { >- $tmp_kohafield =~ s|biblioitems|biblioitem|; >+ { >+ frameworkcode => $frameworkcode, >+ kohafield => $kohafield, >+ } >+ ); >+ my $tmp_kohafield = $kohafield; >+ if ( $tmp_kohafield =~ /^biblioitems/ ) { >+ $tmp_kohafield =~ s|biblioitems|biblioitem|; > } else { >- $tmp_kohafield =~ s|items|me|; >- } >- # replace items.attr with me.attr >- >- # We are only checking biblios with items >- my $items = Koha::Items->search( >- { >- $tmp_kohafield => >- { >- -not_in => [ $avs->get_column('authorised_value'), '' ], >- '!=' => undef, >- }, >- 'biblio.frameworkcode' => $frameworkcode >- }, >- { join => [ 'biblioitem', 'biblio' ] } >- ); >- if ( $items->count ) { >- $invalid_av_per_framework->{ $frameworkcode }->{$av} = >- { items => $items, kohafield => $kohafield }; >- } >+ $tmp_kohafield =~ s|items|me|; >+ } >+ # replace items.attr with me.attr >+ >+ # We are only checking biblios with items >+ my $items = Koha::Items->search( >+ { >+ $tmp_kohafield => >+ { >+ -not_in => [ $avs->get_column('authorised_value'), '' ], >+ '!=' => undef, >+ }, >+ 'biblio.frameworkcode' => $frameworkcode >+ }, >+ { join => [ 'biblioitem', 'biblio' ] } >+ ); >+ if ( $items->count ) { >+ $invalid_av_per_framework->{ $frameworkcode }->{$av} = >+ { items => $items, kohafield => $kohafield }; > } > } >- if (%$invalid_av_per_framework) { >- new_section('Wrong values linked to authorised values'); >- for my $frameworkcode ( keys %$invalid_av_per_framework ) { >- while ( my ( $av_category, $v ) = each %{$invalid_av_per_framework->{$frameworkcode}} ) { >- my $items = $v->{items}; >- my $kohafield = $v->{kohafield}; >- my ( $table, $column ) = split '\.', $kohafield; >- my $output; >- while ( my $i = $items->next ) { >- my $value = $table eq 'items' >- ? $i->$column >- : $table eq 'biblio' >- ? $i->biblio->$column >- : $i->biblioitem->$column; >- $output .= " {" . $i->itemnumber . " => " . $value . "}\n"; >- } >- new_item( >- sprintf( >- "The Framework *%s* is using the authorised value's category *%s*, " >- . "but the following %s do not have a value defined ({itemnumber => value }):\n%s", >- $frameworkcode, $av_category, $kohafield, $output >- ) >- ); >+} >+if (%$invalid_av_per_framework) { >+ new_section('Wrong values linked to authorised values'); >+ for my $frameworkcode ( keys %$invalid_av_per_framework ) { >+ while ( my ( $av_category, $v ) = each %{$invalid_av_per_framework->{$frameworkcode}} ) { >+ my $items = $v->{items}; >+ my $kohafield = $v->{kohafield}; >+ my ( $table, $column ) = split '\.', $kohafield; >+ my $output; >+ while ( my $i = $items->next ) { >+ my $value = $table eq 'items' >+ ? $i->$column >+ : $table eq 'biblio' >+ ? $i->biblio->$column >+ : $i->biblioitem->$column; >+ $output .= " {" . $i->itemnumber . " => " . $value . "}\n"; > } >+ new_item( >+ sprintf( >+ "The Framework *%s* is using the authorised value's category *%s*, " >+ . "but the following %s do not have a value defined ({itemnumber => value }):\n%s", >+ $frameworkcode, $av_category, $kohafield, $output >+ ) >+ ); > } > } > } >+} > > sub CheckItemsTitle { >- my $biblios = Koha::Biblios->search({ >- -or => [ >- title => '', >- title => undef, >- ] >- }); >- if ( $biblios->count ) { >- my ( $title_tag, $title_subtag ) = C4::Biblio::GetMarcFromKohaField( 'biblio.title' ); >- my $title_field = $title_tag // ''; >- $title_field .= '$'.$title_subtag if $title_subtag; >- new_section("Biblio without title $title_field"); >- while ( my $biblio = $biblios->next ) { >- new_item(sprintf "Biblio with biblionumber=%s does not have title defined", $biblio->biblionumber); >- } >- new_hint("Edit these bibliographic records to define a title"); >+my $biblios = Koha::Biblios->search({ >+-or => [ >+title => '', >+title => undef, >+] >+}); >+if ( $biblios->count ) { >+ my ( $title_tag, $title_subtag ) = C4::Biblio::GetMarcFromKohaField( 'biblio.title' ); >+ my $title_field = $title_tag // ''; >+ $title_field .= '$'.$title_subtag if $title_subtag; >+ new_section("Biblio without title $title_field"); >+ while ( my $biblio = $biblios->next ) { >+ new_item(sprintf "Biblio with biblionumber=%s does not have title defined", $biblio->biblionumber); > } >+ new_hint("Edit these bibliographic records to define a title"); >+} > } > > sub CheckAgeForCategory { >- my $aging_patrons = Koha::Patrons->search( >- { >- -not => { >- -or => { >- 'me.dateofbirth' => undef, >- -and => { >- 'categorycode.dateofbirthrequired' => undef, >- 'categorycode.upperagelimit' => undef, >- } >- } >- } >- }, >- { prefetch => ['categorycode'] }, >- { order_by => [ 'me.categorycode', 'me.borrowernumber' ] }, >- ); >- my @invalid_patrons; >- while ( my $aging_patron = $aging_patrons->next ) { >- push @invalid_patrons, $aging_patron unless $aging_patron->is_expired || $aging_patron->is_valid_age; >+my $aging_patrons = Koha::Patrons->search( >+{ >+-not => { >+-or => { >+'me.dateofbirth' => undef, >+-and => { >+'categorycode.dateofbirthrequired' => undef, >+'categorycode.upperagelimit' => undef, >+} >+} >+} >+}, >+{ prefetch => ['categorycode'] }, >+{ order_by => [ 'me.categorycode', 'me.borrowernumber' ] }, >+); >+my @invalid_patrons; >+while ( my $aging_patron = $aging_patrons->next ) { >+push @invalid_patrons, $aging_patron unless $aging_patron->is_expired || $aging_patron->is_valid_age; >+} >+if (@invalid_patrons) { >+new_section("Patrons with invalid age for category"); >+foreach my $invalid_patron (@invalid_patrons) { >+my $category = $invalid_patron->category; >+new_item( >+sprintf "Patron borrowernumber=%s has an invalid age of %s for their category '%s' (%s to %s)", >+$invalid_patron->borrowernumber, $invalid_patron->get_age, $category->categorycode, >+$category->dateofbirthrequired // '0', $category->upperagelimit // 'unlimited' >+); >+} >+new_hint("You may change the patron's category automatically with misc/cronjobs/update_patrons_category.pl"); >+} >+} >+ >+sub CheckRelationshipsLoop { >+my @loop_borrowers_relationships; >+my @relationships = Koha::Patron::Relationships->search(); >+my @patrons_guarantors = Koha::Patron::Relationships::guarantors(@relationships)->as_list; >+my @patrons_guarantees = Koha::Patron::Relationships::guarantees(@relationships)->as_list; >+ >+foreach my $patron_guarantor (@patrons_guarantors) { >+foreach my $patron_guarantee (@patrons_guarantees) { >+if ($patron_guarantor->borrowernumber == $patron_guarantee->borrowernumber) { >+ >+my $relationship_id; >+my $guarantee_id; >+my $size_list; >+my $tmp_garantor_id = $patron_guarantor->borrowernumber; >+my @relationship_ids; >+my @guarantor_to_find; >+ >+push @guarantor_to_find, $patron_guarantor->borrowernumber; >+ >+do { >+my @relationship_for_go = Koha::Patron::Relationships->search( >+{ >+-or => [ >+'guarantor_id' => { '=', $tmp_garantor_id }, >+] >+}, >+)->as_list; >+$size_list = scalar @relationship_for_go; >+ >+foreach my $relation (@relationship_for_go) { >+ $relationship_id = $relation->id; >+ unless (grep { $_ == $relationship_id } @relationship_ids) { >+ push @relationship_ids, $relationship_id; > } >- if (@invalid_patrons) { >- new_section("Patrons with invalid age for category"); >- foreach my $invalid_patron (@invalid_patrons) { >- my $category = $invalid_patron->category; >- new_item( >- sprintf "Patron borrowernumber=%s has an invalid age of %s for their category '%s' (%s to %s)", >- $invalid_patron->borrowernumber, $invalid_patron->get_age, $category->categorycode, >- $category->dateofbirthrequired // '0', $category->upperagelimit // 'unlimited' >- ); >+ $guarantee_id = $relation->guarantee_id; >+ >+ if (grep { $_ eq $guarantee_id } @guarantor_to_find) { >+ last; >+ } >+ >+ my @relationship_for_go = Koha::Patron::Relationships->search( >+ { >+ -or => [ >+ 'guarantor_id' => { '=', $guarantee_id }, >+ ] >+ }, >+ )->as_list; >+ $size_list = scalar @relationship_for_go; >+ >+ push @guarantor_to_find, $guarantee_id; >+ >+ foreach my $relation (@relationship_for_go) { >+ $relationship_id = $relation->id; >+ unless (grep { $_ == $relationship_id } @relationship_ids) { >+ push @relationship_ids, $relationship_id; >+ } >+ $guarantee_id = $relation->guarantee_id; >+ >+ if (grep { $_ eq $guarantee_id } @guarantor_to_find) { >+ last; > } >- new_hint("You may change the patron's category automatically with misc/cronjobs/update_patrons_category.pl"); >+ } >+ if (grep { $_ eq $guarantee_id } @guarantor_to_find) { >+ last; > } > } > >+$tmp_garantor_id = $guarantee_id; >+} while ((!grep { $_ eq $guarantee_id } @guarantor_to_find) && $size_list > 0); >+ >+if ($patron_guarantor->borrowernumber == $guarantee_id) { >+ unless (grep { join("", sort @$_) eq join("", sort @relationship_ids) } @loop_borrowers_relationships) { >+ push @loop_borrowers_relationships, \@relationship_ids; >+ } >+} >+} >+} >+} >+ >+if (scalar @loop_borrowers_relationships > 0) { >+new_section("The list of relationships id with guarantors who are also guarantee."); >+foreach my $table (@loop_borrowers_relationships) { >+new_item( >+sprintf "Relationships connected : %s |", >+join(" | ", @$table) >+); >+} >+new_hint("Relationships that form guarantor loops must be deleted"); >+} >+} > > sub new_section { >- my ( $name ) = @_; >- say "\n== $name =="; >+my ( $name ) = @_; >+say "\n== $name =="; > } > > sub new_item { >- my ( $name ) = @_; >- say "\t* $name"; >+my ( $name ) = @_; >+say "\t* $name"; > } > sub new_hint { >- my ( $name ) = @_; >- say "=> $name"; >+my ( $name ) = @_; >+say "=> $name"; > } > > =head1 NAME >@@ -390,7 +486,7 @@ search_for_data_inconsistencies.pl > > =head1 SYNOPSIS > >- perl search_for_data_inconsistencies.pl >+perl search_for_data_inconsistencies.pl > > =head1 DESCRIPTION > >@@ -399,9 +495,9 @@ Catch data inconsistencies in Koha database > * Items with undefined homebranch and/or holdingbranch > * Authorities with undefined authtypecodes/authority types > * Item types: >- * if item types are defined at item level (item-level_itypes=specific item), >- then items.itype must be set else biblioitems.itemtype must be set >- * Item types defined in items or biblioitems must be defined in the itemtypes table >+* if item types are defined at item level (item-level_itypes=specific item), >+then items.itype must be set else biblioitems.itemtype must be set >+* Item types defined in items or biblioitems must be defined in the itemtypes table > * Invalid MARCXML in bibliographic records > * Patrons with invalid category types due to lower and upper age limits > >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36027
:
161852
|
161953
|
161954
|
162162
|
162349
|
162351
|
162540
|
162546
|
163259
|
163956
|
166117
|
167766
|
167787
|
168953
|
168954
|
169228
|
169229
|
170847
|
170848
|
170849
|
173269
|
173270
|
173271
|
173556