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";
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 $marcdata=$rec->raw();
271 my $separator=C4::Context->preference('authoritysep');
272 $authrecord = MARC::File::USMARC::decode($marcdata);
273 my $authid=$authrecord->field('001')->data();
275 $newline{authid} = $authid;
276 if ( !$skipmetadata ) {
278 BuildSummary( $authrecord, $authid, $authtypecode );
280 "SELECT auth_tag_to_report FROM auth_types WHERE authtypecode=?";
281 my $sth = $dbh->prepare($query_auth_tag);
282 $sth->execute($authtypecode);
283 my $auth_tag_to_report = $sth->fetchrow;
285 my $mainentry = $authrecord->field($auth_tag_to_report);
288 foreach ( $mainentry->subfields() ) {
289 $reported_tag .= '$' . $_->[0] . $_->[1];
292 my $thisauthtype = GetAuthType(GetAuthTypeCode($authid));
293 unless (defined $thisauthtype) {
294 $thisauthtype = GetAuthType($authtypecode) if $authtypecode;
296 $newline{authtype} = defined($thisauthtype) ?
297 $thisauthtype->{'authtypetext'} : '';
298 $newline{summary} = $summary;
299 $newline{even} = $counter % 2;
300 $newline{reported_tag} = $reported_tag;
303 push @finalresult, \%newline;
306 if (! $skipmetadata) {
307 for (my $z=0; $z<@finalresult; $z++){
308 my $count=CountUsage($finalresult[$z]{authid});
309 $finalresult[$z]{used}=$count;
315 $oAResult->destroy();
316 # $oAuth[0]->destroy();
318 return (\@finalresult, $nbresults);
323 $count= &CountUsage($authid)
325 counts Usage of Authid in bibliorecords.
331 if (C4::Context->preference('NoZebra')) {
332 # Read the index Koha-Auth-Number for this authid and count the lines
333 my $result = C4::Search::NZanalyse("an=$authid");
334 my @tab = split /;/,$result;
339 $query= "an:".$authid;
340 my ($err,$res,$result) = C4::Search::SimpleSearch($query,0,10);
342 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 {
390 return unless defined $record;
391 my $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
531 FROM auth_subfield_structure
533 ORDER BY tagfield,tagsubfield"
535 $sth->execute($authtypecode);
538 my $authorised_value;
547 ( $tag, $subfield, $liblibrarian, , $libopac, $tab,
548 $mandatory, $repeatable, $authorised_value, $authtypecode,
549 $value_builder, $kohafield, $seealso, $hidden,
554 $res->{$tag}->{$subfield}->{lib} = ($forlibrarian or !$libopac)?$liblibrarian:$libopac;
555 $res->{$tag}->{$subfield}->{tab} = $tab;
556 $res->{$tag}->{$subfield}->{mandatory} = $mandatory;
557 $res->{$tag}->{$subfield}->{repeatable} = $repeatable;
558 $res->{$tag}->{$subfield}->{authorised_value} = $authorised_value;
559 $res->{$tag}->{$subfield}->{authtypecode} = $authtypecode;
560 $res->{$tag}->{$subfield}->{value_builder} = $value_builder;
561 $res->{$tag}->{$subfield}->{kohafield} = $kohafield;
562 $res->{$tag}->{$subfield}->{seealso} = $seealso;
563 $res->{$tag}->{$subfield}->{hidden} = $hidden;
564 $res->{$tag}->{$subfield}->{isurl} = $isurl;
565 $res->{$tag}->{$subfield}->{link} = $link;
572 $authid= &AddAuthority($record, $authid,$authtypecode)
574 Either Create Or Modify existing authority.
575 returns authid of the newly created authority
580 # pass the MARC::Record to this function, and it will create the records in the authority table
581 my ($record,$authid,$authtypecode) = @_;
582 my $dbh=C4::Context->dbh;
583 my $leader=' nz a22 o 4500';#Leader for incomplete MARC21 record
585 # if authid empty => true add, find a new authid number
587 if (uc(C4::Context->preference('marcflavour')) eq 'UNIMARC') {
588 $format= 'UNIMARCAUTH';
594 #update date/time to 005 for marc and unimarc
595 my $time=POSIX::strftime("%Y%m%d%H%M%S",localtime);
596 my $f5=$record->field('005');
598 $record->insert_fields_ordered( MARC::Field->new('005',$time.".0") );
601 $f5->update($time.".0");
604 SetUTF8Flag($record);
605 if ($format eq "MARC21") {
606 if (!$record->leader) {
607 $record->leader($leader);
609 if (!$record->field('003')) {
610 $record->insert_fields_ordered(
611 MARC::Field->new('003',C4::Context->preference('MARCOrgCode'))
614 my $date=POSIX::strftime("%y%m%d",localtime);
615 if (!$record->field('008')) {
616 # Get a valid default value for field 008
617 my $default_008 = C4::Context->preference('MARCAuthorityControlField008');
618 if(!$default_008 or length($default_008)<34) {
619 $default_008 = '|| aca||aabn | a|a d';
622 $default_008 = substr($default_008,0,34);
625 $record->insert_fields_ordered( MARC::Field->new('008',$date.$default_008) );
627 if (!$record->field('040')) {
628 $record->insert_fields_ordered(
629 MARC::Field->new('040','','',
630 'a' => C4::Context->preference('MARCOrgCode'),
631 'c' => C4::Context->preference('MARCOrgCode')
637 if ($format eq "UNIMARCAUTH") {
638 $record->leader(" nx j22 ") unless ($record->leader());
639 my $date=POSIX::strftime("%Y%m%d",localtime);
640 my $defaultfield100 = C4::Context->preference('UNIMARCAuthorityField100');
641 if (my $string=$record->subfield('100',"a")){
642 $string=~s/fre50/frey50/;
643 $record->field('100')->update('a'=>$string);
645 elsif ($record->field('100')){
646 $record->field('100')->update('a'=>$date.$defaultfield100);
648 $record->append_fields(
649 MARC::Field->new('100',' ',' '
650 ,'a'=>$date.$defaultfield100)
654 my ($auth_type_tag, $auth_type_subfield) = get_auth_type_location($authtypecode);
655 if (!$authid and $format eq "MARC21") {
656 # only need to do this fix when modifying an existing authority
657 C4::AuthoritiesMarc::MARC21::fix_marc21_auth_type_location($record, $auth_type_tag, $auth_type_subfield);
659 if (my $field=$record->field($auth_type_tag)){
660 $field->update($auth_type_subfield=>$authtypecode);
663 $record->add_fields($auth_type_tag,'','', $auth_type_subfield=>$authtypecode);
669 my $sth=$dbh->prepare("select max(authid) from auth_header");
671 ($authid)=$sth->fetchrow;
673 ##Insert the recordID in MARC record
674 unless ($record->field('001') && $record->field('001')->data() eq $authid){
675 $record->delete_field($record->field('001'));
676 $record->insert_fields_ordered(MARC::Field->new('001',$authid));
679 $auth_exists=$dbh->do(qq(select authid from auth_header where authid=?),undef,$authid);
680 # warn "auth_exists = $auth_exists";
683 $oldRecord=GetAuthority($authid);
684 $record->add_fields('001',$authid) unless ($record->field('001'));
685 # warn "\n\n\n enregistrement".$record->as_formatted;
686 my $sth=$dbh->prepare("update auth_header set authtypecode=?,marc=?,marcxml=? where authid=?");
687 $sth->execute($authtypecode,$record->as_usmarc,$record->as_xml_record($format),$authid) or die $sth->errstr;
691 my $sth=$dbh->prepare("insert into auth_header (authid,datecreated,authtypecode,marc,marcxml) values (?,now(),?,?,?)");
692 $sth->execute($authid,$authtypecode,$record->as_usmarc,$record->as_xml_record($format));
694 logaction( "AUTHORITIES", "ADD", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
696 ModZebra($authid,'specialUpdate',"authorityserver",$oldRecord,$record);
703 $authid= &DelAuthority($authid)
711 my $dbh=C4::Context->dbh;
713 logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
714 ModZebra($authid,"recordDelete","authorityserver",GetAuthority($authid),undef);
715 my $sth = $dbh->prepare("DELETE FROM auth_header WHERE authid=?");
716 $sth->execute($authid);
721 $authid= &ModAuthority($authid,$record,$authtypecode)
723 Modifies authority record, optionally updates attached biblios.
728 my ($authid,$record,$authtypecode)=@_; # deprecated $merge parameter removed
730 my $dbh=C4::Context->dbh;
731 #Now rewrite the $record to table with an add
732 my $oldrecord=GetAuthority($authid);
733 $authid=AddAuthority($record,$authid,$authtypecode);
735 # If a library thinks that updating all biblios is a long process and wishes
736 # to leave that to a cron job, use misc/migration_tools/merge_authority.pl.
737 # In that case set system preference "dontmerge" to 1. Otherwise biblios will
739 unless(C4::Context->preference('dontmerge') eq '1'){
740 &merge($authid,$oldrecord,$authid,$record);
742 # save a record in need_merge_authorities table
743 my $sqlinsert="INSERT INTO need_merge_authorities (authid, done) ".
745 $dbh->do($sqlinsert,undef,($authid,0));
747 logaction( "AUTHORITIES", "MODIFY", $authid, "BEFORE=>" . $oldrecord->as_formatted ) if C4::Context->preference("AuthoritiesLog");
751 =head2 GetAuthorityXML
753 $marcxml= &GetAuthorityXML( $authid)
755 returns xml form of record $authid
759 sub GetAuthorityXML {
760 # Returns MARC::XML of the authority passed in parameter.
762 if (uc(C4::Context->preference('marcflavour')) eq 'UNIMARC') {
763 my $dbh=C4::Context->dbh;
764 my $sth = $dbh->prepare("select marcxml from auth_header where authid=? " );
765 $sth->execute($authid);
766 my ($marcxml)=$sth->fetchrow;
770 # for MARC21, call GetAuthority instead of
771 # getting the XML directly since we may
772 # need to fix up the location of the authority
773 # code -- note that this is reasonably safe
774 # because GetAuthorityXML is used only by the
775 # indexing processes like zebraqueue_start.pl
776 my $record = GetAuthority($authid);
777 return $record->as_xml_record('MARC21');
783 $record= &GetAuthority( $authid)
785 Returns MARC::Record of the authority passed in parameter.
791 my $authority = Koha::Authority->get_from_authid($authid);
792 return unless $authority;
793 return ($authority->record);
798 $result = &GetAuthType($authtypecode)
800 If the authority type specified by C<$authtypecode> exists,
801 returns a hashref of the type's fields. If the type
802 does not exist, returns undef.
807 my ($authtypecode) = @_;
808 my $dbh=C4::Context->dbh;
810 if (defined $authtypecode){ # NOTE - in MARC21 framework, '' is a valid authority
811 # type (FIXME but why?)
812 $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
813 $sth->execute($authtypecode);
814 if (my $res = $sth->fetchrow_hashref) {
822 =head2 FindDuplicateAuthority
824 $record= &FindDuplicateAuthority( $record, $authtypecode)
826 return $authid,Summary if duplicate is found.
828 Comments : an improvement would be to return All the records that match.
832 sub FindDuplicateAuthority {
834 my ($record,$authtypecode)=@_;
835 # warn "IN for ".$record->as_formatted;
836 my $dbh = C4::Context->dbh;
837 # warn "".$record->as_formatted;
838 my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
839 $sth->execute($authtypecode);
840 my ($auth_tag_to_report) = $sth->fetchrow;
842 # warn "record :".$record->as_formatted." auth_tag_to_report :$auth_tag_to_report";
843 # build a request for SearchAuthorities
845 $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
852 my $query='at:'.$authtypecode.' ';
853 my $filtervalues=qr([\001-\040\!\'\"\`\#\$\%\&\*\+,\-\./:;<=>\?\@\(\)\{\[\]\}_\|\~]);
854 if ($record->field($auth_tag_to_report)) {
855 foreach ($record->field($auth_tag_to_report)->subfields()) {
856 $_->[1]=~s/$filtervalues/ /g; $query.= " $op he:\"".$_->[1]."\"" if ($_->[0]=~/[A-z]/);
859 my ($error, $results, $total_hits) = C4::Search::SimpleSearch( $query, 0, 1, [ "authorityserver" ] );
860 # there is at least 1 result => return the 1st one
861 if (!defined $error && @{$results} ) {
862 my $marcrecord = MARC::File::USMARC::decode($results->[0]);
863 return $marcrecord->field('001')->data,BuildSummary($marcrecord,$marcrecord->field('001')->data,$authtypecode);
865 # no result, returns nothing
871 $summary= &BuildSummary( $record, $authid, $authtypecode)
873 Returns a hashref with a summary of the specified record.
875 Comment : authtypecode can be infered from both record and authid.
876 Moreover, authid can also be inferred from $record.
877 Would it be interesting to delete those things.
882 ## give this a Marc record to return summary
883 my ($record,$authid,$authtypecode)=@_;
884 my $dbh=C4::Context->dbh;
886 # handle $authtypecode is NULL or eq ""
888 my $authref = GetAuthType($authtypecode);
889 $summary{authtypecode} = $authref->{authtypecode};
890 $summary{type} = $authref->{authtypetext};
891 $summary{summary} = $authref->{summary};
893 my $marc21subfields = 'abcdfghjklmnopqrstuvxyz68';
894 my %marc21controlrefs = ( 'a' => 'earlier',
900 'n' => 'notapplicable',
904 my %unimarc_relation_from_code = (
910 $thesaurus{'1'}="Peuples";
911 $thesaurus{'2'}="Anthroponymes";
912 $thesaurus{'3'}="Oeuvres";
913 $thesaurus{'4'}="Chronologie";
914 $thesaurus{'5'}="Lieux";
915 $thesaurus{'6'}="Sujets";
918 # if the library has a summary defined, use it. Otherwise, build a standard one
919 # FIXME - it appears that the summary field in the authority frameworks
920 # can work as a display template. However, this doesn't
921 # suit the MARC21 version, so for now the "templating"
922 # feature will be enabled only for UNIMARC for backwards
924 if ($summary{summary} and C4::Context->preference('marcflavour') eq 'UNIMARC') {
925 my @fields = $record->fields();
926 # $reported_tag = '$9'.$result[$counter];
928 foreach my $field (@fields) {
929 my $tag = $field->tag();
930 my $tagvalue = $field->as_string();
931 my $localsummary= $summary{summary};
932 $localsummary =~ s/\[(.?.?.?.?)$tag\*(.*?)\]/$1$tagvalue$2\[$1$tag$2\]/g;
935 $reported_tag.='$3'.$field->data();
938 my @subf = $field->subfields;
939 for my $i (0..$#subf) {
940 my $subfieldcode = $subf[$i][0];
941 my $subfieldvalue = $subf[$i][1];
942 my $tagsubf = $tag.$subfieldcode;
943 $localsummary =~ s/\[(.?.?.?.?)$tagsubf(.*?)\]/$1$subfieldvalue$2\[$1$tagsubf$2\]/g;
946 push @stringssummary, $localsummary if ($localsummary ne $summary{summary});
949 $resultstring = join(" -- ",@stringssummary);
950 $resultstring =~ s/\[(.*?)\]//g;
951 $resultstring =~ s/\n/<br>/g;
952 $summary{summary} = $resultstring;
959 if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
960 # construct UNIMARC summary, that is quite different from MARC21 one
962 foreach my $field ($record->field('2..')) {
963 push @authorized, { heading => $field->as_string('abcdefghijlmnopqrstuvwxyz'), field => $field->tag() };
966 foreach my $field ($record->field('3..')) {
967 push @notes, { note => $field->subfield('a'), field => $field->tag() };
969 foreach my $field ($record->field('4..')) {
970 my $thesaurus = $field->subfield('2') ? "thes. : ".$thesaurus{"$field->subfield('2')"}." : " : '';
971 push @seefrom, { heading => $thesaurus . $field->as_string('abcdefghijlmnopqrstuvwxyz'), type => 'seefrom', field => $field->tag() };
976 my $type = $unimarc_relation_from_code{$_->subfield('5') || 'a'};
977 my $heading = $_->as_string('abcdefgjxyz');
983 authid => $_->subfield('9'),
985 } $record->field('5..');
988 @otherscript = map { {
989 lang => $_->subfield('8') || '',
990 term => $_->subfield('a'),
993 } } $record->field('7..');
996 # construct MARC21 summary
997 # FIXME - looping over 1XX is questionable
998 # since MARC21 authority should have only one 1XX
999 my $subfields_to_report;
1000 foreach my $field ($record->field('1..')) {
1001 my $tag = $field->tag();
1002 next if "152" eq $tag;
1003 # FIXME - 152 is not a good tag to use
1004 # in MARC21 -- purely local tags really ought to be
1006 if ($tag eq '100') {
1007 $subfields_to_report = 'abcdefghjklmnopqrstvxyz';
1008 } elsif ($tag eq '110') {
1009 $subfields_to_report = 'abcdefghklmnoprstvxyz';
1010 } elsif ($tag eq '111') {
1011 $subfields_to_report = 'acdefghklnpqstvxyz';
1012 } elsif ($tag eq '130') {
1013 $subfields_to_report = 'adfghklmnoprstvxyz';
1014 } elsif ($tag eq '148') {
1015 $subfields_to_report = 'abvxyz';
1016 } elsif ($tag eq '150') {
1017 $subfields_to_report = 'abvxyz';
1018 } elsif ($tag eq '151') {
1019 $subfields_to_report = 'avxyz';
1020 } elsif ($tag eq '155') {
1021 $subfields_to_report = 'abvxyz';
1022 } elsif ($tag eq '180') {
1023 $subfields_to_report = 'vxyz';
1024 } elsif ($tag eq '181') {
1025 $subfields_to_report = 'vxyz';
1026 } elsif ($tag eq '182') {
1027 $subfields_to_report = 'vxyz';
1028 } elsif ($tag eq '185') {
1029 $subfields_to_report = 'vxyz';
1031 if ($subfields_to_report) {
1032 push @authorized, { heading => $field->as_string($subfields_to_report), field => $tag };
1034 push @authorized, { heading => $field->as_string(), field => $tag };
1037 foreach my $field ($record->field('4..')) { #See From
1038 my $type = 'seefrom';
1039 $type = ($marc21controlrefs{substr $field->subfield('w'), 0, 1} || '') if ($field->subfield('w'));
1040 if ($type eq 'notapplicable') {
1041 $type = substr $field->subfield('w'), 2, 1;
1042 $type = 'earlier' if $type && $type ne 'n';
1044 if ($type eq 'subfi') {
1045 push @seefrom, { heading => $field->as_string($marc21subfields), type => ($field->subfield('i') || ''), field => $field->tag() };
1047 push @seefrom, { heading => $field->as_string($marc21subfields), type => $type, field => $field->tag() };
1050 foreach my $field ($record->field('5..')) { #See Also
1051 my $type = 'seealso';
1052 $type = ($marc21controlrefs{substr $field->subfield('w'), 0, 1} || '') if ($field->subfield('w'));
1053 if ($type eq 'notapplicable') {
1054 $type = substr $field->subfield('w'), 2, 1;
1055 $type = 'earlier' if $type && $type ne 'n';
1057 if ($type eq 'subfi') {
1059 heading => $field->as_string($marc21subfields),
1060 type => $field->subfield('i'),
1061 field => $field->tag(),
1062 search => $field->as_string($marc21subfields) || '',
1063 authid => $field->subfield('9') || ''
1067 heading => $field->as_string($marc21subfields),
1069 field => $field->tag(),
1070 search => $field->as_string($marc21subfields) || '',
1071 authid => $field->subfield('9') || ''
1075 foreach my $field ($record->field('6..')) {
1076 push @notes, { note => $field->as_string(), field => $field->tag() };
1078 foreach my $field ($record->field('880')) {
1079 my $linkage = $field->subfield('6');
1080 my $category = substr $linkage, 0, 1;
1081 if ($category eq '1') {
1082 $category = 'preferred';
1083 } elsif ($category eq '4') {
1084 $category = 'seefrom';
1085 } elsif ($category eq '5') {
1086 $category = 'seealso';
1089 if ($field->subfield('w')) {
1090 $type = $marc21controlrefs{substr $field->subfield('w'), '0'};
1094 my $direction = $linkage =~ m#/r$# ? 'rtl' : 'ltr';
1095 push @otherscript, { term => $field->as_string($subfields_to_report), category => $category, type => $type, direction => $direction, linkage => $linkage };
1098 $summary{mainentry} = $authorized[0]->{heading};
1099 $summary{authorized} = \@authorized;
1100 $summary{notes} = \@notes;
1101 $summary{seefrom} = \@seefrom;
1102 $summary{seealso} = \@seealso;
1103 $summary{otherscript} = \@otherscript;
1107 =head2 GetAuthorizedHeading
1109 $heading = &GetAuthorizedHeading({ record => $record, authid => $authid })
1111 Takes a MARC::Record object describing an authority record or an authid, and
1112 returns a string representation of the first authorized heading. This routine
1113 should be considered a temporary shim to ease the future migration of authority
1114 data from C4::AuthoritiesMarc to the object-oriented Koha::*::Authority.
1118 sub GetAuthorizedHeading {
1121 unless ($record = $args->{record}) {
1122 return unless $args->{authid};
1123 $record = GetAuthority($args->{authid});
1125 return unless (ref $record eq 'MARC::Record');
1126 if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
1127 # construct UNIMARC summary, that is quite different from MARC21 one
1129 foreach my $field ($record->field('2..')) {
1130 return $field->as_string('abcdefghijlmnopqrstuvwxyz');
1133 foreach my $field ($record->field('1..')) {
1134 my $tag = $field->tag();
1135 next if "152" eq $tag;
1136 # FIXME - 152 is not a good tag to use
1137 # in MARC21 -- purely local tags really ought to be
1139 if ($tag eq '100') {
1140 return $field->as_string('abcdefghjklmnopqrstvxyz68');
1141 } elsif ($tag eq '110') {
1142 return $field->as_string('abcdefghklmnoprstvxyz68');
1143 } elsif ($tag eq '111') {
1144 return $field->as_string('acdefghklnpqstvxyz68');
1145 } elsif ($tag eq '130') {
1146 return $field->as_string('adfghklmnoprstvxyz68');
1147 } elsif ($tag eq '148') {
1148 return $field->as_string('abvxyz68');
1149 } elsif ($tag eq '150') {
1150 return $field->as_string('abvxyz68');
1151 } elsif ($tag eq '151') {
1152 return $field->as_string('avxyz68');
1153 } elsif ($tag eq '155') {
1154 return $field->as_string('abvxyz68');
1155 } elsif ($tag eq '180') {
1156 return $field->as_string('vxyz68');
1157 } elsif ($tag eq '181') {
1158 return $field->as_string('vxyz68');
1159 } elsif ($tag eq '182') {
1160 return $field->as_string('vxyz68');
1161 } elsif ($tag eq '185') {
1162 return $field->as_string('vxyz68');
1164 return $field->as_string();
1171 =head2 BuildAuthHierarchies
1173 $text= &BuildAuthHierarchies( $authid, $force)
1175 return text containing trees for hierarchies
1176 for them to be stored in auth_header
1179 122,1314,2452;1324,2342,3,2452
1183 sub BuildAuthHierarchies{
1184 my $authid = shift @_;
1185 # warn "authid : $authid";
1186 my $force = shift @_ || (C4::Context->preference('marcflavour') eq 'UNIMARC' ? 0 : 1);
1188 my $dbh=C4::Context->dbh;
1190 my $data = GetHeaderAuthority($authid);
1191 if ($data->{'authtrees'} and not $force){
1192 return $data->{'authtrees'};
1193 # } elsif ($data->{'authtrees'}){
1194 # $hierarchies=$data->{'authtrees'};
1196 my $record = GetAuthority($authid);
1198 return unless $record;
1199 foreach my $field ($record->field('5..')){
1202 (C4::Context->preference('marcflavour') eq 'UNIMARC' && $field->subfield('5') && $field->subfield('5') eq 'g') ||
1203 (C4::Context->preference('marcflavour') ne 'UNIMARC' && $field->subfield('w') && substr($field->subfield('w'), 0, 1) eq 'g'));
1205 my $subfauthid=_get_authid_subfield($field) || '';
1206 next if ($subfauthid eq $authid);
1207 my $parentrecord = GetAuthority($subfauthid);
1208 next unless $parentrecord;
1209 my $localresult=$hierarchies;
1211 $trees = BuildAuthHierarchies($subfauthid);
1214 @trees = split(/;/,$trees);
1216 push @trees, $trees;
1221 @globalresult = (@globalresult,@trees);
1224 $hierarchies=join(";",@globalresult);
1226 #Unless there is no ancestor, I am alone.
1227 $hierarchies="$authid" unless ($hierarchies);
1229 AddAuthorityTrees($authid,$hierarchies);
1230 return $hierarchies;
1233 =head2 BuildAuthHierarchy
1235 $ref= &BuildAuthHierarchy( $record, $class,$authid)
1237 return a hashref in order to display hierarchy for record and final Authid $authid
1248 sub BuildAuthHierarchy{
1249 my $record = shift @_;
1250 my $class = shift @_;
1251 my $authid_constructed = shift @_;
1252 return unless ($record && $record->field('001'));
1253 my $authid=$record->field('001')->data();
1255 my $parents=""; my $children="";
1256 my (@loopparents,@loopchildren);
1257 my $marcflavour = C4::Context->preference('marcflavour');
1258 my $relationshipsf = $marcflavour eq 'UNIMARC' ? '5' : 'w';
1259 foreach my $field ($record->field('5..')){
1260 my $subfauthid=_get_authid_subfield($field);
1261 if ($subfauthid && $field->subfield($relationshipsf) && $field->subfield('a')){
1262 my $relationship = substr($field->subfield($relationshipsf), 0, 1);
1263 if ($relationship eq 'h'){
1264 push @loopchildren, { "authid"=>$subfauthid,"value"=>$field->subfield('a')};
1266 elsif ($relationship eq 'g'){
1267 push @loopparents, { "authid"=>$subfauthid,"value"=>$field->subfield('a')};
1269 # brothers could get in there with an else
1272 $cell{"parents"}=\@loopparents;
1273 $cell{"children"}=\@loopchildren;
1274 $cell{"class"}=$class;
1275 $cell{"authid"}=$authid;
1276 $cell{"current_value"} =1 if ($authid eq $authid_constructed);
1277 $cell{"value"}=C4::Context->preference('marcflavour') eq 'UNIMARC' ? $record->subfield('2..',"a") : $record->subfield('1..', 'a');
1281 =head2 BuildAuthHierarchyBranch
1283 $branch = &BuildAuthHierarchyBranch( $tree, $authid[, $cnt])
1285 Return a data structure representing an authority hierarchy
1286 given a list of authorities representing a single branch in
1287 an authority hierarchy tree. $authid is the current node in
1288 the tree (which may or may not be somewhere in the middle).
1289 $cnt represents the level of the upper-most item, and is only
1290 used when BuildAuthHierarchyBranch is called recursively (i.e.,
1291 don't ever pass in anything but zero to it).
1295 sub BuildAuthHierarchyBranch {
1296 my ($tree, $authid, $cnt) = @_;
1298 my $elementdata = GetAuthority(shift @$tree);
1299 my $branch = BuildAuthHierarchy($elementdata,"child".$cnt, $authid);
1300 if (scalar @$tree > 0) {
1301 my $nextBranch = BuildAuthHierarchyBranch($tree, $authid, ++$cnt);
1302 my $nextAuthid = $nextBranch->{authid};
1304 # If we already have the next branch listed as a child, let's
1305 # replace the old listing with the new one. If not, we will add
1306 # the branch at the end.
1307 foreach my $cell (@{$branch->{children}}) {
1308 if ($cell->{authid} eq $nextAuthid) {
1309 $cell = $nextBranch;
1314 push @{$branch->{children}}, $nextBranch unless $found;
1319 =head2 GenerateHierarchy
1321 $hierarchy = &GenerateHierarchy($authid);
1323 Return an arrayref holding one or more "trees" representing
1324 authority hierarchies.
1328 sub GenerateHierarchy {
1330 my $trees = BuildAuthHierarchies($authid);
1331 my @trees = split /;/,$trees ;
1332 push @trees,$trees unless (@trees);
1333 my @loophierarchies;
1334 foreach my $tree (@trees){
1335 my @tree=split /,/,$tree;
1336 push @tree, $tree unless (@tree);
1337 my $branch = BuildAuthHierarchyBranch(\@tree, $authid);
1338 push @loophierarchies, [ $branch ];
1340 return \@loophierarchies;
1343 sub _get_authid_subfield{
1345 return $field->subfield('9')||$field->subfield('3');
1347 =head2 GetHeaderAuthority
1349 $ref= &GetHeaderAuthority( $authid)
1351 return a hashref in order auth_header table data
1355 sub GetHeaderAuthority{
1356 my $authid = shift @_;
1357 my $sql= "SELECT * from auth_header WHERE authid = ?";
1358 my $dbh=C4::Context->dbh;
1359 my $rq= $dbh->prepare($sql);
1360 $rq->execute($authid);
1361 my $data= $rq->fetchrow_hashref;
1365 =head2 AddAuthorityTrees
1367 $ref= &AddAuthorityTrees( $authid, $trees)
1369 return success or failure
1373 sub AddAuthorityTrees{
1374 my $authid = shift @_;
1375 my $trees = shift @_;
1376 my $sql= "UPDATE IGNORE auth_header set authtrees=? WHERE authid = ?";
1377 my $dbh=C4::Context->dbh;
1378 my $rq= $dbh->prepare($sql);
1379 return $rq->execute($trees,$authid);
1384 $ref= &merge(mergefrom,$MARCfrom,$mergeto,$MARCto)
1386 Could add some feature : Migrating from a typecode to an other for instance.
1387 Then we should add some new parameter : bibliotargettag, authtargettag
1392 my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_;
1393 my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0);
1394 my $dbh=C4::Context->dbh;
1395 my $authtypecodefrom = GetAuthTypeCode($mergefrom);
1396 my $authtypecodeto = GetAuthTypeCode($mergeto);
1397 # warn "mergefrom : $authtypecodefrom $mergefrom mergeto : $authtypecodeto $mergeto ";
1398 # return if authority does not exist
1399 return "error MARCFROM not a marcrecord ".Data::Dumper::Dumper($MARCfrom) if scalar($MARCfrom->fields()) == 0;
1400 return "error MARCTO not a marcrecord".Data::Dumper::Dumper($MARCto) if scalar($MARCto->fields()) == 0;
1401 # search the tag to report
1402 my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
1403 $sth->execute($authtypecodefrom);
1404 my ($auth_tag_to_report_from) = $sth->fetchrow;
1405 $sth->execute($authtypecodeto);
1406 my ($auth_tag_to_report_to) = $sth->fetchrow;
1409 @record_to = $MARCto->field($auth_tag_to_report_to)->subfields() if $MARCto->field($auth_tag_to_report_to);
1411 @record_from = $MARCfrom->field($auth_tag_to_report_from)->subfields() if $MARCfrom->field($auth_tag_to_report_from);
1414 # search all biblio tags using this authority.
1415 #Getting marcbiblios impacted by the change.
1416 if (C4::Context->preference('NoZebra')) {
1418 my $dbh=C4::Context->dbh;
1419 my $rq=$dbh->prepare(qq(SELECT biblionumbers from nozebra where indexname="an" and server="biblioserver" and value="$mergefrom" ));
1421 while (my $biblionumbers=$rq->fetchrow){
1422 my @biblionumbers=split /;/,$biblionumbers;
1423 foreach (@biblionumbers) {
1424 if ($_=~/(\d+),.*/) {
1425 my $marc=GetMarcBiblio($1);
1426 push @reccache,$marc;
1432 my $oConnection=C4::Context->Zconn("biblioserver",0);
1433 # We used to use XML syntax here, but that no longer works.
1434 # Thankfully, we don't need it.
1436 $query= "an=".$mergefrom;
1437 my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
1440 $count=$oResult->size();
1443 while ( $z<$count ) {
1445 $rec=$oResult->record($z);
1446 my $marcdata = $rec->raw();
1447 my $marcrecordzebra= MARC::Record->new_from_usmarc($marcdata);
1448 my ( $biblionumbertagfield, $biblionumbertagsubfield ) = &GetMarcFromKohaField( "biblio.biblionumber", '' );
1449 my $i = ($biblionumbertagfield < 10) ? $marcrecordzebra->field($biblionumbertagfield)->data : $marcrecordzebra->subfield($biblionumbertagfield, $biblionumbertagsubfield);
1450 my $marcrecorddb=GetMarcBiblio($i);
1451 push @reccache, $marcrecorddb;
1454 $oResult->destroy();
1456 #warn scalar(@reccache)." biblios to update";
1457 # Get All candidate Tags for the change
1458 # (This will reduce the search scope in marc records).
1459 $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
1460 $sth->execute($authtypecodefrom);
1461 my @tags_using_authtype;
1462 while (my ($tagfield) = $sth->fetchrow) {
1463 push @tags_using_authtype,$tagfield ;
1466 if ($authtypecodeto ne $authtypecodefrom){
1467 # If many tags, take the first
1468 $sth->execute($authtypecodeto);
1469 $tag_to=$sth->fetchrow;
1472 # BulkEdit marc records
1473 # May be used as a template for a bulkedit field
1474 foreach my $marcrecord(@reccache){
1476 foreach my $tagfield (@tags_using_authtype){
1477 # warn "tagfield : $tagfield ";
1478 foreach my $field ($marcrecord->field($tagfield)){
1479 # biblio is linked to authority with $9 subfield containing authid
1480 my $auth_number=$field->subfield("9");
1481 my $tag=$field->tag();
1482 if ($auth_number==$mergefrom) {
1483 my $field_to=MARC::Field->new(($tag_to?$tag_to:$tag),$field->indicator(1),$field->indicator(2),"9"=>$mergeto);
1485 foreach my $subfield (grep {$_->[0] ne '9'} @record_to) {
1486 $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1487 $exclude.= $subfield->[0];
1489 $exclude='['.$exclude.']';
1490 # add subfields in $field not included in @record_to
1491 my @restore= grep {$_->[0]!~/$exclude/} $field->subfields();
1492 foreach my $subfield (@restore) {
1493 $field_to->add_subfields($subfield->[0] =>$subfield->[1]);
1495 $marcrecord->delete_field($field);
1496 $marcrecord->insert_grouped_field($field_to);
1501 my ($bibliotag,$bibliosubf) = GetMarcFromKohaField("biblio.biblionumber","") ;
1504 $biblionumber=$marcrecord->field($bibliotag)->data;
1507 $biblionumber=$marcrecord->subfield($bibliotag,$bibliosubf);
1509 unless ($biblionumber){
1510 warn "pas de numéro de notice bibliographique dans : ".$marcrecord->as_formatted;
1514 &ModBiblio($marcrecord,$biblionumber,GetFrameworkCode($biblionumber)) ;
1515 $counteditedbiblio++;
1516 warn $counteditedbiblio if (($counteditedbiblio % 10) and $ENV{DEBUG});
1519 return $counteditedbiblio;
1520 # now, find every other authority linked with this authority
1521 # now, find every other authority linked with this authority
1522 # my $oConnection=C4::Context->Zconn("authorityserver");
1524 # # att 9210 Auth-Internal-authtype
1525 # # att 9220 Auth-Internal-LN
1526 # # ccl.properties to add for authorities
1527 # $query= "= ".$mergefrom;
1528 # my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
1529 # my $count=$oResult->size() if ($oResult);
1532 # while ( $z<$count ) {
1534 # $rec=$oResult->record($z);
1535 # my $marcdata = $rec->raw();
1536 # push @reccache, $marcdata;
1539 # $oResult->destroy();
1540 # foreach my $marc(@reccache){
1543 # $marcrecord = MARC::File::USMARC::decode($marc);
1544 # foreach my $tagfield (@tags_using_authtype){
1545 # $tagfield=substr($tagfield,0,3);
1546 # my @tags = $marcrecord->field($tagfield);
1547 # foreach my $tag (@tags){
1548 # my $tagsubs=$tag->subfield("9");
1549 # #warn "$tagfield:$tagsubs:$mergefrom";
1550 # if ($tagsubs== $mergefrom) {
1551 # $tag->update("9" =>$mergeto);
1552 # foreach my $subfield (@record_to) {
1553 # # warn "$subfield,$subfield->[0],$subfield->[1]";
1554 # $tag->update($subfield->[0] =>$subfield->[1]);
1557 # $marcrecord->delete_field($tag);
1558 # $marcrecord->add_fields($tag);
1561 # }#foreach tagfield
1562 # my $authoritynumber = TransformMarcToKoha($dbh,$marcrecord,"") ;
1564 # &ModAuthority($marcrecord,$authoritynumber,GetAuthTypeCode($authoritynumber)) ;
1570 =head2 get_auth_type_location
1572 my ($tag, $subfield) = get_auth_type_location($auth_type_code);
1574 Get the tag and subfield used to store the heading type
1575 for indexing purposes. The C<$auth_type> parameter is
1576 optional; if it is not supplied, assume ''.
1578 This routine searches the MARC authority framework
1579 for the tag and subfield whose kohafield is
1580 C<auth_header.authtypecode>; if no such field is
1581 defined in the framework, default to the hardcoded value
1582 specific to the MARC format.
1586 sub get_auth_type_location {
1587 my $auth_type_code = @_ ? shift : '';
1589 my ($tag, $subfield) = GetAuthMARCFromKohaField('auth_header.authtypecode', $auth_type_code);
1590 if (defined $tag and defined $subfield and $tag != 0 and $subfield ne '' and $subfield ne ' ') {
1591 return ($tag, $subfield);
1593 if (C4::Context->preference('marcflavour') eq "MARC21") {
1594 return C4::AuthoritiesMarc::MARC21::default_auth_type_location();
1596 return C4::AuthoritiesMarc::UNIMARC::default_auth_type_location();
1601 END { } # module clean-up code here (global destructor)
1608 Koha Development Team <http://koha-community.org/>
1610 Paul POULAIN paul.poulain@free.fr