[Koha-patches] [PATCH] Bug 4226: bulkmarcimport.pl doesn't replace 001

Brian Harrington brian at jhu.edu
Fri Feb 19 00:02:29 CET 2010


Please ignore previous commit.  This patch makes sure that the 001
is replaced in MARC21 records loaded by buldmarcimport.pl unless
the 003 matches the MARCOrgCode.  It also fixes AuthoritiesMarc.pm
to make sure that MARC21 records have their 003 updated when the
001 changes.
---
 C4/AuthoritiesMarc.pm                  |    6 ++++++
 misc/migration_tools/bulkmarcimport.pl |    9 ++++++++-
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm
index d77ac2a..ec04fd1 100644
--- a/C4/AuthoritiesMarc.pm
+++ b/C4/AuthoritiesMarc.pm
@@ -696,6 +696,12 @@ sub AddAuthority {
     unless ($record->field('001') && $record->field('001')->data() eq $authid){
         $record->delete_field($record->field('001'));
         $record->insert_fields_ordered(MARC::Field->new('001',$authid));
+		#If we add our ID, we should make sure we add our org code
+		#Is there a UNIMARC equiv?
+		if ($format eq 'MARC21') {
+			$record->delete_field($record->field('003'));
+			$record->insert_fields_ordered(MARC::Field->new('003',C4::Context->preference('MARCOrgCode')));
+		}
     }
   } else {
     $auth_exists=$dbh->do(qq(select authid from auth_header where authid=?),undef,$authid);
diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl
index da0ebf7..fdd9c06 100755
--- a/misc/migration_tools/bulkmarcimport.pl
+++ b/misc/migration_tools/bulkmarcimport.pl
@@ -112,6 +112,7 @@ my $marcFlavour = C4::Context->preference('marcflavour') || 'MARC21';
 
 print "Characteristic MARC flavour: $marcFlavour\n" if $verbose;
 my $starttime = gettimeofday;
+my $symbol = C4::Context->preference('MARCOrgCode');
 my $batch;
 my $fh = IO::File->new($input_marc_file); # don't let MARC::Batch open the file, as it applies the ':utf8' IO layer
 if (defined $format && $format =~ /XML/i) {
@@ -251,6 +252,10 @@ RECORD: while (  ) {
             use C4::AuthoritiesMarc;
             my $authtypecode=GuessAuthTypeCode($record);
             my $authid= ($id?$id:GuessAuthId($record));
+			my $authidsource = '';
+			if ($record->field('003')) {
+				$authidsource = $record->field('003')->as_string();
+			}
             if ($authid && GetAuthority($authid)){
             ## Authority has an id and is in database : Replace
                 eval { ( $authid ) = ModAuthority($authid,$record, $authtypecode) };
@@ -262,8 +267,10 @@ RECORD: while (  ) {
 					printlog({id=>$originalid||$id||$authid, op=>"edit",status=>"ok"}) if ($logfile);
 				}
             }  
-            elsif (defined $authid) {
+            elsif ((defined $authid) && (($marcFlavour eq "UNIMARC") || ($symbol eq $authidsource))) {
             ## An authid is defined but no authority in database : add
+			## unless it's not our record, does UNIMARC have equivalent
+			## of 003?
                 eval { ( $authid ) = AddAuthority($record,$authid, $authtypecode) };
                 if ($@){
                     warn "Problem with authority $authid Cannot Add ".$@;
-- 
1.6.3.3




More information about the Koha-patches mailing list