Koha/misc/batchImportMARCWithBiblionumbers.pl
Jonathan Druart 238fabc4ab Bug 28617: Remove kohalib.pl and rely on PERL5LIB
The purpose of this script was to load the relevant Koha lib for the
different scripts (installation, cronjob, CLI, etc.)
However it is not used consistently and we prefer to rely on PERL5LIB.

From bug 28617 comment 6 from Galen:
"""
Time marches on, and one of the motivations for having kohalib.pl - making
it possible to install Koha without setting a single environment variable -
has been obviated by the vast improvements in the ease of installing Koha.

Consequently, I think kohalib.pl can go away.
"""

Test plan:
confirm that the changes make sense and that kohalib.pl can be removed
safely.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
2021-12-07 12:16:28 -10:00

91 lines
2.4 KiB
Perl
Executable file

#!/usr/bin/perl
# load records that already have biblionumber set into a koha system
# Written by TG on 10/04/2006
use strict;
#use warnings; FIXME - Bug 2505
# Koha modules used
use Koha::Script;
use C4::Context;
use C4::Biblio qw( GetMarcFromKohaField );
use MARC::File::USMARC;
use MARC::File::XML;
use MARC::Batch;
use Time::HiRes qw( gettimeofday );
use Getopt::Long qw( GetOptions );
use IO::File;
my $input_marc_file = '';
my ($version);
GetOptions(
'file:s' => \$input_marc_file,
'h' => \$version,
);
if ($version || ($input_marc_file eq '')) {
print <<EOF
If your ISO2709 file already has biblionumbers, you can use this script
to import the MARC into your database.
parameters :
\th : this version/help screen
\tfile /path/to/file/to/dump : the file to dump
SAMPLE :
\t\$ export KOHA_CONF=/etc/koha.conf
\t\$ perl misc/marcimport_to_biblioitems.pl -file /home/jmf/koha.mrc
EOF
;#'
die;
}
my $starttime = gettimeofday;
my $timeneeded;
my $dbh = C4::Context->dbh;
my $sth2=$dbh->prepare("update biblioitems set marc=? where biblionumber=?");
my $fh = IO::File->new($input_marc_file); # don't let MARC::Batch open the file, as it applies the ':utf8' IO layer
my $batch = MARC::Batch->new( 'USMARC', $fh );
$batch->warnings_off();
$batch->strict_off();
my ($tagfield,$biblionumtagsubfield) = &GetMarcFromKohaField( "biblio.biblionumber" );
my $i=0;
while ( my $record = $batch->next() ) {
my $biblionumber = ($tagfield < 10) ? $record->field($tagfield)->data : $record->subfield($tagfield, $biblionumtagsubfield);
$i++;
$sth2->execute($record->as_usmarc,$biblionumber) if $biblionumber;
print "$biblionumber \n";
}
$timeneeded = gettimeofday - $starttime ;
print "$i records in $timeneeded s\n" ;
END;
# IS THIS SUPPOSED TO BE __END__ ?? If not, then what is it? --JBA
sub search {
my ($query)=@_;
my $nquery="\ \@attr 1=1007 ".$query;
my $oAuth=C4::Context->Zconn("biblioserver");
if ($oAuth eq "error"){
warn "Error/CONNECTING \n";
return("error",undef);
}
my $oAResult;
my $Anewq= ZOOM::Query::PQF->new($nquery);
eval {
$oAResult= $oAuth->search_pqf($nquery) ;
};
if($@){
warn " /Cannot search:", $@->code()," /MSG:",$@->message(),"\n";
return("error",undef);
}
my $authrecord;
my $nbresults="0";
$nbresults=$oAResult->size();
if ($nbresults eq "1" ){
my $rec=$oAResult->record(0);
my $marcdata=$rec->raw();
$authrecord = MARC::File::USMARC::decode($marcdata);
}
return ($authrecord,$nbresults);
}