[open-ils-commits] r7934 - trunk/Open-ILS/src/extras/import

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Oct 25 20:59:13 EDT 2007


Author: dbs
Date: 2007-10-25 20:45:16 -0400 (Thu, 25 Oct 2007)
New Revision: 7934

Modified:
   trunk/Open-ILS/src/extras/import/marc2bre.pl
Log:
Always delete the 901 field from incoming MARC records;
we append a new 901 with the TCN and read from it, so
there can be only one 901. Well - we could read from the
last 901 in a list of returned fields, but that's not
our current style.

Use 'exists' test to avoid autovivifying hashes for a tiny
amount of overall saving of memory.

If no start ID is supplied at the command line, get the
next biblio.record_entry ID value from the database.

Remove references to the $start_id variable; it is unused.


Modified: trunk/Open-ILS/src/extras/import/marc2bre.pl
===================================================================
--- trunk/Open-ILS/src/extras/import/marc2bre.pl	2007-10-25 21:22:03 UTC (rev 7933)
+++ trunk/Open-ILS/src/extras/import/marc2bre.pl	2007-10-26 00:45:16 UTC (rev 7934)
@@ -18,12 +18,16 @@
 use MARC::Batch;
 use MARC::File::XML ( BinaryEncoding => 'utf-8' );
 use MARC::Charset;
+use DBI;
 
 #MARC::Charset->ignore_errors(1);
 
 my ($id_field, $recid, $user, $config, $idlfile, $marctype, $keyfile, $dontuse_file, $enc, $force_enc, @files, @trash_fields, $quiet) =
-	('', 1, 1, '/openils/conf/opensrf_core.xml', '/openils/conf/fm_IDL.xml', 'USMARC');
+	('', 0, 1, '/openils/conf/opensrf_core.xml', '/openils/conf/fm_IDL.xml', 'USMARC');
 
+my ($db_driver,$db_host,$db_name,$db_user,$db_pw) =
+	('Pg','localhost','evergreen','postgres','postgres');
+
 GetOptions(
 	'marctype=s'	=> \$marctype,
 	'startid=i'	=> \$recid,
@@ -37,6 +41,11 @@
 	'trash=s'	=> \@trash_fields,
 	'xml_idl=s'	=> \$idlfile,
 	'dontuse=s'	=> \$dontuse_file,
+	"db_driver=s"		=> \$db_driver,
+	"db_host=s"		=> \$db_host,
+	"db_name=s"		=> \$db_name,
+	"db_user=s"		=> \$db_user,
+	"db_pw=s"		=> \$db_pw,
 	'quiet'		=> \$quiet
 );
 
@@ -57,8 +66,19 @@
 my @req;
 my %processing_cache;
 
-my $startid = $recid;
+my $dsn = "dbi:$db_driver:host=$db_host;dbname=$db_name";
 
+if (!$recid) {
+	my $dbh = DBI->connect($dsn,$db_user,$db_pw);
+	my $sth = $dbh->prepare("SELECT nextval('biblio.record_entry_id_seq')");
+	$sth->execute;
+	$sth->bind_col(1, \$recid);
+	$sth->fetch;
+	$sth->finish;
+	$recid++;
+	$dbh->disconnect;
+}
+
 my %source_map = (      
 	o  => 'OCLC',
 	i  => 'ISxN',    
@@ -67,8 +87,6 @@
 	g  => 'Gutenberg',  
 );                              
 
-
-
 Fieldmapper->import(IDL => $idlfile);
 
 my %keymap;
@@ -110,7 +128,7 @@
 	my $id;
 
 	$recid++;
-	while ($used_ids{$recid}) {
+	while (exists $used_ids{$recid}) {
 		$recid++;
 	}
 	$used_ids{$recid} = 1;
@@ -195,40 +213,35 @@
 	if (!$id) {
 		my $f = $rec->field('001');
 		$id = $f->data if ($f);
-        $id = '' if ($dontuse_id{$id});
+        $id = '' if (exists $dontuse_id{$id});
 	}
 
-	if (!$id || $dontuse_id{$source.$id}) {
+	if (!$id || exists $dontuse_id{$source.$id}) {
 		my $f = $rec->field('000');
 		$id = $f->data if ($f);
 		$source = 'g' if ($f); # only PG seems to use this
 	}
 
-        if (!$id || $dontuse_id{$source.$id}) {
+        if (!$id || exists $dontuse_id{$source.$id}) {
                 my $f = $rec->field('020');
                 $id = $f->subfield('a') if ($f);
 		$source = 'i' if ($f);
         }
 
-        if (!$id || $dontuse_id{$source.$id}) {
+        if (!$id || exists $dontuse_id{$source.$id}) {
                 my $f = $rec->field('022');
                 $id = $f->subfield('a') if ($f);
 		$source = 'i' if ($f);
         }
 
-        if (!$id || $dontuse_id{$source.$id}) {
+        if (!$id || exists $dontuse_id{$source.$id}) {
                 my $f = $rec->field('010');
                 $id = $f->subfield('a') if ($f);
 		$source = 'l' if ($f);
         }
 
-#        if (!$id) {
-#                my $f = $rec->field($id_field);
-#                $id = $f->subfield('a') if ($f);
-#        }
+	$rec->delete_field($_) for ($rec->field('901', $id_field, @trash_fields));
 
-	$rec->delete_field($_) for ($rec->field($id_field, @trash_fields));
-
 	if ($id) {
 		$id =~ s/\s*$//o;
 		$id =~ s/^\s*//o;
@@ -243,7 +256,7 @@
 		}
 	}
 
-	if ($id && $dontuse_id{$id}) {
+	if ($id && exists $dontuse_id{$id}) {
 		warn "\n!!! ID $id is already in use\n";
 		$id = '';
 	}



More information about the open-ils-commits mailing list