cleanup in memberentry,categories.
[koha.git] / misc / marcimport_to_biblioitems.pl
blobf56f72dc3a647aba7354cfe6227845d2f3680af2
1 #!/usr/bin/perl
2 # script that correct the marcxml from in biblioitems
3 # Written by TG on 10/04/2006
4 use strict;
6 # Koha modules used
8 use C4::Context;
9 use C4::Biblio;
10 use MARC::Record;
11 use MARC::File::USMARC;
12 use MARC::File::XML;
13 use MARC::Batch;
14 use Time::HiRes qw(gettimeofday);
15 use Getopt::Long;
16 my $input_marc_file = '';
17 my ($version);
18 GetOptions(
19 'file:s' => \$input_marc_file,
20 'h' => \$version,
23 if ($version || ($input_marc_file eq '')) {
24 print <<EOF
25 small script to import an iso2709 file into Koha with existing biblionumbers in marc record.
26 parameters :
27 \th : this version/help screen
28 \tfile /path/to/file/to/dump : the file to dump
29 SAMPLE :
30 \t\$ export KOHA_CONF=/etc/koha.conf
31 \t\$ perl misc/marcimport_to_biblioitems.pl -file /home/jmf/koha.mrc
32 EOF
33 ;#'
34 die;
36 my $starttime = gettimeofday;
37 my $timeneeded;
38 my $dbh = C4::Context->dbh;
40 my $sth2=$dbh->prepare("update biblioitems set marc=? where biblionumber=?");
41 my $batch = MARC::Batch->new( 'USMARC', $input_marc_file );
42 $batch->warnings_off();
43 $batch->strict_off();
44 my ($tagfield,$biblionumtagsubfield) = &GetMarcFromKohaField("biblio.biblionumber","");
46 my $i=0;
47 while ( my $record = $batch->next() ) {
48 my $biblionumber=$record->field($tagfield)->subfield($biblionumtagsubfield);
49 $i++;
50 $sth2->execute($record->as_usmarc,$biblionumber) if $biblionumber;
51 print "$biblionumber \n";
54 $timeneeded = gettimeofday - $starttime ;
55 print "$i records in $timeneeded s\n" ;
57 END;
58 # IS THIS SUPPOSED TO BE __END__ ?? If not, then what is it? --JBA
60 sub search {
61 my ($query)=@_;
62 my $nquery="\ \@attr 1=1007 ".$query;
63 my $oAuth=C4::Context->Zconn("biblioserver");
64 if ($oAuth eq "error"){
65 warn "Error/CONNECTING \n";
66 return("error",undef);
68 my $oAResult;
69 my $Anewq= new ZOOM::Query::PQF($nquery);
70 eval {
71 $oAResult= $oAuth->search_pqf($nquery) ;
73 if($@){
74 warn " /Cannot search:", $@->code()," /MSG:",$@->message(),"\n";
75 return("error",undef);
77 my $authrecord;
78 my $nbresults="0";
79 $nbresults=$oAResult->size();
80 if ($nbresults eq "1" ){
81 my $rec=$oAResult->record(0);
82 my $marcdata=$rec->raw();
83 $authrecord = MARC::File::USMARC::decode($marcdata);
85 return ($authrecord,$nbresults);