@@ -, +, @@ --- C4/AuthoritiesMarc.pm | 15 +- C4/Biblio.pm | 47 +-- C4/Linker/Default.pm | 5 +- Koha/Authorities.pm | 24 ++ .../searchengine/elasticsearch/mappings.yaml | 320 +++++++++++++++--- authorities/blinddetail-biblio-search.pl | 4 +- authorities/detail.pl | 3 +- cataloguing/addbiblio.pl | 13 +- .../marc21/biblios/biblio-koha-indexdefs.xml | 154 ++++----- .../marc21/biblios/biblio-zebra-indexdefs.xsl | 92 ++--- .../normarc/biblios/biblio-koha-indexdefs.xml | 118 +++---- .../biblios/biblio-zebra-indexdefs.xsl | 58 ++-- .../authorities/blinddetail-biblio-search.tt | 3 +- misc/maintenance/batchAuthorityLinking.pl | 210 ++++++++++++ t/db_dependent/Koha/Authorities.t | 56 ++- 15 files changed, 822 insertions(+), 300 deletions(-) create mode 100755 misc/maintenance/batchAuthorityLinking.pl --- a/C4/AuthoritiesMarc.pm +++ a/C4/AuthoritiesMarc.pm @@ -888,6 +888,7 @@ sub BuildSummary { my @seefrom; my @seealso; my @otherscript; + my $authsubfield = Koha::Authorities->authority_linking_subfield; if (C4::Context->preference('marcflavour') eq 'UNIMARC') { # construct UNIMARC summary, that is quite different from MARC21 one # accepted form @@ -922,7 +923,7 @@ sub BuildSummary { heading => $heading, hemain => ( $_->subfield('a') // undef ), search => $heading, - authid => ( $_->subfield('9') // undef ), + authid => ( $_->subfield($authsubfield) // undef ), } } $record->field('5..'); @@ -1021,7 +1022,7 @@ sub BuildSummary { type => $field->subfield('i'), field => $field->tag(), search => $field->as_string($marc21subfields) || '', - authid => $field->subfield('9') || '' + authid => $field->subfield($authsubfield) || '' }; } else { push @seealso, { @@ -1030,7 +1031,7 @@ sub BuildSummary { type => $type, field => $field->tag(), search => $field->as_string($marc21subfields) || '', - authid => $field->subfield('9') || '' + authid => $field->subfield($authsubfield) || '' }; } } @@ -1305,7 +1306,8 @@ sub GenerateHierarchy { sub _get_authid_subfield{ my ($field)=@_; - return $field->subfield('9')||$field->subfield('3'); + my $authsubfield = Koha::Authorities->authority_linking_subfield; + return $field->subfield($authsubfield)||$field->subfield('3'); } =head2 GetHeaderAuthority @@ -1408,6 +1410,7 @@ sub merge { # Search authtypes and reporting tags my $authfrom = Koha::Authorities->find($mergefrom); my $authto = Koha::Authorities->find($mergeto); + my $authsubfield = Koha::Authorities->authority_linking_subfield; my $authtypefrom = $authfrom ? Koha::Authority::Types->find($authfrom->authtypecode) : undef; my $authtypeto = $authto ? Koha::Authority::Types->find($authto->authtypecode) : undef; my $auth_tag_to_report_from = $authtypefrom ? $authtypefrom->auth_tag_to_report : ''; @@ -1459,7 +1462,7 @@ sub merge { foreach my $tagfield (@$tags_using_authtype) { my $countfrom = 0; # used in strict mode to remove duplicates foreach my $field ( $marcrecord->field($tagfield) ) { - my $auth_number = $field->subfield("9"); # link to authority + my $auth_number = $field->subfield($authsubfield); # link to authority my $tag = $field->tag(); next if !defined($auth_number) || $auth_number ne $mergefrom; $countfrom++; @@ -1479,7 +1482,7 @@ sub merge { $newtag, $controlled_ind->{ind1} // $field->indicator(1), $controlled_ind->{ind2} // $field->indicator(2), - 9 => $mergeto, # Needed to create field, will be moved + $authsubfield => $mergeto, # Needed to create field, will be moved ); my ( @prefix, @postfix ); if ( !$overwrite ) { --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -99,6 +99,7 @@ use C4::OAI::Sets; use C4::Debug; use Koha::Caches; +use Koha::Authorities; use Koha::Authority::Types; use Koha::Acquisition::Currencies; use Koha::Biblio::Metadatas; @@ -280,7 +281,7 @@ sub ModBiblio { # throw an exception which probably won't be handled. foreach my $field ($record->fields()) { if (! $field->is_control_field()) { - if (scalar($field->subfields()) == 0 || (scalar($field->subfields()) == 1 && $field->subfield('9'))) { + if (scalar($field->subfields()) == 0 || (scalar($field->subfields()) == 1 && $field->subfield('0'))) { $record->delete_field($field); } } @@ -489,6 +490,7 @@ sub LinkBibHeadingsToAuthorities { require C4::Heading; require C4::AuthoritiesMarc; + my $authsubfield = Koha::Authorities->authority_linking_subfield; $allowrelink = 1 unless defined $allowrelink; my $num_headings_changed = 0; foreach my $field ( $bib->fields() ) { @@ -496,7 +498,7 @@ sub LinkBibHeadingsToAuthorities { next unless defined $heading; # check existing $9 - my $current_link = $field->subfield('9'); + my $current_link = $field->subfield($authsubfield); if ( defined $current_link && (!$allowrelink || !C4::Context->preference('LinkerRelink')) ) { @@ -510,8 +512,8 @@ sub LinkBibHeadingsToAuthorities { ->{ $heading->display_form() }++; next if defined $current_link and $current_link == $authid; - $field->delete_subfield( code => '9' ) if defined $current_link; - $field->add_subfields( '9', $authid ); + $field->delete_subfield( code => $authsubfield ) if defined $current_link; + $field->add_subfields( $authsubfield, $authid ); $num_headings_changed++; } else { @@ -531,7 +533,7 @@ sub LinkBibHeadingsToAuthorities { $marcrecordauth->leader(' nz a22 o 4500'); SetMarcUnicodeFlag( $marcrecordauth, 'MARC21' ); } - $field->delete_subfield( code => '9' ) + $field->delete_subfield( code => $authsubfield ) if defined $current_link; my $authfield = MARC::Field->new( $authority_type->auth_tag_to_report, @@ -584,7 +586,7 @@ sub LinkBibHeadingsToAuthorities { $authid = C4::AuthoritiesMarc::AddAuthority( $marcrecordauth, '', $heading->auth_type() ); - $field->add_subfields( '9', $authid ); + $field->add_subfields( $authsubfield, $authid ); $num_headings_changed++; $linker->update_cache($heading, $authid); $results{'added'}->{ $heading->display_form() }++; @@ -595,7 +597,7 @@ sub LinkBibHeadingsToAuthorities { $results{'linked'}->{ $heading->display_form() }++; } else { - $field->delete_subfield( code => '9' ); + $field->delete_subfield( code => $authsubfield ); $num_headings_changed++; $results{'unlinked'}->{ $heading->display_form() }++; } @@ -1739,6 +1741,7 @@ sub GetMarcSubjects { my $subject_limit = C4::Context->preference("TraceCompleteSubfields") ? 'su,complete-subfield' : 'su'; my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator'); + my $authsubfield = Koha::Authorities->authority_linking_subfield; foreach my $field ( $record->field($fields_filter) ) { next unless ($field->tag() >= $mintag && $field->tag() <= $maxtag); @@ -1746,11 +1749,11 @@ sub GetMarcSubjects { my @subfields = $field->subfields(); my @link_loop; - # if there is an authority link, build the links with an= subfield9 - my $subfield9 = $field->subfield('9'); + # if there is an authority link, build the links with an=$authsubfield + my $auth_subfield = $field->subfield($authsubfield); my $authoritylink; - if ($subfield9) { - my $linkvalue = $subfield9; + if ($auth_subfield) { + my $linkvalue = $auth_subfield; $linkvalue =~ s/(\(|\))//g; @link_loop = ( { limit => 'an', 'link' => $linkvalue } ); $authoritylink = $linkvalue @@ -1758,7 +1761,7 @@ sub GetMarcSubjects { # other subfields for my $subject_subfield (@subfields) { - next if ( $subject_subfield->[0] eq '9' ); + next if ( $subject_subfield->[0] eq $authsubfield ); # don't load unimarc subfields 3,4,5 next if ( ( $marcflavour eq "UNIMARC" ) and ( $subject_subfield->[0] =~ /2|3|4|5/ ) ); @@ -1770,7 +1773,7 @@ sub GetMarcSubjects { my $linkvalue = $value; $linkvalue =~ s/(\(|\))//g; # if no authority link, build a search query - unless ($subfield9) { + unless ($auth_subfield) { push @link_loop, { limit => $subject_limit, 'link' => $linkvalue, @@ -1831,6 +1834,7 @@ sub GetMarcAuthors { my @marcauthors; my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator'); + my $authsubfield = Koha::Authorities->authority_linking_subfield; foreach my $field ( $record->field($fields_filter) ) { next unless $field->tag() >= $mintag && $field->tag() <= $maxtag; @@ -1839,10 +1843,10 @@ sub GetMarcAuthors { my @subfields = $field->subfields(); my $count_auth = 0; - # if there is an authority link, build the link with Koha-Auth-Number: subfield9 - my $subfield9 = $field->subfield('9'); - if ($subfield9) { - my $linkvalue = $subfield9; + # if there is an authority link, build the link with Koha-Auth-Number: $authsubfield + my $auth_subfield = $field->subfield($authsubfield); + if ($auth_subfield) { + my $linkvalue = $auth_subfield; $linkvalue =~ s/(\(|\))//g; @link_loop = ( { 'limit' => 'an', 'link' => $linkvalue } ); } @@ -1850,7 +1854,7 @@ sub GetMarcAuthors { # other subfields my $unimarc3; for my $authors_subfield (@subfields) { - next if ( $authors_subfield->[0] eq '9' ); + next if ( $authors_subfield->[0] eq $authsubfield ); # unimarc3 contains the $3 of the author for UNIMARC. # For french academic libraries, it's the "ppn", and it's required for idref webservice @@ -1869,7 +1873,7 @@ sub GetMarcAuthors { $linkvalue = "($value)"; } # if no authority link, build a search query - unless ($subfield9) { + unless ($auth_subfield) { push @link_loop, { limit => 'au', 'link' => $linkvalue, @@ -1890,7 +1894,7 @@ sub GetMarcAuthors { } push @marcauthors, { MARCAUTHOR_SUBFIELDS_LOOP => \@subfields_loop, - authoritylink => $subfield9, + authoritylink => $auth_subfield, unimarc3 => $unimarc3 }; } @@ -1986,6 +1990,7 @@ sub GetMarcSeries { my @marcseries; my $AuthoritySeparator = C4::Context->preference('AuthoritySeparator'); + my $authsubfield = Koha::Authorities->authority_linking_subfield; foreach my $field ( $record->field($fields_filter) ) { next unless $field->tag() >= $mintag && $field->tag() <= $maxtag; @@ -1996,7 +2001,7 @@ sub GetMarcSeries { for my $series_subfield (@subfields) { # ignore $9, used for authority link - next if ( $series_subfield->[0] eq '9' ); + next if ( $series_subfield->[0] eq $authsubfield ); my $volume_number; my $code = $series_subfield->[0]; --- a/C4/Linker/Default.pm +++ a/C4/Linker/Default.pm @@ -22,6 +22,7 @@ use warnings; use Carp; use MARC::Field; use C4::Heading; +use Koha::Authorities; use base qw(C4::Linker); @@ -32,7 +33,7 @@ sub get_link { my $search_form = $heading->search_form(); my $authid; my $fuzzy = 0; - + my $authsubfield = Koha::Authorities->authority_linking_subfield; if ( $self->{'cache'}->{$search_form}->{'cached'} ) { $authid = $self->{'cache'}->{$search_form}->{'authid'}; $fuzzy = $self->{'cache'}->{$search_form}->{'fuzzy'}; @@ -56,7 +57,7 @@ sub get_link { if ( !defined $authid && $self->{'broader_headings'} ) { my $field = $heading->field(); - my @subfields = grep { $_->[0] ne '9' } $field->subfields(); + my @subfields = grep { $_->[0] ne $authsubfield } $field->subfields(); if ( scalar @subfields > 1 ) { pop @subfields; $field = --- a/Koha/Authorities.pm +++ a/Koha/Authorities.pm @@ -22,6 +22,7 @@ use Modern::Perl; use Carp; use Koha::Database; +use C4::Context; use Koha::Authority; @@ -94,6 +95,29 @@ sub linked_biblionumbers { return @biblionumbers; } +=head3 authority_linking_subfield + + $authsubfield = Koha::Authorities->authority_linking_subfield; + + Returns the authority subfield for selected MARC format + +=cut + +sub authority_linking_subfield { + my ( $class ) = @_; + + my $marcflavour = C4::Context->preference('marcflavour'); + + my $subfield; + if ($marcflavour eq 'UNIMARC') { + $subfield = '9'; + } else { + $subfield = '0'; + } + + return $subfield; +} + =head3 type =cut --- a/admin/searchengine/elasticsearch/mappings.yaml +++ a/admin/searchengine/elasticsearch/mappings.yaml @@ -2283,231 +2283,461 @@ biblios: mappings: - facet: '' marc_field: '1009' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '1109' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '1119' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '1309' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '2459' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '4009' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '4109' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '4409' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '4909' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6009' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6109' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6119' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6309' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6489' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6509' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6519' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6529' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6539' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6549' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6559' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6569' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6579' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6629' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6909' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6919' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6969' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6979' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6989' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '6999' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '7009' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '7109' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '7119' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '7309' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '7519' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '7969' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '7979' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '7989' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '7999' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '8009' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '8109' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '8119' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '8309' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '8969' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '8979' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '8989' - marc_type: marc21 + marc_type: unimarc sort: ~ suggestible: '' - facet: '' marc_field: '8999' + marc_type: unimarc + sort: ~ + suggestible: '' + - facet: '' + marc_field: '1000' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '1100' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '1110' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '1300' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '2450' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '4000' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '4100' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '4400' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '4900' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6000' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6100' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6110' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6300' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6480' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6500' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6510' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6520' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6530' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6540' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6550' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6560' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6570' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6620' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6900' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6910' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6960' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6970' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6980' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '6990' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '7000' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '7100' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '7110' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '7300' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '7510' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '7960' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '7970' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '7980' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '7990' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '8000' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '8100' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '8110' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '8300' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '8960' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '8970' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '8980' + marc_type: marc21 + sort: ~ + suggestible: '' + - facet: '' + marc_field: '8990' marc_type: marc21 sort: ~ suggestible: '' --- a/authorities/blinddetail-biblio-search.pl +++ a/authorities/blinddetail-biblio-search.pl @@ -57,6 +57,7 @@ my $authid = $query->param('authid'); my $index = $query->param('index'); my $tagid = $query->param('tagid'); my $relationship = $query->param('relationship'); +my $authsubfield = Koha::Authorities->authority_linking_subfield; # open template my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -88,7 +89,7 @@ if ($authid) { # Get all values for each distinct subfield and add to subfield loop my %done_subfields; for ( $field->subfields ) { - next if $_->[0] eq '9'; # $9 will be set with authid value + next if $_->[0] eq $authsubfield; # will be set with authid value my $letter = $_->[0]; $letter ||= '@'; next if defined $done_subfields{$letter}; @@ -115,6 +116,7 @@ if ($authid) { $template->param( authid => $authid ? $authid : "", + authsubfield => $authsubfield, index => $index, tagid => $tagid, update_ind1 => defined($indicator1), --- a/authorities/detail.pl +++ a/authorities/detail.pl @@ -210,8 +210,9 @@ my $count = $authobj ? $authobj->get_usage_count : 0; my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?"); $sth->execute($authtypecode); my $biblio_fields; +my $authsubfield = Koha::Authorities->authority_linking_subfield; while (my ($tagfield) = $sth->fetchrow) { - $biblio_fields.= $tagfield."9,"; + $biblio_fields.= $tagfield.$authsubfield.","; } chop $biblio_fields if $biblio_fields; --- a/cataloguing/addbiblio.pl +++ a/cataloguing/addbiblio.pl @@ -328,16 +328,16 @@ sub create_input { # expand all subfields of 773 if there is a host item provided in the input $subfield_data{visibility} ="" if ($tag eq 773 and $cgi->param('hostitemnumber')); - + my $authsubfield = Koha::Authorities->authority_linking_subfield; # it's an authorised field if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) { $subfield_data{marc_value} = build_authorized_values_list( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ); - # it's a subfield $9 linking to an authority record - see bug 2206 + # it's a subfield linking to an authority record - see bug 2206 } - elsif ($subfield eq "9" and + elsif ($subfield eq $authsubfield and exists($tagslib->{$tag}->{'a'}->{authtypecode}) and defined($tagslib->{$tag}->{'a'}->{authtypecode}) and $tagslib->{$tag}->{'a'}->{authtypecode} ne '') { @@ -489,7 +489,8 @@ sub build_tabs { my @BIG_LOOP; my %seen; my @tab_data; # all tags to display - + my $authsubfield = Koha::Authorities->authority_linking_subfield; + foreach my $used ( @$usedTagsLib ){ push @tab_data,$used->{tagfield} if not $seen{$used->{tagfield}}; $seen{$used->{tagfield}}++; @@ -576,7 +577,7 @@ sub build_tabs { next if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 ) or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 ) ) - and not ( $subfield eq "9" and + and not ( $subfield eq $authsubfield and exists($tagslib->{$tag}->{'a'}->{authtypecode}) and defined($tagslib->{$tag}->{'a'}->{authtypecode}) and $tagslib->{$tag}->{'a'}->{authtypecode} ne "" @@ -625,7 +626,7 @@ sub build_tabs { next if ( ( $tagslib->{$tag}->{$subfield}->{hidden} <= -4 ) or ( $tagslib->{$tag}->{$subfield}->{hidden} >= 5 ) ) - and not ( $subfield eq "9" and + and not ( $subfield eq $authsubfield and exists($tagslib->{$tag}->{'a'}->{authtypecode}) and defined($tagslib->{$tag}->{'a'}->{authtypecode}) and $tagslib->{$tag}->{'a'}->{authtypecode} ne "" --- a/etc/zebradb/marc_defs/marc21/biblios/biblio-koha-indexdefs.xml +++ a/etc/zebradb/marc_defs/marc21/biblios/biblio-koha-indexdefs.xml @@ -257,8 +257,8 @@ Number-govt-pub:w - - + + Cross-Reference:w Koha-Auth-Number:w @@ -283,8 +283,8 @@ Name-and-title:w Personal-name:w - - + + Koha-Auth-Number:w @@ -298,8 +298,8 @@ Name-and-title:w Corporate-name:w - - + + Koha-Auth-Number:w @@ -321,8 +321,8 @@ Music-key:w - - + + Koha-Auth-Number:w @@ -404,8 +404,8 @@ Author-in-order:p Author-in-order:s - - + + Cross-Reference:w Koha-Auth-Number:w @@ -470,8 +470,8 @@ Title:w Title-series:w - - + + Koha-Auth-Number:w @@ -491,8 +491,8 @@ Title:w Title-series:w - - + + Koha-Auth-Number:w @@ -519,8 +519,8 @@ Title-series:w Title-series:p - - + + Koha-Auth-Number:w @@ -535,8 +535,8 @@ Title-series:w Title-series:p - - + + Koha-Auth-Number:w @@ -628,8 +628,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -653,8 +653,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -677,8 +677,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -700,8 +700,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -709,11 +709,11 @@ Subject:w Subject:p - + Koha-Auth-Number:w - - + + Koha-Auth-Number:w @@ -721,8 +721,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -731,8 +731,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -742,8 +742,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -751,8 +751,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -767,8 +767,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -776,8 +776,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -785,8 +785,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -820,11 +820,11 @@ Subject:w Subject:p - + Koha-Auth-Number:w - - + + Koha-Auth-Number:w @@ -832,23 +832,23 @@ Subject:w Subject:p - + Koha-Auth-Number:w - + Koha-Auth-Number:w - + Koha-Auth-Number:w - + Koha-Auth-Number:w - + Koha-Auth-Number:w - - + + Cross-Reference:w Koha-Auth-Number:w @@ -892,8 +892,8 @@ Name-and-title:w - - + + Koha-Auth-Number:w @@ -913,8 +913,8 @@ Title:w Title-uniform:w - - + + Koha-Auth-Number:w @@ -933,8 +933,8 @@ Music-key:w - - + + Koha-Auth-Number:w @@ -953,8 +953,8 @@ Name-geographic:w - - + + Koha-Auth-Number:w @@ -1031,16 +1031,16 @@ Record-control-number:w - + Koha-Auth-Number:w - + Koha-Auth-Number:w - + Koha-Auth-Number:w - + Koha-Auth-Number:w @@ -1057,8 +1057,8 @@ Title-series:w Title-series:p - - + + Koha-Auth-Number:w @@ -1090,8 +1090,8 @@ Record-control-number:w - - + + Koha-Auth-Number:w @@ -1107,8 +1107,8 @@ Title-series:w Title-series:p - - + + Koha-Auth-Number:w @@ -1134,8 +1134,8 @@ Record-control-number:w - - + + Koha-Auth-Number:w @@ -1150,16 +1150,16 @@ Title-series:w Title-series:p - + Koha-Auth-Number:w - + Koha-Auth-Number:w - + Koha-Auth-Number:w - + Koha-Auth-Number:w --- a/etc/zebradb/marc_defs/marc21/biblios/biblio-zebra-indexdefs.xsl +++ a/etc/zebradb/marc_defs/marc21/biblios/biblio-zebra-indexdefs.xsl @@ -239,7 +239,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -255,7 +255,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -264,7 +264,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -287,7 +287,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -342,7 +342,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -388,7 +388,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -411,7 +411,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -443,7 +443,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -459,7 +459,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -552,7 +552,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -575,7 +575,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -598,7 +598,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -621,7 +621,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -630,7 +630,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -639,7 +639,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -648,7 +648,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -657,7 +657,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -673,7 +673,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -682,7 +682,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -698,7 +698,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -707,7 +707,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -716,7 +716,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -748,7 +748,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -757,7 +757,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -766,7 +766,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -775,7 +775,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -784,7 +784,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -793,7 +793,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -802,7 +802,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -811,7 +811,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -862,7 +862,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -885,7 +885,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -908,7 +908,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -924,7 +924,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -1051,7 +1051,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -1060,7 +1060,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -1069,7 +1069,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -1078,7 +1078,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -1101,7 +1101,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -1138,7 +1138,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -1154,7 +1154,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -1184,7 +1184,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -1193,7 +1193,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -1202,7 +1202,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -1211,7 +1211,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -1220,7 +1220,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + --- a/etc/zebradb/marc_defs/normarc/biblios/biblio-koha-indexdefs.xml +++ a/etc/zebradb/marc_defs/normarc/biblios/biblio-koha-indexdefs.xml @@ -163,8 +163,8 @@ Dewey-classification:w Dewey-classification:s - - + + Cross-Reference:w Koha-Auth-Number:w @@ -187,8 +187,8 @@ Name-and-title:w Personal-name:w - - + + Koha-Auth-Number:w @@ -200,8 +200,8 @@ Name-and-title:w Corporate-name:w - - + + Koha-Auth-Number:w @@ -225,8 +225,8 @@ Music-key:w - - + + Koha-Auth-Number:w @@ -278,8 +278,8 @@ Author-in-order:p Author-in-order:s - - + + Cross-Reference:w Koha-Auth-Number:w @@ -325,8 +325,8 @@ Title-series:w Title-series:p - - + + Koha-Auth-Number:w @@ -346,8 +346,8 @@ Title:w Title-series:w - - + + Koha-Auth-Number:w @@ -384,8 +384,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -409,8 +409,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -440,8 +440,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -468,8 +468,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -477,11 +477,11 @@ Subject:w Subject:p - + Koha-Auth-Number:w - - + + Koha-Auth-Number:w @@ -489,8 +489,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -499,12 +499,12 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w - - + + Koha-Auth-Number:w @@ -512,8 +512,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -521,8 +521,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -530,8 +530,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -539,8 +539,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -548,8 +548,8 @@ Subject:w Subject:p - - + + Koha-Auth-Number:w @@ -557,8 +557,8 @@ Subject:w Subject:p - - + + Cross-Reference:w Koha-Auth-Number:w @@ -615,8 +615,8 @@ Thematic-number:w - - + + Koha-Auth-Number:w @@ -634,8 +634,8 @@ Title:w Title-uniform:w - - + + Koha-Auth-Number:w @@ -656,8 +656,8 @@ Music-key:w - - + + Koha-Auth-Number:w @@ -674,8 +674,8 @@ Host-item:w - - + + Host-Item-Number:w @@ -711,8 +711,8 @@ Title:w Title-series:w - - + + Koha-Auth-Number:w @@ -733,8 +733,8 @@ Title:w Title-series:w - - + + Koha-Auth-Number:w @@ -748,8 +748,8 @@ Name-and-title:w - - + + Koha-Auth-Number:w @@ -766,8 +766,8 @@ Name:w Conference-name:w - - + + Koha-Auth-Number:w --- a/etc/zebradb/marc_defs/normarc/biblios/biblio-zebra-indexdefs.xsl +++ a/etc/zebradb/marc_defs/normarc/biblios/biblio-zebra-indexdefs.xsl @@ -149,7 +149,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -165,7 +165,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -174,7 +174,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -204,7 +204,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -250,7 +250,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -289,7 +289,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -305,7 +305,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -328,7 +328,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -351,7 +351,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -374,7 +374,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -404,7 +404,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -413,7 +413,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -422,7 +422,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -431,7 +431,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -440,7 +440,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -449,7 +449,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -458,7 +458,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -467,7 +467,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -476,7 +476,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -485,7 +485,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -494,7 +494,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -503,7 +503,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -568,7 +568,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -591,7 +591,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -621,7 +621,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -683,7 +683,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -706,7 +706,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -722,7 +722,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + @@ -738,7 +738,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml) - + --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tt @@ -40,6 +40,7 @@ RancorReplaceField( new_line, "[% indicator1 | html %]", "[% indicator2 | html %]" ); [% ELSE %] var index_start = "[% index | html %]"; + var authsubfield = "[% authsubfield %]"; var whichfield; try { whichfield = opener.opener.document.getElementById(index_start); @@ -135,7 +136,7 @@ [% IF ( clear ) %] if (subfield){subfield.value="" ;} [% ELSE %] - if(code.value=='9'){ + if(code.value==authsubfield){ subfield.value = "[% authid |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') | html %]"; break; } --- a/misc/maintenance/batchAuthorityLinking.pl +++ a/misc/maintenance/batchAuthorityLinking.pl @@ -0,0 +1,210 @@ +#!/usr/bin/perl + +#----------------------------------- +# Copyright 2019 Koha-Suomi Oy +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +#----------------------------------- + +use Modern::Perl; +use Getopt::Long; + +use C4::Context; +use C4::Biblio; +use C4::Record; +use MARC::Field; + +my ($help, $confirm, $verbose); +my $schema = 'MARC21'; +my $chunks = 500; + +GetOptions( + 'h|help' => \$help, + 'v|verbose:i' => \$verbose, + 'c|confirm' => \$confirm, + 's|schema:s' => \$schema, + 'chunks:i' => \$chunks, +); + +my $usage = << 'ENDUSAGE'; + +Changes authority linking subfield from $9 to $0 + + -h --help This nice help! + + -v --verbose More chatty output. + + -c --confirm Confirm that you want to mangle your bibliographic records + + -s --schema Select MARC schema, MARC21 or NORMARC. Default is MARC21 + + --chunks Increase processed chunks + + +EXAMPLE: + +perl batchAuthorityLinking.pl -v -c +perl batchAuthorityLinking.pl -v -c -f NORMARC +perl batchAuthorityLinking.pl -v --chunks 1000 + +ENDUSAGE + +if ($help) { + print $usage; + exit 0; +} + +our $marc21Authorityfields = { + '100' => 1, + '110' => 1, + '111' => 1, + '130' => 1, + '245' => 1, + '400' => 1, + '410' => 1, + '440' => 1, + '490' => 1, + '600' => 1, + '610' => 1, + '611' => 1, + '630' => 1, + '648' => 1, + '650' => 1, + '651' => 1, + '652' => 1, + '653' => 1, + '654' => 1, + '655' => 1, + '656' => 1, + '657' => 1, + '662' => 1, + '690' => 1, + '691' => 1, + '696' => 1, + '697' => 1, + '698' => 1, + '699' => 1, + '700' => 1, + '710' => 1, + '711' => 1, + '730' => 1, + '751' => 1, + '796' => 1, + '797' => 1, + '798' => 1, + '799' => 1, + '800' => 1, + '810' => 1, + '811' => 1, + '830' => 1, + '896' => 1, + '897' => 1, + '898' => 1, + '899' => 1 + }; + +our $normarcAuthorityfields = { + '100' => 1, + '110' => 1, + '111' => 1, + '130' => 1, + '245' => 1, + '440' => 1, + '490' => 1, + '600' => 1, + '610' => 1, + '611' => 1, + '630' => 1, + '650' => 1, + '651' => 1, + '652' => 1, + '653' => 1, + '654' => 1, + '655' => 1, + '656' => 1, + '657' => 1, + '690' => 1, + '700' => 1, + '710' => 1, + '711' => 1, + '730' => 1, + '800' => 1, + '810' => 1, + '811' => 1, + '830' => 1 +}; + +my $params = { + chunks => $chunks, + page => 1 +}; + + +my $pageCount = 1; +my $authorityfields = $schema eq 'NORMARC' ? $normarcAuthorityfields : $marc21Authorityfields; + +while ($pageCount >= $params->{page}) { + my $biblios = biblios($params); + my $count = 0; + my $lastnumber = 0; + foreach my $biblio (@{$biblios}) { + my $record = C4::Record::marcxml2marc($biblio->{metadata}); + foreach my $field ($record->fields) { + my @subfield_data; + if ($authorityfields->{$field->tag}) { + if ($field->subfields) { + for my $subfield ($field->subfields) { + if ($subfield->[0] eq "9") { + $subfield->[0] = "0"; + print "Change $schema 9 field to 0 from ".$biblio->{biblionumber}."\n" if (defined $verbose); + } + push @subfield_data, $subfield->[0], $subfield->[1]; + } + } + } + $field->replace_with(MARC::Field->new( + $field->tag(), $field->indicator(1), $field->indicator(2), + @subfield_data) + ) if @subfield_data; + } + my $frameworkcode = C4::Biblio::GetFrameworkCode( $biblio->{biblionumber} ); + C4::Biblio::ModBiblio($record, $biblio->{biblionumber}, $frameworkcode) if $confirm; + $count++; + $lastnumber = $biblio->{biblionumber}; + } + print "last processed biblio $lastnumber\n"; + print "$count biblios processed!\n"; + if ($count eq $params->{chunks}) { + $pageCount++; + $params->{page} = $pageCount; + } else { + $pageCount = 0; + } +} + +sub biblios { + my ($params) = @_; + print "Starting to change offset $params->{page}!\n"; + my $biblios = Koha::Biblio::Metadatas->search({format => 'marcxml', schema => $schema}, + { + page => $params->{page}, + rows => $params->{chunks} + } + )->unblessed; + + return $biblios; + +} --- a/t/db_dependent/Koha/Authorities.t +++ a/t/db_dependent/Koha/Authorities.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 7; +use Test::More tests => 8; use MARC::Field; use MARC::File::XML; use MARC::Record; @@ -129,7 +129,7 @@ subtest 'Testing reporting_tag_xml in MergeRequest' => sub { ); }; -subtest 'Trivial tests for get_usage_count and linked_biblionumbers' => sub { +subtest 'Trivial tests for get_usage_count and linked_biblionumbers with UNIMARC' => sub { plan tests => 5; # NOTE: We are not testing $searcher->simple_search_compat here. Suppose @@ -137,6 +137,48 @@ subtest 'Trivial tests for get_usage_count and linked_biblionumbers' => sub { # So we're just testing the 'wrapper' here. my ( $mods, $koha_fields ); + t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' ); + t::lib::Mocks::mock_preference('SearchEngine', 'Zebra'); + $mods->{zebra} = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' ); + $mods->{elastic} = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch::Search' ); + $mods->{biblio} = Test::MockModule->new( 'C4::Biblio' ); + $mods->{zebra}->mock( 'simple_search_compat', \&simple_search_compat ); + $mods->{elastic}->mock( 'simple_search_compat', \&simple_search_compat ); + $mods->{biblio}->mock( 'GetMarcFromKohaField', sub { return @$koha_fields; }); + + my $auth1 = $builder->build({ source => 'AuthHeader' }); + $auth1 = Koha::Authorities->find( $auth1->{authid} ); + + # Test error condition + my $count; + $search_compat_pars = [ 0, 'some_error' ]; + warning_like { $count = $auth1->get_usage_count } + qr/some_error/, 'Catch warn of simple_search_compat'; + is( $count, undef, 'Undef returned when error encountered' ); + + # Simple test with some results; one result discarded in the 2nd test + $search_compat_pars = [ 1 ]; + $koha_fields = [ '001', '' ]; + is( $auth1->get_usage_count, 3, 'Three results expected (Zebra)' ); + cmp_deeply( [ $auth1->linked_biblionumbers ], [ 1001, 3003 ], + 'linked_biblionumbers should ignore record without biblionumber' ); + + # And a simple test with Elastic + t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch'); + cmp_deeply( [ $auth1->linked_biblionumbers ], [ 2001 ], + 'linked_biblionumbers with Elasticsearch' ); + t::lib::Mocks::mock_preference('SearchEngine', 'Zebra'); +}; + +subtest 'Trivial tests for get_usage_count and linked_biblionumbers with MARC21' => sub { + plan tests => 5; + + # NOTE: We are not testing $searcher->simple_search_compat here. Suppose + # that should be done in t/db../Koha/SearchEngine? + # So we're just testing the 'wrapper' here. + + my ( $mods, $koha_fields ); + t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); t::lib::Mocks::mock_preference('SearchEngine', 'Zebra'); $mods->{zebra} = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' ); $mods->{elastic} = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch::Search' ); @@ -200,23 +242,25 @@ unimarc,*,ind1:auth2,ind2:auth1|); }; sub simple_search_compat { + my $authsubfield = Koha::Authorities->authority_linking_subfield; if( $search_compat_pars->[0] == 0 ) { return ( $search_compat_pars->[1], [], 0 ); } elsif( $search_compat_pars->[0] == 1 ) { my $records = C4::Context->preference('SearchEngine') eq 'Zebra' - ? few_marcxml_records() + ? few_marcxml_records($authsubfield) : few_marc_records(); return ( undef, $records, scalar @$records ); } } sub few_marcxml_records { + my ($authsubfield) = @_; return [ q| 1001 - 102 + 102 My Corporation |, @@ -224,7 +268,7 @@ q| - 112 + 112 Another Corporation |, @@ -232,7 +276,7 @@ q| 3003 - 102 + 102 My Corporation | --