Removed ASMP custom frameworks from standard default MARC 21 framework.
[koha.git] / misc / marcimport_to_biblioitems.pl
1 #!/usr/bin/perl
2 # script that correct the marcxml  from in biblioitems 
3 #  Written by TG on 10/04/2006
4 use strict;
5
6 # Koha modules used
7
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,
21 );
22
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;
35 }
36 my $starttime = gettimeofday;
37 my $timeneeded;
38 my $dbh = C4::Context->dbh;
39
40 my $sth2=$dbh->prepare("update biblioitems  set marc=? where biblionumber=?");
41 my $i=0;
42
43 my $batch = MARC::Batch->new( 'USMARC', $input_marc_file );
44 $batch->warnings_off();
45 $batch->strict_off();
46 my $i=0;
47 my ($tagfield,$biblionumtagsubfield) = &MARCfind_marc_from_kohafield($dbh,"biblio.biblionumber","");
48
49 while ( my $record = $batch->next() ) {
50 my $biblionumber=$record->field($tagfield)->subfield($biblionumtagsubfield);
51 $i++;
52 $sth2->execute($record->as_usmarc,$biblionumber) if $biblionumber;
53 print "$biblionumber \n";
54 }
55
56 $timeneeded = gettimeofday - $starttime ;
57         print "$i records in $timeneeded s\n" ;
58
59 END;
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);
67 }
68 my $oAResult;
69 my $Anewq= new ZOOM::Query::PQF($nquery);
70 eval {
71 $oAResult= $oAuth->search_pqf($nquery) ; 
72 };
73 if($@){
74 warn " /Cannot search:", $@->code()," /MSG:",$@->message(),"\n";
75   return("error",undef);
76 }
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);
84 }
85 return ($authrecord,$nbresults);
86 }