Changes to bulkmarcimport.pl
authorJ. David Bavousett <David.Bavousett@liblime.com>
Fri, 26 Dec 2008 21:56:55 +0000 (15:56 -0600)
committerGalen Charlton <galen.charlton@liblime.com>
Sat, 4 Apr 2009 00:18:29 +0000 (19:18 -0500)
Adds three new switches:

-idmap <filename> - optional output file of
                    map of source record ID numbers
                    to Koha biblionumber
-x                - if idmap is supplied, MARC tag
                    to get source record ID from
-y                - if idmap is supplied, MARC subfield
                    to get source record ID from

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
misc/migration_tools/bulkmarcimport.pl

index b4b84bb..5fc8e4c 100755 (executable)
@@ -31,6 +31,7 @@ binmode(STDOUT, ":utf8");
 
 my ( $input_marc_file, $number, $offset) = ('',0,0);
 my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format);
+my ($sourcetag,$sourcesubfield,$idmapfl);
 
 $|=1;
 
@@ -47,6 +48,9 @@ GetOptions(
     'v:s' => \$verbose,
     'fk' => \$fk_off,
     'm:s' => \$format,
+    'x:s' => \$sourcetag,
+    'y:s' => \$sourcesubfield,
+    'idmap:s' => \$idmapfl,
 );
 
 if ($version || ($input_marc_file eq '')) {
@@ -69,6 +73,9 @@ Parameters:
   d      delete EVERYTHING related to biblio in koha-DB before import. Tables:
          biblio, biblioitems, titems
   m      format, MARCXML or ISO2709 (defaults to ISO2709)
+  x      source bib tag for reporting the source bib number
+  y      source subfield for reporting the source bib number
+  idmap  file for the koha bib and source id
   
 IMPORTANT: don't use this script before you've entered and checked your MARC 
            parameters tables twice (or more!). Otherwise, the import won't work 
@@ -83,6 +90,15 @@ EOF
 exit;
 }
 
+if (defined $idmapfl) {
+  open(IDMAP,">$idmapfl") or die "cannot open $idmapfl \n";
+}
+
+if ((not defined $sourcesubfield) && (not defined $sourcetag)){
+  $sourcetag="910";
+  $sourcesubfield="a";
+}
+
 my $dbh = C4::Context->dbh;
 
 # save the CataloguingLog property : we don't want to log a bulkmarcimport. It will slow the import & 
@@ -172,6 +188,18 @@ RECORD: while (  ) {
             warn "ERROR: Adding biblio $biblionumber failed: $@\n";
             next RECORD;
         } 
+        if (defined $idmapfl) {
+          if ($sourcetag < "010"){
+            if ($record->field($sourcetag)){
+              my $source = $record->field($sourcetag)->data();
+              printf(IDMAP "%s|%s\n",$source,$biblionumber);
+            }
+          } else {
+            my $source=$record->subfield($sourcetag,$sourcesubfield);
+            printf(IDMAP "%s|%s\n",$source,$biblionumber);
+          }
+       }
+       
         eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); };
         if ( $@ ) {
             warn "ERROR: Adding items to bib $biblionumber failed: $@\n";