my $db_handle;
my $log_mod = 500; # log every 500th of each type of event (see verbose)
-my $file;
+my $marc_file;
+my $zip_file;
my $export_date;
my $working_dir = '.',
my $bib_collision_file;
my $help;
GetOptions(
- 'file=s' => \$file,
+ 'marc-file=s' => \$marc_file,
+ 'zip-file=s' => \$zip_file,
'export-date=s' => \$export_date,
'working-dir=s' => \$working_dir,
'bib-collision-file=s' => \$bib_collision_file,
avoid losing change made by staff since the export.
--file
- Full path to ZIP file to process.
+ Full path to a single bib or authority MARC file.
+
+ --zip-file
+ Full path to a ZIP file containing multiple authority and bib
+ MARC files to process.
--working-dir
Directory where constituent files are extracted.
die "required: --export-date YYYY-MM-DD\n" unless
$export_date && $export_date =~ /^\d{4}-\d{2}-\d{2}$/;
-die "--file required\n" unless $file;
+die "--marc-file or --zip-file required\n" unless ($marc_file || $zip_file);
# Log every occurrence of each event type.
$log_mod = 1 if $verbose;
my $zip = Archive::Zip->new();
- announce('ERR', "Failed to read $file", 1)
- unless $zip->read($file) == AZ_OK;
+ announce('ERR', "Failed to read $zip_file", 1)
+ unless $zip->read($zip_file) == AZ_OK;
# Avoid processing XLS and HTM files.
# All of the MARC files end in .UTF8.
announce('ERR', "Unable to extract to file: $local_file", 1)
unless $member->extractToFileNamed($local_file) == AZ_OK;
- my $marc_batch = MARC::File::USMARC->in($local_file, 'UTF8')
- or announce('ERR', "Unable to read $local_file as MARC", 1);
+ process_marc_file($local_file);
+ }
+}
- if ($basename =~ /BIB/) {
+sub process_marc_file {
+ my $local_file = shift;
+ my $basename = basename($local_file);
- handle_modified_bibs($marc_batch);
+ my $marc_batch = MARC::File::USMARC->in($local_file, 'UTF8')
+ or announce('ERR', "Unable to read $local_file as MARC", 1);
- } elsif ($basename =~ /DEL/) {
+ if ($basename =~ /BIB/) {
- handle_deleted_auths($marc_batch);
+ handle_modified_bibs($marc_batch);
- } elsif ($basename =~ /CHG|NEW|AUTH/) {
+ } elsif ($basename =~ /DEL/) {
- handle_modified_auths($marc_batch);
+ handle_deleted_auths($marc_batch);
- } else {
- announce('WARNING', "Un-handled file type: $basename");
- }
+ } elsif ($basename =~ /CHG|NEW|AUTH/) {
+
+ handle_modified_auths($marc_batch);
+
+ } else {
+
+ announce('WARNING', "Unknown file type: $basename");
}
}
openlog($syslog_ident, $syslog_ops, $syslog_facility);
connect_db();
prepare_statements();
-process_zip_file();
+process_zip_file() if $zip_file;
+process_marc_file($marc_file) if $marc_file;
$new_auth_sth->finish;
$mod_auth_sth->finish;