use IO::File;
use Pod::Usage;
+use Koha::SearchEngine;
+use Koha::SearchEngine::Search;
+
use open qw( :std :encoding(UTF-8) );
binmode( STDOUT, ":encoding(UTF-8)" );
my ( $input_marc_file, $number, $offset) = ('',0,0);
$insert ||= !$update;
my $writemode = ($append) ? "a" : "w";
+pod2usage( -msg => "\nYou must specify either --biblios or --authorities, not both.\n", -exitval ) if $biblios && $authorities;
+
if ($all) {
$insert = 1;
$update = 1;
$sourcesubfield="a";
}
-#Disable the syspref cache or else the following UPDATE statements will have no effect
-C4::Context->disable_syspref_cache();
-# save the CataloguingLog and AuthoritiesLog properties : we don't want to log a bulkmarcimport. It will slow the import &
-# will create problems in the action_logs table, that can't handle more than 1 entry per second per user.
-my $CataloguingLog = C4::Context->preference('CataloguingLog');
-$dbh->do("UPDATE systempreferences SET value=0 WHERE variable='CataloguingLog'");
+# Disable logging for the biblios and authorities import operation. It would unnecessarily
+# slow the import
-my $AuthoritiesLog = C4::Context->preference('AuthoritiesLog');
-$dbh->do("UPDATE systempreferences SET value=0 WHERE variable='AuthoritiesLog'");
+# Disable the syspref cache so we can change logging settings
+C4::Context->disable_syspref_cache();
+# Save current CataloguingLog and AuthoritiesLog sysprefs values
+my $CataloguingLog = C4::Context->preference( 'CataloguingLog' );
+my $AuthoritiesLog = C4::Context->preference( 'AuthoritiesLog' );
+# Disable logging for both
+C4::Context->set_preference( 'CataloguingLog', 0 );
+C4::Context->set_preference( 'AuthoritiesLog', 0 );
if ($fk_off) {
$dbh->do("SET FOREIGN_KEY_CHECKS = 0");
$loghandle= IO::File->new($logfile, $writemode) ;
print $loghandle "id;operation;status\n";
}
+
+my $searcher = Koha::SearchEngine::Search->new(
+ {
+ index => (
+ $authorities
+ ? $Koha::SearchEngine::AUTHORITIES_INDEX
+ : $Koha::SearchEngine::BIBLIOS_INDEX
+ )
+ }
+);
+
RECORD: while ( ) {
my $record;
# get records
my $query = build_query( $match, $record );
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' );
$debug && warn $query;
- my ( $error, $results, $totalhits ) = C4::Search::SimpleSearch( $query, 0, 3, [$server] );
- die "unable to search the database for duplicates : $error" if ( defined $error );
+ my ( $error, $results, $totalhits ) = $searcher->simple_search_compat( $query, 0, 3, [$server] );
+ # changed to warn so able to continue with one broken record
+ if ( defined $error ) {
+ warn "unable to search the database for duplicates : $error";
+ printlog( { id => $id || $originalid || $match, op => "match", status => "ERROR" } ) if ($logfile);
+ next RECORD;
+ }
$debug && warn "$query $server : $totalhits";
if ( $results && scalar(@$results) == 1 ) {
my $marcrecord = C4::Search::new_record_from_zebra( $server, $results->[0] );
if ($biblionumber) {
eval{$biblioitemnumber=GetBiblioData($biblionumber)->{biblioitemnumber};};
if ($update) {
- eval { ( $biblionumber, $biblioitemnumber ) = ModBiblio( $record, $biblionumber, GetFrameworkcode($biblionumber) ) };
+ eval { ( $biblionumber, $biblioitemnumber ) = ModBiblio( $record, $biblionumber, GetFrameworkCode($biblionumber) ) };
if ($@) {
warn "ERROR: Edit biblio $biblionumber failed: $@\n";
printlog( { id => $id || $originalid || $biblionumber, op => "update", status => "ERROR" } ) if ($logfile);
$dbh->do("SET FOREIGN_KEY_CHECKS = 1");
}
-# restore CataloguingLog
-$dbh->do("UPDATE systempreferences SET value=$CataloguingLog WHERE variable='CataloguingLog'");
-# restore AuthoritiesLog
-$dbh->do("UPDATE systempreferences SET value=$AuthoritiesLog WHERE variable='AuthoritiesLog'");
+# Restore CataloguingLog
+C4::Context->set_preference( 'CataloguingLog', $CataloguingLog );
+# Restore AuthoritiesLog
+C4::Context->set_preference( 'AuthoritiesLog', $AuthoritiesLog );
my $timeneeded = gettimeofday - $starttime;
print "\n$i MARC records done in $timeneeded seconds\n";
=item B<-t, -test>
-Test mode: parses the file, saying what he would do, but doing nothing.
+Test mode: parses the file, saying what it would do, but doing nothing.
=item B<-s>
=item B<-k, -keepids>=<FIELD>
-Field store ids in I<FIELD> (usefull for authorities, where 001 contains the
+Field store ids in I<FIELD> (useful for authorities, where 001 contains the
authid for Koha, that can contain a very valuable info for authorities coming
from LOC or BNF. useless for biblios probably)
=item B<-keepids>
-Store ids in 009 (usefull for authorities, where 001 contains the authid for
+Store ids in 009 (useful for authorities, where 001 contains the authid for
Koha, that can contain a very valuable info for authorities coming from LOC or
BNF. useless for biblios probably)