Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 98 lines (88 sloc) 2.508 kB
a0b06fb @ctfliblime Prepare for perlbrew usage by changing all script magic to "#!/usr/bi…
ctfliblime authored
1 #!/usr/bin/env perl
dd3f557 fixing nomenclature on files in misc/, adding a few new utilities
Joshua Ferraro authored
2 # load records that already have biblionumber set into a koha system
3 # Written by TG on 10/04/2006
d5acfe9 update to virtual shelves -- approved
Joshua Ferraro authored
4 use strict;
b8a58c4 installer: command-line scripts improve finding C4 modules
Galen Charlton authored
5 BEGIN {
6 # find Koha's Perl modules
7 # test carefully before changing this
8 use FindBin;
9 eval { require "$FindBin::Bin/kohalib.pl" };
10 }
d5acfe9 update to virtual shelves -- approved
Joshua Ferraro authored
11
12 # Koha modules used
13
3607caa @ctfliblime Add Koha.pm and include it universally
ctfliblime authored
14 use Koha;
d5acfe9 update to virtual shelves -- approved
Joshua Ferraro authored
15 use C4::Context;
16 use C4::Biblio;
17 use MARC::Record;
18 use MARC::File::USMARC;
19 use MARC::File::XML;
20 use MARC::Batch;
21 use Time::HiRes qw(gettimeofday);
22 use Getopt::Long;
b4f39e5 do not let MARC::Batch open MARC files
Galen Charlton authored
23 use IO::File;
24
d5acfe9 update to virtual shelves -- approved
Joshua Ferraro authored
25 my $input_marc_file = '';
26 my ($version);
27 GetOptions(
28 'file:s' => \$input_marc_file,
29 'h' => \$version,
30 );
31
32 if ($version || ($input_marc_file eq '')) {
33 print <<EOF
dd3f557 fixing nomenclature on files in misc/, adding a few new utilities
Joshua Ferraro authored
34 If your ISO2709 file already has biblionumbers, you can use this script
35 to import the MARC into your database.
d5acfe9 update to virtual shelves -- approved
Joshua Ferraro authored
36 parameters :
37 \th : this version/help screen
38 \tfile /path/to/file/to/dump : the file to dump
39 SAMPLE :
40 \t\$ export KOHA_CONF=/etc/koha.conf
41 \t\$ perl misc/marcimport_to_biblioitems.pl -file /home/jmf/koha.mrc
42 EOF
43 ;#'
28159f0 misc subdir - Dates.pm integration and warnings fixes.
Joe Atzberger authored
44 die;
d5acfe9 update to virtual shelves -- approved
Joshua Ferraro authored
45 }
46 my $starttime = gettimeofday;
47 my $timeneeded;
48 my $dbh = C4::Context->dbh;
49
50 my $sth2=$dbh->prepare("update biblioitems set marc=? where biblionumber=?");
b4f39e5 do not let MARC::Batch open MARC files
Galen Charlton authored
51 my $fh = IO::File->new($input_marc_file); # don't let MARC::Batch open the file, as it applies the ':utf8' IO layer
52 my $batch = MARC::Batch->new( 'USMARC', $fh );
d5acfe9 update to virtual shelves -- approved
Joshua Ferraro authored
53 $batch->warnings_off();
54 $batch->strict_off();
55 my ($tagfield,$biblionumtagsubfield) = &GetMarcFromKohaField("biblio.biblionumber","");
56
28159f0 misc subdir - Dates.pm integration and warnings fixes.
Joe Atzberger authored
57 my $i=0;
d5acfe9 update to virtual shelves -- approved
Joshua Ferraro authored
58 while ( my $record = $batch->next() ) {
28159f0 misc subdir - Dates.pm integration and warnings fixes.
Joe Atzberger authored
59 my $biblionumber=$record->field($tagfield)->subfield($biblionumtagsubfield);
60 $i++;
61 $sth2->execute($record->as_usmarc,$biblionumber) if $biblionumber;
62 print "$biblionumber \n";
d5acfe9 update to virtual shelves -- approved
Joshua Ferraro authored
63 }
64
65 $timeneeded = gettimeofday - $starttime ;
28159f0 misc subdir - Dates.pm integration and warnings fixes.
Joe Atzberger authored
66 print "$i records in $timeneeded s\n" ;
d5acfe9 update to virtual shelves -- approved
Joshua Ferraro authored
67
68 END;
28159f0 misc subdir - Dates.pm integration and warnings fixes.
Joe Atzberger authored
69 # IS THIS SUPPOSED TO BE __END__ ?? If not, then what is it? --JBA
70
71 sub search {
72 my ($query)=@_;
73 my $nquery="\ \@attr 1=1007 ".$query;
74 my $oAuth=C4::Context->Zconn("biblioserver");
75 if ($oAuth eq "error"){
76 warn "Error/CONNECTING \n";
77 return("error",undef);
78 }
79 my $oAResult;
80 my $Anewq= new ZOOM::Query::PQF($nquery);
81 eval {
82 $oAResult= $oAuth->search_pqf($nquery) ;
83 };
84 if($@){
85 warn " /Cannot search:", $@->code()," /MSG:",$@->message(),"\n";
86 return("error",undef);
87 }
88 my $authrecord;
89 my $nbresults="0";
90 $nbresults=$oAResult->size();
91 if ($nbresults eq "1" ){
92 my $rec=$oAResult->record(0);
93 my $marcdata=$rec->raw();
d147d3e @pjones9 DE265: incomplete support for marcxml
pjones9 authored
94 $authrecord = MARC::File::XML::decode($marcdata);
28159f0 misc subdir - Dates.pm integration and warnings fixes.
Joe Atzberger authored
95 }
96 return ($authrecord,$nbresults);
d5acfe9 update to virtual shelves -- approved
Joshua Ferraro authored
97 }
Something went wrong with that request. Please try again.