bugfix: now database names are always transfered to filtering function
[webpac] / all2xml.pl
index 3fc1299..8f7e26c 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use IsisDB;
+use Biblio::Isis;
 use Getopt::Std;
 use Data::Dumper;
 use XML::Simple;
@@ -22,7 +22,8 @@ die "FATAL: can't find configuration file '$config_file'" if (! -e $config_file)
 my $config;
 
 #use index_DBI;                # default DBI module for index
-use index_DBI_cache;   # faster DBI module using memory cache
+#use index_DBI_cache;  # faster DBI module using memory cache
+use index_DBI_filter;  # filter support for indexes
 my $index;
 
 my %opts;
@@ -257,8 +258,6 @@ sub data2xml {
                        # init vars so that we go into while...
                        ($swish,$display) = (1,1);
 
-                       # placeholder for all repeatable entries for index
-
                        sub mkformat($$) {
                                my $x = shift || die "mkformat needs tag reference";
                                my $data = shift || return;
@@ -634,6 +633,10 @@ if ($my_unac_filter) {
 
 foreach my $database ($cfg->Sections) {
 
+       # save database name in global variable path for later
+       # (need for index filter creation)
+       $path = $database;
+
        my $type = lc($cfg -> val($database, 'type')) || die "$database doesn't have 'type' defined";
        my $add_xml = $cfg -> val($database, 'xml');    # optional
 
@@ -737,13 +740,16 @@ print STDERR "using: $type...\n";
                my $isis_db = $cfg -> val($database, 'isis_db') || die "$database doesn't have 'isis_db' defined!";
 
                $import2cp = Text::Iconv->new($config->{isis_codepage},$codepage);
-               my $db = new IsisDB( isisdb => $isis_db );
+               my $db = new Biblio::Isis( isisdb => $isis_db );
 
-               my $max_rowid = $db->{'maxmfn'} || die "can't find maxmfn";
+               my $max_rowid = $db->count if ($db);
 
-               print STDERR "Reading database: $isis_db [$max_rowid rows]\n";
+               if (! $max_rowid) {
+                       print STDERR "FATAL: can't read ISIS database: $isis_db, skipping...\n";
+                       next;
+               }
 
-               my $path = $database;
+               print STDERR "Reading database: $isis_db [$max_rowid rows]\n";
 
                for (my $row_id = 1; $row_id <= $max_rowid; $row_id++ ) {
                        my $row = $db->to_hash( $row_id );
@@ -826,6 +832,9 @@ print STDERR "using: $type...\n";
                                print "Document-Type: XML\n\n$xml\n";
                        }
                }
+
+               print STDERR "\n";
+
        } elsif ($type_base eq "marc") {
 
                require MARC::File::USMARC;
@@ -837,13 +846,17 @@ print STDERR "using: $type...\n";
                warn "marc_format is no longer used!" if ($config->{marc_format});
                print STDERR "Reading MARC file '$marc_file'\n";
 
-               my $marc = MARC::File::USMARC->in( $marc_file )
-                       || die "Can't open MARC file '$marc_file': ".$MARC::File::ERROR;
+               my $marc = MARC::File::USMARC->in( $marc_file );
+
+               if (! $marc) {
+                       print STDERR "FATAL: can't read MARC file: $marc_file, skipping...\n";
+                       next;
+               }
 
                # count records in MARC file
                sub marc_count {
                        my $filename = shift || die;
-                       my $file = MARC::File::USMARC->in($filename) || die $MARC::File::ERROR;
+                       my $file = MARC::File::USMARC->in($filename) || return;
                        my $count = 0;
                        while ($file->skip()) {
                                $count++;
@@ -853,11 +866,11 @@ print STDERR "using: $type...\n";
 
                my $count = marc_count($marc_file) || warn "no records in '$marc_file'?";
 
-               my $i = 0;
+               my $i = 1;
 
                while( my $rec = $marc->next() ) {
 
-                       progress($i++,$count);
+                       progress($i,$count);
 
                        my $swishpath = $database."#".$i;
 
@@ -868,6 +881,8 @@ print STDERR "using: $type...\n";
                                print "Content-Length: ".(length($xml)+1)."\n";
                                print "Document-Type: XML\n\n$xml\n";
                        }
+
+                       $i++;
                }
 
                print STDERR "\n";
@@ -932,8 +947,8 @@ all2xml.pl - read various file formats and dump XML for SWISH-E
 
 =head1 DESCRIPTION
 
-This command will read ISIS data file using IsisDB perl module, MARC
-records using MARC module and optionally Micro$oft Excel files to
+This command will read ISIS data file using Biblio::Isis perl module, MARC
+records using MARC::File module and optionally Micro$oft Excel files to
 create one XML file for usage with I<SWISH-E> indexer. Dispite it's name,
 this script B<isn't general xml generator> from isis files (isis allready
 has something like that). Output of this script is tailor-made for SWISH-E.