use Modern::Perl;
+use Koha::Script;
use C4::Context;
-use Getopt::Long;
-use Fcntl qw(:flock);
-use File::Temp qw/ tempdir /;
-use File::Path;
-use C4::Biblio;
+use Getopt::Long qw( GetOptions );
+use Fcntl qw( LOCK_EX LOCK_NB LOCK_UN );
+use File::Temp qw( tempdir );
+use File::Path qw( mkpath rmtree );
+use C4::Biblio qw( GetXmlBiblio );
use C4::AuthoritiesMarc;
-use C4::Items;
+use C4::Items qw( GetItemsInfo Item2Marc );
use Koha::RecordProcessor;
use Koha::Caches;
use XML::LibXML;
my $wait_for_lock = 0;
my $use_flock;
my $table = 'biblioitems';
-my $is_memcached = Koha::Caches->get_instance('syspref')->memcached_cache;
+my $is_memcached = Koha::Caches->get_instance->memcached_cache;
my $verbose_logging = 0;
my $zebraidx_log_opt = " -v none,fatal,warn ";
die $msg;
}
-our @tables_allowed_for_select = ( 'biblioitems', 'items', 'biblio' );
-unless ( grep { /^$table$/ } @tables_allowed_for_select ) {
+our @tables_allowed_for_select = ( 'biblioitems', 'items', 'biblio', 'biblio_metadata' );
+unless ( grep { $_ eq $table } @tables_allowed_for_select ) {
die "Cannot specify -t|--table with value '$table'. Only "
. ( join ', ', @tables_allowed_for_select )
. " are allowed.";
my $authorityserverdir = C4::Context->zebraconfig('authorityserver')->{directory};
my $kohadir = C4::Context->config('intranetdir');
-my $bib_index_mode = C4::Context->config('zebra_bib_index_mode') // 'dom';
-my $auth_index_mode = C4::Context->config('zebra_auth_index_mode') // 'dom';
-my ($biblionumbertagfield,$biblionumbertagsubfield) = &GetMarcFromKohaField("biblio.biblionumber","");
-my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaField("biblioitems.biblioitemnumber","");
+my ($biblionumbertagfield,$biblionumbertagsubfield) = C4::Biblio::GetMarcFromKohaField( "biblio.biblionumber" );
+my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = C4::Biblio::GetMarcFromKohaField( "biblioitems.biblioitemnumber" );
my $marcxml_open = q{<?xml version="1.0" encoding="UTF-8"?>
<collection xmlns="http://www.loc.gov/MARC21/slim">
# the lockfile)
};
+my $start_time = time();
if ( $verbose_logging ) {
+ my $pretty_time = POSIX::strftime("%H:%M:%S",localtime($start_time));
print "Zebra configuration information\n";
print "================================\n";
print "Zebra biblio directory = $biblioserverdir\n";
print "BIBLIONUMBER in : $biblionumbertagfield\$$biblionumbertagsubfield\n";
print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n";
print "================================\n";
+ print "Job started: $pretty_time\n";
}
my $tester = XML::LibXML->new();
if ( $verbose_logging ) {
print "====================\n";
+ print "Indexing complete: ". pretty_time() . "\n";
+ print "====================\n";
print "CLEANING\n";
print "====================\n";
}
print "parameter";
}
print "\n";
- print "if you just want to rebuild zebra after changing the record.abs\n";
- print "or another zebra config file\n";
+ print "if you just want to rebuild zebra after changing zebra config files\n";
} else {
unless ($use_tempdir) {
# if we're using a temporary directory
} else {
if ( $verbose_logging ) {
print "====================\n";
- print "exporting $record_type\n";
+ print "exporting $record_type " . pretty_time() . "\n";
print "====================\n";
}
mkdir "$directory" unless (-d $directory);
} else {
if ( $verbose_logging ) {
print "====================\n";
- print "REINDEXING zebra\n";
+ print "REINDEXING zebra " . pretty_time() . "\n";
print "====================\n";
}
my $record_fmt = 'marcxml';
sub select_all_biblios {
$table = 'biblioitems'
- unless grep { /^$table$/ } @tables_allowed_for_select;
- my $strsth = qq{ SELECT biblionumber FROM $table };
+ unless grep { $_ eq $table } @tables_allowed_for_select;
+ my $strsth = qq{ SELECT DISTINCT biblionumber FROM $table };
$strsth.=qq{ WHERE $where } if ($where);
$strsth.=qq{ LIMIT $length } if ($length && !$offset);
$strsth.=qq{ LIMIT $offset,$length } if ($offset);
print {$fh} $marcxml_open;
my $i = 0;
- my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField("items.itemnumber",'');
+ my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
while (my ($record_number) = $sth->fetchrow_array) {
print "." if ( $verbose_logging );
print "\r$i" unless ($i++ %100 or !$verbose_logging);
}
}
}
- print "\nRecords exported: $num_exported\n" if ( $verbose_logging );
+ print "\nRecords exported: $num_exported " . pretty_time() . "\n" if ( $verbose_logging );
print {$fh} $marcxml_close;
close $fh;
}
}
}
- print "\nRecords exported: $num_exported\n" if ( $verbose_logging );
+ print "\nRecords exported: $num_exported " . pretty_time() . "\n" if ( $verbose_logging );
print {$fh} $marcxml_close;
$records_deleted->{$record_number} = 1;
}
- print "\nRecords exported: $i\n" if ( $verbose_logging );
+ print "\nRecords exported: $i " . pretty_time() . "\n" if ( $verbose_logging );
print {$fh} $marcxml_close;
my @filters;
push @filters, 'EmbedItemsAvailability';
- push @filters, 'IncludeSeeFromInSearches'
+ push @filters, 'EmbedSeeFromHeadings'
if C4::Context->preference('IncludeSeeFromInSearches');
my $normalizer = Koha::RecordProcessor->new( { filters => \@filters } );
my $marc;
if ($record_type eq 'biblio') {
- eval { $marc = GetMarcBiblio($record_number, 1); };
+ eval { $marc = C4::Biblio::GetMarcBiblio({ biblionumber => $record_number, embed_items => 1 }); };
if ($@ || !$marc) {
# here we do warn since catching an exception
# means that the bib was found but failed
return ( $fh, $dir.'/'.LOCK_FILENAME );
}
+sub pretty_time {
+ use integer;
+ my $now = time;
+ my $elapsed = $now - $start_time;
+ local $_ = $elapsed;
+ my ( $h, $m, $s );
+ $s = $_ % 60;
+ $_ /= 60;
+ $m = $_ % 60;
+ $_ /= 60;
+ $h = $_ % 24;
+
+ my $now_pretty = POSIX::strftime("%H:%M:%S",localtime($now));
+ my $elapsed_pretty = sprintf "[%02d:%02d:%02d]",$h,$m,$s;
+
+ return "$now_pretty $elapsed_pretty";
+}
+
sub print_usage {
print <<_USAGE_;
$0: reindex MARC bibs and/or authorities in Zebra.
to wait for the lock to free and then continue
processing the rebuild request,
- --table specify a table (can be items, biblioitems or biblio) to retrieve biblionumber to index.
+ --table specify a table (can be items, biblioitems, biblio, biblio_metadata) to retrieve biblionumber to index.
biblioitems is the default value.
--help or -h show this message.