1 package C4
::AuthoritiesMarc
;
2 # Copyright 2000-2002 Katipo Communications
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with Koha; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 use C4
::AuthoritiesMarc
::MARC21
;
26 use C4
::AuthoritiesMarc
::UNIMARC
;
31 use vars
qw($VERSION @ISA @EXPORT);
34 # set the version for version checking
35 $VERSION = 3.07.00.049;
43 &GetAuthMARCFromKohaField
61 &FindDuplicateAuthority
73 =head2 GetAuthMARCFromKohaField
75 ( $tag, $subfield ) = &GetAuthMARCFromKohaField ($kohafield,$authtypecode);
77 returns tag and subfield linked to kohafield
80 Suppose Kohafield is only linked to ONE subfield
84 sub GetAuthMARCFromKohaField
{
85 #AUTHfind_marc_from_kohafield
86 my ( $kohafield,$authtypecode ) = @_;
87 my $dbh=C4
::Context
->dbh;
88 return 0, 0 unless $kohafield;
89 $authtypecode="" unless $authtypecode;
90 my $marcfromkohafield;
91 my $sth = $dbh->prepare("select tagfield,tagsubfield from auth_subfield_structure where kohafield= ? and authtypecode=? ");
92 $sth->execute($kohafield,$authtypecode);
93 my ($tagfield,$tagsubfield) = $sth->fetchrow;
95 return ($tagfield,$tagsubfield);
98 =head2 SearchAuthorities
100 (\@finalresult, $nbresults)= &SearchAuthorities($tags, $and_or,
101 $excluding, $operator, $value, $offset,$length,$authtypecode,
102 $sortby[, $skipmetadata])
104 returns ref to array result and count of results returned
108 sub SearchAuthorities
{
109 my ($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby,$skipmetadata) = @_;
110 # warn Dumper($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby);
111 my $dbh=C4
::Context
->dbh;
115 $QParser = C4
::Context
->queryparser if (C4
::Context
->preference('UseQueryParser'));
117 # the marclist may contain "mainentry". In this case, search the tag_to_report, that depends on
118 # the authtypecode. Then, search on $a of this tag_to_report
119 # also store main entry MARC tag, to extract it at end of search
121 ##first set the authtype search and may be multiple authorities
125 my @auths=split / /,$authtypecode ;
126 foreach my $auth (@auths){
127 $query .=" \@attr 1=authtype \@attr 5=100 ".$auth; ##No truncation on authtype
128 push @authtypecode ,$auth;
132 while ($n>1){$query= "\@or ".$query;$n--;}
135 $qpquery .= '(authtype:' . join('|| authtype:', @auths) . ')';
143 for(my $i = 0 ; $i <= $#{$value} ; $i++)
146 if ( @
$tags[$i] eq "mainmainentry" ) {
147 $attr = " \@attr 1=Heading-Main ";
149 elsif ( @
$tags[$i] eq "mainentry" ) {
150 $attr = " \@attr 1=Heading ";
152 elsif ( @
$tags[$i] eq "match" ) {
153 $attr = " \@attr 1=Match ";
155 elsif ( @
$tags[$i] eq "match-heading" ) {
156 $attr = " \@attr 1=Match-heading ";
158 elsif ( @
$tags[$i] eq "see-from" ) {
159 $attr = " \@attr 1=Match-heading-see-from ";
161 elsif ( @
$tags[$i] eq "thesaurus" ) {
162 $attr = " \@attr 1=Subject-heading-thesaurus ";
164 else { # Assume any if no index was specified
165 $attr = " \@attr 1=Any ";
167 if ( @
$operator[$i] eq 'is' ) {
168 $attr .= " \@attr 4=1 \@attr 5=100 "
169 ; ##Phrase, No truncation,all of subfield field must match
171 elsif ( @
$operator[$i] eq "=" ) {
172 $attr .= " \@attr 4=107 "; #Number Exact match
174 elsif ( @
$operator[$i] eq "start" ) {
175 $attr .= " \@attr 3=2 \@attr 4=1 \@attr 5=1 "
176 ; #Firstinfield Phrase, Right truncated
178 elsif ( @
$operator[$i] eq "exact" ) {
179 $attr .= " \@attr 4=1 \@attr 5=100 \@attr 6=3 "
180 ; ##Phrase, No truncation,all of subfield field must match
183 $attr .= " \@attr 5=1 \@attr 4=6 "
184 ; ## Word list, right truncated, anywhere
185 if ($sortby eq 'Relevance') {
186 $attr .= "\@attr 2=102 ";
189 @
$value[$i] =~ s/"/\\"/g; # Escape the double-quotes in the search value
190 $attr =$attr."\"".@
$value[$i]."\"";
195 $qpquery .= " $tags->[$i]:\"$value->[$i]\"";
199 ##Add how many queries generated
200 if (defined $query && $query=~/\S+/){
201 $query= $and x
$attr_cnt . $query . (defined $q2 ?
$q2 : '');
206 #$query=' @or @attr 7=2 @attr 1=Heading 0 @or @attr 7=1 @attr 1=Heading 1'.$query if ($sortby eq "HeadingDsc");
208 if ($sortby eq 'HeadingAsc') {
209 $orderstring = '@attr 7=1 @attr 1=Heading 0';
210 } elsif ($sortby eq 'HeadingDsc') {
211 $orderstring = '@attr 7=2 @attr 1=Heading 0';
212 } elsif ($sortby eq 'AuthidAsc') {
213 $orderstring = '@attr 7=1 @attr 4=109 @attr 1=Local-Number 0';
214 } elsif ($sortby eq 'AuthidDsc') {
215 $orderstring = '@attr 7=2 @attr 4=109 @attr 1=Local-Number 0';
218 $qpquery .= ' all:all' unless $value->[0];
220 if ( $value->[0] =~ m/^qp=(.*)$/ ) {
224 $qpquery .= " #$sortby" unless $sortby eq '';
226 $QParser->parse( $qpquery );
227 $query = $QParser->target_syntax('authorityserver');
229 $query=($query?
$query:"\@attr 1=_ALLRECORDS \@attr 2=103 ''");
230 $query="\@or $orderstring $query" if $orderstring;
233 $offset=0 unless $offset;
234 my $counter = $offset;
235 $length=10 unless $length;
238 $oAuth[0]=C4
::Context
->Zconn("authorityserver" , 1);
239 my $Anewq= new ZOOM
::Query
::PQF
($query,$oAuth[0]);
241 $oAResult= $oAuth[0]->search($Anewq) ;
242 while (($i = ZOOM
::event
(\
@oAuth)) != 0) {
243 my $ev = $oAuth[$i-1]->last_event();
244 last if $ev == ZOOM
::Event
::ZEND
;
246 my($error, $errmsg, $addinfo, $diagset) = $oAuth[0]->error_x();
248 warn "oAuth error: $errmsg ($error) $addinfo $diagset\n";
253 $nbresults=$oAResult->size();
254 my $nremains=$nbresults;
256 my @finalresult = ();
260 ##Find authid and linkid fields
261 ##we may be searching multiple authoritytypes.
262 ## FIXME this assumes that all authid and linkid fields are the same for all authority types
263 # my ($authidfield,$authidsubfield)=GetAuthMARCFromKohaField($dbh,"auth_header.authid",$authtypecode[0]);
264 # my ($linkidfield,$linkidsubfield)=GetAuthMARCFromKohaField($dbh,"auth_header.linkid",$authtypecode[0]);
265 while (($counter < $nbresults) && ($counter < ($offset + $length))) {
267 ##Here we have to extract MARC record and $authid from ZEBRA AUTHORITIES
268 my $rec=$oAResult->record($counter);
269 my $separator=C4
::Context
->preference('authoritysep');
270 my $authrecord = C4
::Search
::new_record_from_zebra
(
275 if ( !defined $authrecord or !defined $authrecord->field('001') ) {
280 my $authid=$authrecord->field('001')->data();
282 $newline{authid
} = $authid;
283 if ( !$skipmetadata ) {
285 BuildSummary
( $authrecord, $authid, GetAuthTypeCode
($authid) );
287 "SELECT auth_tag_to_report FROM auth_types WHERE authtypecode=?";
288 my $sth = $dbh->prepare($query_auth_tag);
289 $sth->execute($authtypecode);
290 my $auth_tag_to_report = $sth->fetchrow;
292 my $mainentry = $authrecord->field($auth_tag_to_report);
295 foreach ( $mainentry->subfields() ) {
296 $reported_tag .= '$' . $_->[0] . $_->[1];
299 my $thisauthtype = GetAuthType
(GetAuthTypeCode
($authid));
300 unless (defined $thisauthtype) {
301 $thisauthtype = GetAuthType
($authtypecode) if $authtypecode;
303 $newline{authtype
} = defined($thisauthtype) ?
304 $thisauthtype->{'authtypetext'} : '';
305 $newline{summary
} = $summary;
306 $newline{even
} = $counter % 2;
307 $newline{reported_tag
} = $reported_tag;
310 push @finalresult, \
%newline;
313 if (! $skipmetadata) {
314 for (my $z=0; $z<@finalresult; $z++){
315 my $count=CountUsage
($finalresult[$z]{authid
});
316 $finalresult[$z]{used
}=$count;
322 $oAResult->destroy();
323 # $oAuth[0]->destroy();
325 return (\
@finalresult, $nbresults);
330 $count= &CountUsage($authid)
332 counts Usage of Authid in bibliorecords.
340 $query= "an:".$authid;
341 my ($err,$res,$result) = C4
::Search
::SimpleSearch
($query,0,10);
343 warn "Error: $err from search $query";
350 =head2 CountUsageChildren
352 $count= &CountUsageChildren($authid)
354 counts Usage of narrower terms of Authid in bibliorecords.
358 sub CountUsageChildren
{
362 =head2 GetAuthTypeCode
364 $authtypecode= &GetAuthTypeCode($authid)
366 returns authtypecode of an authid
370 sub GetAuthTypeCode
{
371 #AUTHfind_authtypecode
373 my $dbh=C4
::Context
->dbh;
374 my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?");
375 $sth->execute($authid);
376 my $authtypecode = $sth->fetchrow;
377 return $authtypecode;
380 =head2 GuessAuthTypeCode
382 my $authtypecode = GuessAuthTypeCode($record);
384 Get the record and tries to guess the adequate authtypecode from its content.
388 sub GuessAuthTypeCode
{
389 my ($record, $heading_fields) = @_;
390 return unless defined $record;
391 $heading_fields //= {
393 '100'=>{authtypecode
=>'PERSO_NAME'},
394 '110'=>{authtypecode
=>'CORPO_NAME'},
395 '111'=>{authtypecode
=>'MEETI_NAME'},
396 '130'=>{authtypecode
=>'UNIF_TITLE'},
397 '148'=>{authtypecode
=>'CHRON_TERM'},
398 '150'=>{authtypecode
=>'TOPIC_TERM'},
399 '151'=>{authtypecode
=>'GEOGR_NAME'},
400 '155'=>{authtypecode
=>'GENRE/FORM'},
401 '180'=>{authtypecode
=>'GEN_SUBDIV'},
402 '181'=>{authtypecode
=>'GEO_SUBDIV'},
403 '182'=>{authtypecode
=>'CHRON_SUBD'},
404 '185'=>{authtypecode
=>'FORM_SUBD'},
406 #200 Personal name 700, 701, 702 4-- with embedded 700, 701, 702 600
407 # 604 with embedded 700, 701, 702
408 #210 Corporate or meeting name 710, 711, 712 4-- with embedded 710, 711, 712 601 604 with embedded 710, 711, 712
409 #215 Territorial or geographic name 710, 711, 712 4-- with embedded 710, 711, 712 601, 607 604 with embedded 710, 711, 712
410 #216 Trademark 716 [Reserved for future use]
411 #220 Family name 720, 721, 722 4-- with embedded 720, 721, 722 602 604 with embedded 720, 721, 722
412 #230 Title 500 4-- with embedded 500 605
413 #240 Name and title (embedded 200, 210, 215, or 220 and 230) 4-- with embedded 7-- and 500 7-- 604 with embedded 7-- and 500 500
414 #245 Name and collective title (embedded 200, 210, 215, or 220 and 235) 4-- with embedded 7-- and 501 604 with embedded 7-- and 501 7-- 501
415 #250 Topical subject 606
416 #260 Place access 620
417 #280 Form, genre or physical characteristics 608
420 # Could also be represented with :
422 #a = personal name entry
423 #b = corporate name entry
424 #c = territorial or geographical name
428 #g = collective uniform title
430 #i = name/collective uniform title
433 #l = form, genre or physical characteristics
435 '200'=>{authtypecode
=>'NP'},
436 '210'=>{authtypecode
=>'CO'},
437 '215'=>{authtypecode
=>'SNG'},
438 '216'=>{authtypecode
=>'TM'},
439 '220'=>{authtypecode
=>'FAM'},
440 '230'=>{authtypecode
=>'TU'},
441 '235'=>{authtypecode
=>'CO_UNI_TI'},
442 '240'=>{authtypecode
=>'SAUTTIT'},
443 '245'=>{authtypecode
=>'NAME_COL'},
444 '250'=>{authtypecode
=>'SNC'},
445 '260'=>{authtypecode
=>'PA'},
446 '280'=>{authtypecode
=>'GENRE/FORM'},
449 foreach my $field (keys %{$heading_fields->{uc(C4
::Context
->preference('marcflavour'))} }) {
450 return $heading_fields->{uc(C4
::Context
->preference('marcflavour'))}->{$field}->{'authtypecode'} if (defined $record->field($field));
457 my $authtid = GuessAuthId($record);
459 Get the record and tries to guess the adequate authtypecode from its content.
465 return unless ($record && $record->field('001'));
466 # my $authtypecode=GuessAuthTypeCode($record);
467 # my ($tag,$subfield)=GetAuthMARCFromKohaField("auth_header.authid",$authtypecode);
468 # if ($tag > 010) {return $record->subfield($tag,$subfield)}
469 # else {return $record->field($tag)->data}
470 return $record->field('001')->data;
475 $tagslabel= &GetTagsLabels($forlibrarian,$authtypecode)
477 returns a ref to hashref of authorities tag and subfield structure.
481 $tagslabel->{$tag}->{$subfield}->{'attribute'}
483 where attribute takes values in :
501 my ($forlibrarian,$authtypecode)= @_;
502 my $dbh=C4
::Context
->dbh;
503 $authtypecode="" unless $authtypecode;
505 my $libfield = ($forlibrarian == 1)?
'liblibrarian' : 'libopac';
508 # check that authority exists
509 $sth=$dbh->prepare("SELECT count(*) FROM auth_tag_structure WHERE authtypecode=?");
510 $sth->execute($authtypecode);
511 my ($total) = $sth->fetchrow;
512 $authtypecode="" unless ($total >0);
514 "SELECT auth_tag_structure.tagfield,auth_tag_structure.liblibrarian,auth_tag_structure.libopac,auth_tag_structure.mandatory,auth_tag_structure.repeatable
515 FROM auth_tag_structure
520 $sth->execute($authtypecode);
521 my ( $liblibrarian, $libopac, $tag, $res, $tab, $mandatory, $repeatable );
523 while ( ( $tag, $liblibrarian, $libopac, $mandatory, $repeatable ) = $sth->fetchrow ) {
524 $res->{$tag}->{lib
} = ($forlibrarian or !$libopac)?
$liblibrarian:$libopac;
525 $res->{$tag}->{tab
} = " "; # XXX
526 $res->{$tag}->{mandatory
} = $mandatory;
527 $res->{$tag}->{repeatable
} = $repeatable;
530 "SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,frameworkcode as authtypecode,value_builder,kohafield,seealso,hidden,isurl,defaultvalue
531 FROM auth_subfield_structure
533 ORDER BY tagfield,tagsubfield"
535 $sth->execute($authtypecode);
538 my $authorised_value;
548 ( $tag, $subfield, $liblibrarian, , $libopac, $tab,
549 $mandatory, $repeatable, $authorised_value, $authtypecode,
550 $value_builder, $kohafield, $seealso, $hidden,
551 $isurl, $defaultvalue, $link )
555 $res->{$tag}->{$subfield}->{lib
} = ($forlibrarian or !$libopac)?
$liblibrarian:$libopac;
556 $res->{$tag}->{$subfield}->{tab
} = $tab;
557 $res->{$tag}->{$subfield}->{mandatory
} = $mandatory;
558 $res->{$tag}->{$subfield}->{repeatable
} = $repeatable;
559 $res->{$tag}->{$subfield}->{authorised_value
} = $authorised_value;
560 $res->{$tag}->{$subfield}->{authtypecode
} = $authtypecode;
561 $res->{$tag}->{$subfield}->{value_builder
} = $value_builder;
562 $res->{$tag}->{$subfield}->{kohafield
} = $kohafield;
563 $res->{$tag}->{$subfield}->{seealso
} = $seealso;
564 $res->{$tag}->{$subfield}->{hidden
} = $hidden;
565 $res->{$tag}->{$subfield}->{isurl
} = $isurl;
566 $res->{$tag}->{$subfield}->{link} = $link;
567 $res->{$tag}->{$subfield}->{defaultvalue
} = $defaultvalue;
574 $authid= &AddAuthority($record, $authid,$authtypecode)
576 Either Create Or Modify existing authority.
577 returns authid of the newly created authority
582 # pass the MARC::Record to this function, and it will create the records in the authority table
583 my ($record,$authid,$authtypecode) = @_;
584 my $dbh=C4
::Context
->dbh;
585 my $leader=' nz a22 o 4500';#Leader for incomplete MARC21 record
587 # if authid empty => true add, find a new authid number
589 if (uc(C4
::Context
->preference('marcflavour')) eq 'UNIMARC') {
590 $format= 'UNIMARCAUTH';
596 #update date/time to 005 for marc and unimarc
597 my $time=POSIX
::strftime
("%Y%m%d%H%M%S",localtime);
598 my $f5=$record->field('005');
600 $record->insert_fields_ordered( MARC
::Field
->new('005',$time.".0") );
603 $f5->update($time.".0");
606 SetUTF8Flag
($record);
607 if ($format eq "MARC21") {
608 if (!$record->leader) {
609 $record->leader($leader);
611 if (!$record->field('003')) {
612 $record->insert_fields_ordered(
613 MARC
::Field
->new('003',C4
::Context
->preference('MARCOrgCode'))
616 my $date=POSIX
::strftime
("%y%m%d",localtime);
617 if (!$record->field('008')) {
618 # Get a valid default value for field 008
619 my $default_008 = C4
::Context
->preference('MARCAuthorityControlField008');
620 if(!$default_008 or length($default_008)<34) {
621 $default_008 = '|| aca||aabn | a|a d';
624 $default_008 = substr($default_008,0,34);
627 $record->insert_fields_ordered( MARC
::Field
->new('008',$date.$default_008) );
629 if (!$record->field('040')) {
630 $record->insert_fields_ordered(
631 MARC
::Field
->new('040','','',
632 'a' => C4
::Context
->preference('MARCOrgCode'),
633 'c' => C4
::Context
->preference('MARCOrgCode')
639 if ($format eq "UNIMARCAUTH") {
640 $record->leader(" nx j22 ") unless ($record->leader());
641 my $date=POSIX
::strftime
("%Y%m%d",localtime);
642 my $defaultfield100 = C4
::Context
->preference('UNIMARCAuthorityField100');
643 if (my $string=$record->subfield('100',"a")){
644 $string=~s/fre50/frey50/;
645 $record->field('100')->update('a'=>$string);
647 elsif ($record->field('100')){
648 $record->field('100')->update('a'=>$date.$defaultfield100);
650 $record->append_fields(
651 MARC
::Field
->new('100',' ',' '
652 ,'a'=>$date.$defaultfield100)
656 my ($auth_type_tag, $auth_type_subfield) = get_auth_type_location
($authtypecode);
657 if (!$authid and $format eq "MARC21") {
658 # only need to do this fix when modifying an existing authority
659 C4
::AuthoritiesMarc
::MARC21
::fix_marc21_auth_type_location
($record, $auth_type_tag, $auth_type_subfield);
661 if (my $field=$record->field($auth_type_tag)){
662 $field->update($auth_type_subfield=>$authtypecode);
665 $record->add_fields($auth_type_tag,'','', $auth_type_subfield=>$authtypecode);
671 my $sth=$dbh->prepare("select max(authid) from auth_header");
673 ($authid)=$sth->fetchrow;
675 ##Insert the recordID in MARC record
676 unless ($record->field('001') && $record->field('001')->data() eq $authid){
677 $record->delete_field($record->field('001'));
678 $record->insert_fields_ordered(MARC
::Field
->new('001',$authid));
681 $auth_exists=$dbh->do(qq(select authid from auth_header where authid
=?
),undef,$authid);
682 # warn "auth_exists = $auth_exists";
685 $oldRecord=GetAuthority
($authid);
686 $record->add_fields('001',$authid) unless ($record->field('001'));
687 # warn "\n\n\n enregistrement".$record->as_formatted;
688 my $sth=$dbh->prepare("update auth_header set authtypecode=?,marc=?,marcxml=? where authid=?");
689 $sth->execute($authtypecode,$record->as_usmarc,$record->as_xml_record($format),$authid) or die $sth->errstr;
693 my $sth=$dbh->prepare("insert into auth_header (authid,datecreated,authtypecode,marc,marcxml) values (?,now(),?,?,?)");
694 $sth->execute($authid,$authtypecode,$record->as_usmarc,$record->as_xml_record($format));
696 logaction
( "AUTHORITIES", "ADD", $authid, "authority" ) if C4
::Context
->preference("AuthoritiesLog");
698 ModZebra
($authid,'specialUpdate',"authorityserver",$oldRecord,$record);
705 $authid= &DelAuthority($authid)
713 my $dbh=C4
::Context
->dbh;
715 logaction
( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4
::Context
->preference("AuthoritiesLog");
716 ModZebra
($authid,"recordDelete","authorityserver",GetAuthority
($authid),undef);
717 my $sth = $dbh->prepare("DELETE FROM auth_header WHERE authid=?");
718 $sth->execute($authid);
723 $authid= &ModAuthority($authid,$record,$authtypecode)
725 Modifies authority record, optionally updates attached biblios.
730 my ($authid,$record,$authtypecode)=@_; # deprecated $merge parameter removed
732 my $dbh=C4
::Context
->dbh;
733 #Now rewrite the $record to table with an add
734 my $oldrecord=GetAuthority
($authid);
735 $authid=AddAuthority
($record,$authid,$authtypecode);
737 # If a library thinks that updating all biblios is a long process and wishes
738 # to leave that to a cron job, use misc/migration_tools/merge_authority.pl.
739 # In that case set system preference "dontmerge" to 1. Otherwise biblios will
741 unless(C4
::Context
->preference('dontmerge') eq '1'){
742 &merge
($authid,$oldrecord,$authid,$record);
744 # save a record in need_merge_authorities table
745 my $sqlinsert="INSERT INTO need_merge_authorities (authid, done) ".
747 $dbh->do($sqlinsert,undef,($authid,0));
749 logaction
( "AUTHORITIES", "MODIFY", $authid, "authority BEFORE=>" . $oldrecord->as_formatted ) if C4
::Context
->preference("AuthoritiesLog");
753 =head2 GetAuthorityXML
755 $marcxml= &GetAuthorityXML( $authid)
757 returns xml form of record $authid
761 sub GetAuthorityXML
{
762 # Returns MARC::XML of the authority passed in parameter.
764 if (uc(C4
::Context
->preference('marcflavour')) eq 'UNIMARC') {
765 my $dbh=C4
::Context
->dbh;
766 my $sth = $dbh->prepare("select marcxml from auth_header where authid=? " );
767 $sth->execute($authid);
768 my ($marcxml)=$sth->fetchrow;
772 # for MARC21, call GetAuthority instead of
773 # getting the XML directly since we may
774 # need to fix up the location of the authority
775 # code -- note that this is reasonably safe
776 # because GetAuthorityXML is used only by the
777 # indexing processes like zebraqueue_start.pl
778 my $record = GetAuthority
($authid);
779 return $record->as_xml_record('MARC21');
785 $record= &GetAuthority( $authid)
787 Returns MARC::Record of the authority passed in parameter.
793 my $authority = Koha
::Authority
->get_from_authid($authid);
794 return unless $authority;
795 return ($authority->record);
800 $result = &GetAuthType($authtypecode)
802 If the authority type specified by C<$authtypecode> exists,
803 returns a hashref of the type's fields. If the type
804 does not exist, returns undef.
809 my ($authtypecode) = @_;
810 my $dbh=C4
::Context
->dbh;
812 if (defined $authtypecode){ # NOTE - in MARC21 framework, '' is a valid authority
813 # type (FIXME but why?)
814 $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
815 $sth->execute($authtypecode);
816 if (my $res = $sth->fetchrow_hashref) {
824 =head2 FindDuplicateAuthority
826 $record= &FindDuplicateAuthority( $record, $authtypecode)
828 return $authid,Summary if duplicate is found.
830 Comments : an improvement would be to return All the records that match.
834 sub FindDuplicateAuthority
{
836 my ($record,$authtypecode)=@_;
837 # warn "IN for ".$record->as_formatted;
838 my $dbh = C4
::Context
->dbh;
839 # warn "".$record->as_formatted;
840 my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
841 $sth->execute($authtypecode);
842 my ($auth_tag_to_report) = $sth->fetchrow;
844 # warn "record :".$record->as_formatted." auth_tag_to_report :$auth_tag_to_report";
845 # build a request for SearchAuthorities
847 $QParser = C4
::Context
->queryparser if (C4
::Context
->preference('UseQueryParser'));
854 my $query='at:'.$authtypecode.' ';
855 my $filtervalues=qr
([\001-\040\
!\'\"\
`\#\$\%\&\*\+,\-\./:;<=>\?\@\(\)\{\[\]\}_\|\~]);
856 if ($record->field($auth_tag_to_report)) {
857 foreach ($record->field($auth_tag_to_report)->subfields()) {
858 $_->[1]=~s/$filtervalues/ /g; $query.= " $op he:\"".$_->[1]."\"" if ($_->[0]=~/[A-z]/);
861 my ($error, $results, $total_hits) = C4::Search::SimpleSearch( $query, 0, 1, [ "authorityserver" ] );
862 # there is at least 1 result => return the 1st one
863 if (!defined $error && @{$results} ) {
864 my $marcrecord = C4::Search::new_record_from_zebra(
868 return $marcrecord->field('001')->data,BuildSummary($marcrecord,$marcrecord->field('001')->data,$authtypecode);
870 # no result, returns nothing
876 $summary= &BuildSummary( $record, $authid, $authtypecode)
878 Returns a hashref with a summary of the specified record.
880 Comment : authtypecode can be infered from both record and authid.
881 Moreover, authid can also be inferred from $record.
882 Would it be interesting to delete those things.
887 ## give this a Marc record to return summary
888 my ($record,$authid,$authtypecode)=@_;
889 my $dbh=C4::Context->dbh;
891 # handle $authtypecode is NULL or eq ""
893 my $authref = GetAuthType($authtypecode);
894 $summary{authtypecode} = $authref->{authtypecode};
895 $summary{type} = $authref->{authtypetext};
896 $summary{summary} = $authref->{summary};
898 my $marc21subfields = 'abcdfghjklmnopqrstuvxyz68';
899 my %marc21controlrefs = ( 'a' => 'earlier',
905 'n' => 'notapplicable',
909 my %unimarc_relation_from_code = (
915 $thesaurus{'1'}="Peuples";
916 $thesaurus{'2'}="Anthroponymes";
917 $thesaurus{'3'}="Oeuvres";
918 $thesaurus{'4'}="Chronologie";
919 $thesaurus{'5'}="Lieux";
920 $thesaurus{'6'}="Sujets";
923 # if the library has a summary defined, use it. Otherwise, build a standard one
924 # FIXME - it appears that the summary field in the authority frameworks
925 # can work as a display template. However, this doesn't
926 # suit the MARC21 version, so for now the "templating"
927 # feature will be enabled only for UNIMARC for backwards
929 if ($summary{summary} and C4::Context->preference('marcflavour') eq 'UNIMARC') {
930 my @fields = $record->fields();
931 # $reported_tag = '$9'.$result[$counter];
933 foreach my $field (@fields) {
934 my $tag = $field->tag();
935 my $tagvalue = $field->as_string();
936 my $localsummary= $summary{summary};
937 $localsummary =~ s/\[(.?.?.?.?)$tag\*(.*?)\]/$1$tagvalue$2\[$1$tag$2\]/g;
940 $reported_tag.='$3'.$field->data();
943 my @subf = $field->subfields;
944 for my $i (0..$#subf) {
945 my $subfieldcode = $subf[$i][0];
946 my $subfieldvalue = $subf[$i][1];
947 my $tagsubf = $tag.$subfieldcode;
948 $localsummary =~ s/\[(.?.?.?.?)$tagsubf(.*?)\]/$1$subfieldvalue$2\[$1$tagsubf$2\]/g;
951 push @stringssummary, $localsummary if ($localsummary ne $summary{summary});
954 $resultstring = join(" -- ",@stringssummary);
955 $resultstring =~ s/\[(.*?)\]//g;
956 $resultstring =~ s/\n/<br>/g;
957 $summary{summary} = $resultstring;
964 if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
965 # construct UNIMARC summary, that is quite different from MARC21 one
967 foreach my $field ($record->field('2..')) {
969 heading => $field->as_string('abcdefghijlmnopqrstuvwxyz'),
970 hemain => ( $field->subfield('a') // undef ),
971 field => $field->tag(),
975 foreach my $field ($record->field('3..')) {
976 push @notes, { note => $field->subfield('a'), field => $field->tag() };
978 foreach my $field ($record->field('4..')) {
979 my $thesaurus = $field->subfield('2') ? "thes. : ".$thesaurus{"$field->subfield('2')"}." : " : '';
981 heading => $thesaurus . $field->as_string('abcdefghijlmnopqrstuvwxyz'),
982 hemain => ( $field->subfield('a') // undef ),
984 field => $field->tag(),
990 my $type = $unimarc_relation_from_code{$_->subfield('5') || 'a'};
991 my $heading = $_->as_string('abcdefgjxyz');
996 hemain => ( $_->subfield('a') // undef ),
998 authid => ( $_->subfield('9') // undef ),
1000 } $record->field('5..');
1003 @otherscript = map { {
1004 lang => length ($_->subfield('8')) == 6 ? substr ($_->subfield('8'), 3, 3) : $_->subfield('8') || '',
1005 term => $_->subfield('a') . ($_->subfield('b') ? ', ' . $_->subfield('b') : ''),
1008 } } $record->field('7..');
1011 # construct MARC21 summary
1012 # FIXME - looping over 1XX is questionable
1013 # since MARC21 authority should have only one 1XX
1014 my $subfields_to_report;
1015 foreach my $field ($record->field('1..')) {
1016 my $tag = $field->tag();
1017 next if "152" eq $tag;
1018 # FIXME - 152 is not a good tag to use
1019 # in MARC21 -- purely local tags really ought to be
1021 if ($tag eq '100') {
1022 $subfields_to_report = 'abcdefghjklmnopqrstvxyz';
1023 } elsif ($tag eq '110') {
1024 $subfields_to_report = 'abcdefghklmnoprstvxyz';
1025 } elsif ($tag eq '111') {
1026 $subfields_to_report = 'acdefghklnpqstvxyz';
1027 } elsif ($tag eq '130') {
1028 $subfields_to_report = 'adfghklmnoprstvxyz';
1029 } elsif ($tag eq '148') {
1030 $subfields_to_report = 'abvxyz';
1031 } elsif ($tag eq '150') {
1032 $subfields_to_report = 'abvxyz';
1033 } elsif ($tag eq '151') {
1034 $subfields_to_report = 'avxyz';
1035 } elsif ($tag eq '155') {
1036 $subfields_to_report = 'abvxyz';
1037 } elsif ($tag eq '180') {
1038 $subfields_to_report = 'vxyz';
1039 } elsif ($tag eq '181') {
1040 $subfields_to_report = 'vxyz';
1041 } elsif ($tag eq '182') {
1042 $subfields_to_report = 'vxyz';
1043 } elsif ($tag eq '185') {
1044 $subfields_to_report = 'vxyz';
1046 if ($subfields_to_report) {
1048 heading => $field->as_string($subfields_to_report),
1049 hemain => ( $field->subfield( substr($subfields_to_report, 0, 1) ) // undef ),
1054 heading => $field->as_string(),
1055 hemain => ( $field->subfield( 'a' ) // undef ),
1060 foreach my $field ($record->field('4..')) { #See From
1061 my $type = 'seefrom';
1062 $type = ($marc21controlrefs{substr $field->subfield('w'), 0, 1} || '') if ($field->subfield('w'));
1063 if ($type eq 'notapplicable') {
1064 $type = substr $field->subfield('w'), 2, 1;
1065 $type = 'earlier' if $type && $type ne 'n';
1067 if ($type eq 'subfi') {
1069 heading => $field->as_string($marc21subfields),
1070 hemain => $field->subfield( substr($marc21subfields, 0, 1) ),
1071 type => ($field->subfield('i') || ''),
1072 field => $field->tag(),
1076 heading => $field->as_string($marc21subfields),
1077 hemain => $field->subfield( substr($marc21subfields, 0, 1) ),
1079 field => $field->tag(),
1083 foreach my $field ($record->field('5..')) { #See Also
1084 my $type = 'seealso';
1085 $type = ($marc21controlrefs{substr $field->subfield('w'), 0, 1} || '') if ($field->subfield('w'));
1086 if ($type eq 'notapplicable') {
1087 $type = substr $field->subfield('w'), 2, 1;
1088 $type = 'earlier' if $type && $type ne 'n';
1090 if ($type eq 'subfi') {
1092 heading => $field->as_string($marc21subfields),
1093 hemain => $field->subfield( substr($marc21subfields, 0, 1) ),
1094 type => $field->subfield('i'),
1095 field => $field->tag(),
1096 search => $field->as_string($marc21subfields) || '',
1097 authid => $field->subfield('9') || ''
1101 heading => $field->as_string($marc21subfields),
1102 hemain => $field->subfield( substr($marc21subfields, 0, 1) ),
1104 field => $field->tag(),
1105 search => $field->as_string($marc21subfields) || '',
1106 authid => $field->subfield('9') || ''
1110 foreach my $field ($record->field('6..')) {
1111 push @notes, { note => $field->as_string(), field => $field->tag() };
1113 foreach my $field ($record->field('880')) {
1114 my $linkage = $field->subfield('6');
1115 my $category = substr $linkage, 0, 1;
1116 if ($category eq '1') {
1117 $category = 'preferred';
1118 } elsif ($category eq '4') {
1119 $category = 'seefrom';
1120 } elsif ($category eq '5') {
1121 $category = 'seealso';
1124 if ($field->subfield('w')) {
1125 $type = $marc21controlrefs{substr $field->subfield('w'), '0'};
1129 my $direction = $linkage =~ m#/r$# ? 'rtl' : 'ltr';
1130 push @otherscript, { term => $field->as_string($subfields_to_report), category => $category, type => $type, direction => $direction, linkage => $linkage };
1133 $summary{mainentry} = $authorized[0]->{heading};
1134 $summary{mainmainentry} = $authorized[0]->{hemain};
1135 $summary{authorized} = \@authorized;
1136 $summary{notes} = \@notes;
1137 $summary{seefrom} = \@seefrom;
1138 $summary{seealso} = \@seealso;
1139 $summary{otherscript} = \@otherscript;
1143 =head2 GetAuthorizedHeading
1145 $heading = &GetAuthorizedHeading({ record => $record, authid => $authid })
1147 Takes a MARC::Record object describing an authority record or an authid, and
1148 returns a string representation of the first authorized heading. This routine
1149 should be considered a temporary shim to ease the future migration of authority
1150 data from C4::AuthoritiesMarc to the object-oriented Koha::*::Authority.
1154 sub GetAuthorizedHeading {
1157 unless ($record = $args->{record}) {
1158 return unless $args->{authid};
1159 $record = GetAuthority($args->{authid});
1161 return unless (ref $record eq 'MARC::Record');
1162 if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
1163 # construct UNIMARC summary, that is quite different from MARC21 one
1165 foreach my $field ($record->field('2..')) {
1166 return $field->as_string('abcdefghijlmnopqrstuvwxyz');
1169 foreach my $field ($record->field('1..')) {
1170 my $tag = $field->tag();
1171 next if "152" eq $tag;
1172 # FIXME - 152 is not a good tag to use
1173 # in MARC21 -- purely local tags really ought to be
1175 if ($tag eq '100') {
1176 return $field->as_string('abcdefghjklmnopqrstvxyz68');
1177 } elsif ($tag eq '110') {
1178 return $field->as_string('abcdefghklmnoprstvxyz68');
1179 } elsif ($tag eq '111') {
1180 return $field->as_string('acdefghklnpqstvxyz68');
1181 } elsif ($tag eq '130') {
1182 return $field->as_string('adfghklmnoprstvxyz68');
1183 } elsif ($tag eq '148') {
1184 return $field->as_string('abvxyz68');
1185 } elsif ($tag eq '150') {
1186 return $field->as_string('abvxyz68');
1187 } elsif ($tag eq '151') {
1188 return $field->as_string('avxyz68');
1189 } elsif ($tag eq '155') {
1190 return $field->as_string('abvxyz68');
1191 } elsif ($tag eq '180') {
1192 return $field->as_string('vxyz68');
1193 } elsif ($tag eq '181') {
1194 return $field->as_string('vxyz68');
1195 } elsif ($tag eq '182') {
1196 return $field->as_string('vxyz68');
1197 } elsif ($tag eq '185') {
1198 return $field->as_string('vxyz68');
1200 return $field->as_string();
1207 =head2 BuildAuthHierarchies
1209 $text= &BuildAuthHierarchies( $authid, $force)
1211 return text containing trees for hierarchies
1212 for them to be stored in auth_header
1215 122,1314,2452;1324,2342,3,2452
1219 sub BuildAuthHierarchies{
1220 my $authid = shift @_;
1221 # warn "authid : $authid";
1222 my $force = shift @_ || (C4::Context->preference('marcflavour') eq 'UNIMARC' ? 0 : 1);
1224 my $dbh=C4::Context->dbh;
1226 my $data = GetHeaderAuthority($authid);
1227 if ($data->{'authtrees'} and not $force){
1228 return $data->{'authtrees'};
1229 # } elsif ($data->{'authtrees'}){
1230 # $hierarchies=$data->{'authtrees'};
1232 my $record = GetAuthority($authid);
1234 return unless $record;
1235 foreach my $field ($record->field('5..')){
1238 (C4::Context->preference('marcflavour') eq 'UNIMARC' && $field->subfield('5') && $field->subfield('5') eq 'g') ||
1239 (C4::Context->preference('marcflavour') ne 'UNIMARC' && $field->subfield('w') && substr($field->subfield('w'), 0, 1) eq 'g'));
1241 my $subfauthid=_get_authid_subfield($field) || '';
1242 next if ($subfauthid eq $authid);
1243 my $parentrecord = GetAuthority($subfauthid);
1244 next unless $parentrecord;
1245 my $localresult=$hierarchies;
1247 $trees = BuildAuthHierarchies($subfauthid);
1250 @trees = split(/;/,$trees);
1252 push @trees, $trees;
1257 @globalresult = (@globalresult,@trees);
1260 $hierarchies=join(";",@globalresult);
1262 #Unless there is no ancestor, I am alone.
1263 $hierarchies="$authid" unless ($hierarchies);
1265 AddAuthorityTrees($authid,$hierarchies);
1266 return $hierarchies;
1269 =head2 BuildAuthHierarchy
1271 $ref= &BuildAuthHierarchy( $record, $class,$authid)
1273 return a hashref in order to display hierarchy for record and final Authid $authid
1284 sub BuildAuthHierarchy{
1285 my $record = shift @_;
1286 my $class = shift @_;
1287 my $authid_constructed = shift @_;
1288 return unless ($record && $record->field('001'));
1289 my $authid=$record->field('001')->data();
1291 my $parents=""; my $children="";
1292 my (@loopparents,@loopchildren);
1293 my $marcflavour = C4::Context->preference('marcflavour');
1294 my $relationshipsf = $marcflavour eq 'UNIMARC' ? '5' : 'w';
1295 foreach my $field ($record->field('5..')){
1296 my $subfauthid=_get_authid_subfield($field);
1297 if ($subfauthid && $field->subfield($relationshipsf) && $field->subfield('a')){
1298 my $relationship = substr($field->subfield($relationshipsf), 0, 1);
1299 if ($relationship eq 'h'){
1300 push @loopchildren, { "authid"=>$subfauthid,"value"=>$field->subfield('a')};
1302 elsif ($relationship eq 'g'){
1303 push @loopparents, { "authid"=>$subfauthid,"value"=>$field->subfield('a')};
1305 # brothers could get in there with an else
1308 $cell{"parents"}=\@loopparents;
1309 $cell{"children"}=\@loopchildren;
1310 $cell{"class"}=$class;
1311 $cell{"authid"}=$authid;
1312 $cell{"current_value"} =1 if ($authid eq $authid_constructed);
1313 $cell{"value"}=C4::Context->preference('marcflavour') eq 'UNIMARC' ? $record->subfield('2..',"a") : $record->subfield('1..', 'a');
1317 =head2 BuildAuthHierarchyBranch
1319 $branch = &BuildAuthHierarchyBranch( $tree, $authid[, $cnt])
1321 Return a data structure representing an authority hierarchy
1322 given a list of authorities representing a single branch in
1323 an authority hierarchy tree. $authid is the current node in
1324 the tree (which may or may not be somewhere in the middle).
1325 $cnt represents the level of the upper-most item, and is only
1326 used when BuildAuthHierarchyBranch is called recursively (i.e.,
1327 don't ever pass in anything but zero to it).
1331 sub BuildAuthHierarchyBranch {
1332 my ($tree, $authid, $cnt) = @_;
1334 my $elementdata = GetAuthority(shift @$tree);
1335 my $branch = BuildAuthHierarchy($elementdata,"child".$cnt, $authid);
1336 if (scalar @$tree > 0) {
1337 my $nextBranch = BuildAuthHierarchyBranch($tree, $authid, ++$cnt);
1338 my $nextAuthid = $nextBranch->{authid};
1340 # If we already have the next branch listed as a child, let's
1341 # replace the old listing with the new one. If not, we will add
1342 # the branch at the end.
1343 foreach my $cell (@{$branch->{children}}) {
1344 if ($cell->{authid} eq $nextAuthid) {
1345 $cell = $nextBranch;
1350 push @{$branch->{children}}, $nextBranch unless $found;
1355 =head2 GenerateHierarchy
1357 $hierarchy = &GenerateHierarchy($authid);
1359 Return an arrayref holding one or more "trees" representing
1360 authority hierarchies.
1364 sub GenerateHierarchy {
1366 my $trees = BuildAuthHierarchies($authid);
1367 my @trees = split /;/,$trees ;
1368 push @trees,$trees unless (@trees);
1369 my @loophierarchies;
1370 foreach my $tree (@trees){
1371 my @tree=split /,/,$tree;
1372 push @tree, $tree unless (@tree);
1373 my $branch = BuildAuthHierarchyBranch(\@tree, $authid);
1374 push @loophierarchies, [ $branch ];
1376 return \@loophierarchies;
1379 sub _get_authid_subfield{
1381 return $field->subfield('9')||$field->subfield('3');
1383 =head2 GetHeaderAuthority
1385 $ref= &GetHeaderAuthority( $authid)
1387 return a hashref in order auth_header table data
1391 sub GetHeaderAuthority{
1392 my $authid = shift @_;
1393 my $sql= "SELECT * from auth_header WHERE authid = ?";
1394 my $dbh=C4::Context->dbh;
1395 my $rq= $dbh->prepare($sql);
1396 $rq->execute($authid);
1397 my $data= $rq->fetchrow_hashref;
1401 =head2 AddAuthorityTrees
1403 $ref= &AddAuthorityTrees( $authid, $trees)
1405 return success or failure
1409 sub AddAuthorityTrees{
1410 my $authid = shift @_;
1411 my $trees = shift @_;
1412 my $sql= "UPDATE IGNORE auth_header set authtrees=? WHERE authid = ?";
1413 my $dbh=C4::Context->dbh;
1414 my $rq= $dbh->prepare($sql);
1415 return $rq->execute($trees,$authid);
1420 $ref= &merge(mergefrom,$MARCfrom,$mergeto,$MARCto)
1422 Could add some feature : Migrating from a typecode to an other for instance.
1423 Then we should add some new parameter : bibliotargettag, authtargettag
1428 my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_;
1429 my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0);
1430 my $dbh=C4::Context->dbh;
1431 my $authtypecodefrom = GetAuthTypeCode($mergefrom);
1432 my $authtypecodeto = GetAuthTypeCode($mergeto);
1433 # warn "mergefrom : $authtypecodefrom $mergefrom mergeto : $authtypecodeto $mergeto ";
1434 # return if authority does not exist
1435 return "error MARCFROM not a marcrecord ".Data::Dumper::Dumper($MARCfrom) if scalar($MARCfrom->fields()) == 0;
1436 return "error MARCTO not a marcrecord".Data::Dumper::Dumper($MARCto) if scalar($MARCto->fields()) == 0;
1437 # search the tag to report
1438 my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
1439 $sth->execute($authtypecodefrom);
1440 my ($auth_tag_to_report_from) = $sth->fetchrow;
1441 $sth->execute($authtypecodeto);
1442 my ($auth_tag_to_report_to) = $sth->fetchrow;
1445 @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to);
1447 @record_from = $MARCfrom->field($auth_tag_to_report_from)->subfields() if $MARCfrom->field($auth_tag_to_report_from);
1450 # search all biblio tags using this authority.
1451 #Getting marcbiblios impacted by the change.
1453 my $oConnection=C4::Context->Zconn("biblioserver",0);
1454 # We used to use XML syntax here, but that no longer works.
1455 # Thankfully, we don't need it.
1457 $query= "an=".$mergefrom;
1458 my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
1461 $count=$oResult->size();
1464 while ( $z<$count ) {
1465 my $marcrecordzebra = C4::Search::new_record_from_zebra(
1467 $oResult->record($z)->raw()
1469 my ( $biblionumbertagfield, $biblionumbertagsubfield ) = &GetMarcFromKohaField( "biblio.biblionumber", '' );
1470 my $i = ($biblionumbertagfield < 10)
1471 ? $marcrecordzebra->field( $biblionumbertagfield )->data
1472 : $marcrecordzebra->subfield( $biblionumbertagfield, $biblionumbertagsubfield );
1473 my $marcrecorddb = GetMarcBiblio($i);
1474 push @reccache, $marcrecorddb;
1477 $oResult->destroy();
1478 #warn scalar(@reccache)." biblios to update";
1479 # Get All candidate Tags for the change
1480 # (This will reduce the search scope in marc records).
1481 $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
1482 $sth->execute($authtypecodefrom);
1483 my @tags_using_authtype;
1484 while (my ($tagfield) = $sth->fetchrow) {
1485 push @tags_using_authtype,$tagfield ;
1488 if ($authtypecodeto ne $authtypecodefrom){
1489 # If many tags, take the first
1490 $sth->execute($authtypecodeto);
1491 $tag_to=$sth->fetchrow;
1494 # BulkEdit marc records
1495 # May be used as a template for a bulkedit field
1496 foreach my $marcrecord(@reccache){
1498 foreach my $tagfield (@tags_using_authtype){
1499 # warn "tagfield : $tagfield ";
1500 foreach my $field ($marcrecord->field($tagfield)){
1501 # biblio is linked to authority with $9 subfield containing authid
1502 my $auth_number=$field->subfield("9");
1503 my $tag=$field->tag();
1504 if ($auth_number==$mergefrom) {
1505 my $field_to=MARC::Field->new(($tag_to?$tag_to:$tag),$field->indicator(1),$field->indicator(2),"9"=>$mergeto);
1507 foreach my $subfield (grep {$_->[0] ne '9'} @record_to) {
1508 $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1509 $exclude.= $subfield->[0];
1511 $exclude='['.$exclude.']';
1512 # add subfields in $field not included in @record_to
1513 my @restore= grep {$_->[0]!~/$exclude/} $field->subfields();
1514 foreach my $subfield (@restore) {
1515 $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1517 $marcrecord->delete_field($field);
1518 $marcrecord->insert_grouped_field($field_to);
1523 my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ;
1526 $biblionumber=$marcrecord->field($bibliotag)->data;
1529 $biblionumber=$marcrecord->subfield($bibliotag,$bibliosubf);
1531 unless ($biblionumber){
1532 warn "pas de numéro de notice bibliographique dans : ".$marcrecord->as_formatted;
1536 &ModBiblio($marcrecord,$biblionumber,GetFrameworkCode($biblionumber)) ;
1537 $counteditedbiblio++;
1538 warn $counteditedbiblio if (($counteditedbiblio % 10) and $ENV{DEBUG});
1541 return $counteditedbiblio;
1542 # now, find every other authority linked with this authority
1543 # now, find every other authority linked with this authority
1544 # my $oConnection=C4::Context->Zconn("authorityserver");
1546 # # att 9210 Auth-Internal-authtype
1547 # # att 9220 Auth-Internal-LN
1548 # # ccl.properties to add for authorities
1549 # $query= "= ".$mergefrom;
1550 # my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
1551 # my $count=$oResult->size() if ($oResult);
1554 # while ( $z<$count ) {
1556 # $rec=$oResult->record($z);
1557 # my $marcdata = $rec->raw();
1558 # push @reccache, $marcdata;
1561 # $oResult->destroy();
1562 # foreach my $marc(@reccache){
1565 # $marcrecord = MARC::File::USMARC::decode($marc);
1566 # foreach my $tagfield (@tags_using_authtype){
1567 # $tagfield=substr($tagfield,0,3);
1568 # my @tags = $marcrecord->field($tagfield);
1569 # foreach my $tag (@tags){
1570 # my $tagsubs=$tag->subfield("9");
1571 # #warn "$tagfield:$tagsubs:$mergefrom";
1572 # if ($tagsubs== $mergefrom) {
1573 # $tag->update("9" =>$mergeto);
1574 # foreach my $subfield (@record_to) {
1575 # # warn "$subfield,$subfield->[0],$subfield->[1]";
1576 # $tag->update($subfield->[0] =>$subfield->[1]);
1579 # $marcrecord->delete_field($tag);
1580 # $marcrecord->add_fields($tag);
1583 # }#foreach tagfield
1584 # my $authoritynumber = TransformMarcToKoha($dbh,$marcrecord,"") ;
1586 # &ModAuthority($marcrecord,$authoritynumber,GetAuthTypeCode($authoritynumber)) ;
1592 =head2 get_auth_type_location
1594 my ($tag, $subfield) = get_auth_type_location($auth_type_code);
1596 Get the tag and subfield used to store the heading type
1597 for indexing purposes. The C<$auth_type> parameter is
1598 optional; if it is not supplied, assume ''.
1600 This routine searches the MARC authority framework
1601 for the tag and subfield whose kohafield is
1602 C<auth_header.authtypecode>; if no such field is
1603 defined in the framework, default to the hardcoded value
1604 specific to the MARC format.
1608 sub get_auth_type_location {
1609 my $auth_type_code = @_ ? shift : '';
1611 my ($tag, $subfield) = GetAuthMARCFromKohaField('auth_header.authtypecode', $auth_type_code);
1612 if (defined $tag and defined $subfield and $tag != 0 and $subfield ne '' and $subfield ne ' ') {
1613 return ($tag, $subfield);
1615 if (C4::Context->preference('marcflavour') eq "MARC21") {
1616 return C4::AuthoritiesMarc::MARC21::default_auth_type_location();
1618 return C4::AuthoritiesMarc::UNIMARC::default_auth_type_location();
1623 END { } # module clean-up code here (global destructor)
1630 Koha Development Team <http://koha-community.org/>
1632 Paul POULAIN paul.poulain@free.fr