koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/export export.pl [rel_2_2]


From: Joshua Ferraro
Subject: [Koha-cvs] koha/export export.pl [rel_2_2]
Date: Fri, 26 May 2006 04:17:29 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         rel_2_2
Changes by:     Joshua Ferraro <address@hidden> 06/05/26 04:17:29

Modified files:
        export         : export.pl 

Log message:
        Much better error handling, will now save broken records to a dump
        file. Will also display warnings provided by the MARC::Record package

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/koha/export/export.pl.diff?only_with_tag=rel_2_2&tr1=1.1.2.4&tr2=1.1.2.5&r1=text&r2=text

Patches:
Index: koha/export/export.pl
diff -u koha/export/export.pl:1.1.2.4 koha/export/export.pl:1.1.2.5
--- koha/export/export.pl:1.1.2.4       Thu May 25 21:25:12 2006
+++ koha/export/export.pl       Fri May 26 04:17:29 2006
@@ -59,22 +59,24 @@
 my $VERSION = '.02';
 
 # get the command-line options
-my ($format,$encoding,$ignoreerrors,$assumeunicode,$outfile,$help) = 
('MARC','UTF-8','','','koha.mrc','');
+my ($format,$encoding,$ignoreerrors,$assumeunicode,$outfile,$dumpfile,$help) = 
('MARC','UTF-8','','','koha.mrc','dump','');
 GetOptions(
-       'format:s'              => \$format,
+       'format:s'                      => \$format,
        'encoding:s'            => \$encoding,
        ignoreerrors            => \$ignoreerrors,
        assumeunicode           => \$assumeunicode,
-       'file:s'                => \$outfile,
+       'file:s'                        => \$outfile,
+       'dump:s'                        => \$dumpfile,
        h                                       => \$help,
 );
 if ($help) {die $USAGE};
-
 # open our filehandle, if UTF-8, set the utf8 flag for Perl
 if ((!$encoding) || (lc($encoding) =~ /^utf-?8$/o)) {
-       open (OUT,">utf8",$outfile);
+       open (OUT,">utf8",$outfile) or die $!;
+       open (DUMP,">utf8",$dumpfile) or die $!;
 } else {
        open(OUT,">$outfile") or die $!;
+       open(DUMP,">$dumpfile") or die $!;
 }
 
 # set the MARC::Charset flags specified by user
@@ -87,21 +89,48 @@
 
 # open a coneection to the db
 my $dbh=C4::Context->dbh;
+my $count = 0;
+my $presth = $dbh->prepare("select count(*) from biblio");
+$presth->execute();
+my $total = $presth->fetchrow;
+print "$total records found\n";
+print "Exporting now\n";
 my $sth=$dbh->prepare("select bibid from marc_biblio order by bibid");
 $sth->execute();
 while (my ($bibid) = $sth->fetchrow) {
+       $count++;
        my $record = MARCgetbiblio($dbh,$bibid);
        if ((!$format) || (lc($format) =~ /^marc$/o)) { # plain ole binary MARC
                if (lc($encoding) =~ /^utf-?8$/o) {
-                       my $xml = $record->as_xml_record();
-                       my $newrecord = 
MARC::Record::new_from_xml($xml,$encoding);
-                       print OUT $newrecord->as_usmarc();
+                       my $xml;
+                       eval { 
+                               $xml = $record->as_xml_record(); 
+                       };
+                       if ($@) {
+                               warn "problem in as_xml_record() for record 
#$count:".$@; print DUMP $record->as_usmarc();
+                       }
+                       my $newrecord;
+                       eval {
+                               $newrecord = 
MARC::Record::new_from_xml($xml,$encoding); 
+                       };
+                       if ($@) { 
+                               warn "problem in new_from_xml for record 
#$count:".$@; 
+                               print DUMP $xml;
+                       } else { 
+                               print OUT $newrecord->as_usmarc();
+                       }
                } else {
-                       print OUT $record->as_usmarc();
+                               print OUT $record->as_usmarc();
+               }
+               if ( $record->warnings() ) {
+                       print join( "\n", $record->warnings(), "" );
                }
        } elsif (lc($format) =~ /^marc-?xml$/o) { # MARCXML format
-               my $xml = $record->as_xml_record($encoding);
-               print OUT $xml;
+                       my $xml = $record->as_xml_record($encoding);
+                       print OUT $xml;
+       }
+       if (($count % 100) <1) {
+               print "$count out of $total finished\n"
        }
 }
 close(OUT);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]