Lines 663-700
sub AddAuthority {
Link Here
|
663 |
$record->add_fields($auth_type_tag,'','', $auth_type_subfield=>$authtypecode); |
663 |
$record->add_fields($auth_type_tag,'','', $auth_type_subfield=>$authtypecode); |
664 |
} |
664 |
} |
665 |
|
665 |
|
666 |
my $auth_exists=0; |
666 |
# Save record into auth_header, update 001 |
667 |
my $oldRecord; |
667 |
if (!$authid ) { |
668 |
if (!$authid) { |
668 |
# Save a blank record, get authid |
669 |
my $sth=$dbh->prepare("select max(authid) from auth_header"); |
669 |
$dbh->do( "INSERT INTO auth_header (datecreated,marcxml) values (NOW(),?)", undef, '' ); |
670 |
$sth->execute; |
670 |
$authid = $dbh->last_insert_id( undef, undef, 'auth_header', 'authid' ); |
671 |
($authid)=$sth->fetchrow; |
671 |
logaction( "AUTHORITIES", "ADD", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog"); |
672 |
$authid=$authid+1; |
|
|
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)); |
677 |
} |
672 |
} |
678 |
} else { |
673 |
# Insert/update the recordID in MARC record |
679 |
$auth_exists=$dbh->do(qq(select authid from auth_header where authid=?),undef,$authid); |
674 |
$record->delete_field( $record->field('001') ); |
680 |
# warn "auth_exists = $auth_exists"; |
675 |
$record->insert_fields_ordered( MARC::Field->new( '001', $authid ) ); |
681 |
} |
676 |
# Update |
682 |
if ($auth_exists>0){ |
677 |
$dbh->do( "UPDATE auth_header SET authtypecode=?, marc=?, marcxml=? WHERE authid=?", undef, $authtypecode, $record->as_usmarc, $record->as_xml_record($format), $authid ) or die $DBI::errstr; |
683 |
$oldRecord=GetAuthority($authid); |
678 |
ModZebra( $authid, 'specialUpdate', 'authorityserver', $record ); |
684 |
$record->add_fields('001',$authid) unless ($record->field('001')); |
679 |
|
685 |
# warn "\n\n\n enregistrement".$record->as_formatted; |
680 |
return ( $authid ); |
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; |
688 |
$sth->finish; |
689 |
} |
690 |
else { |
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)); |
693 |
$sth->finish; |
694 |
logaction( "AUTHORITIES", "ADD", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog"); |
695 |
} |
696 |
ModZebra($authid,'specialUpdate',"authorityserver",$oldRecord,$record); |
697 |
return ($authid); |
698 |
} |
681 |
} |
699 |
|
682 |
|
700 |
|
683 |
|