[Koha-patches] [PATCH] Changes to bulkmarcimport.pl

David Bavousett david.bavousett at liblime.com
Fri Jan 30 18:36:23 CET 2009


These changes were suggested by Galen to Michele Maenpaa, and I am
merely transmitting
them for inclusion in the general release.
---
 misc/migration_tools/bulkmarcimport.pl |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/misc/migration_tools/bulkmarcimport.pl
b/misc/migration_tools/bulkmarcimport.pl
index b4b84bb..4be47e2 100755
--- a/misc/migration_tools/bulkmarcimport.pl
+++ b/misc/migration_tools/bulkmarcimport.pl
@@ -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
@@ -82,6 +89,14 @@ EOF
 ;#'
 exit;
 }
+if (define $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;

@@ -172,6 +187,19 @@ 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";
-- 
1.6.0.4



More information about the Koha-patches mailing list