Lines 35-41
BEGIN {
Link Here
|
35 |
$VERSION = 3.07.00.049; |
35 |
$VERSION = 3.07.00.049; |
36 |
require Exporter; |
36 |
require Exporter; |
37 |
@ISA = qw(Exporter); |
37 |
@ISA = qw(Exporter); |
38 |
@EXPORT = qw(&ImportBreeding &BreedingSearch &Z3950Search &Z3950SearchAuth); |
38 |
@EXPORT = qw(&BreedingSearch &Z3950Search &Z3950SearchAuth); |
39 |
} |
39 |
} |
40 |
|
40 |
|
41 |
=head1 NAME |
41 |
=head1 NAME |
Lines 45-158
C4::Breeding : module to add biblios to import_records via
Link Here
|
45 |
|
45 |
|
46 |
=head1 SYNOPSIS |
46 |
=head1 SYNOPSIS |
47 |
|
47 |
|
48 |
use C4::Scan; |
48 |
Z3950Search($pars, $template); |
49 |
&ImportBreeding($marcrecords,$overwrite_biblio,$filename,$z3950random,$batch_type); |
49 |
($count, @results) = &BreedingSearch($title,$isbn,$random); |
50 |
|
|
|
51 |
C<$marcrecord> => the MARC::Record |
52 |
C<$overwrite_biblio> => if set to 1 a biblio with the same ISBN will be overwritted. |
53 |
if set to 0 a biblio with the same isbn will be ignored (the previous will be kept) |
54 |
if set to -1 the biblio will be added anyway (more than 1 biblio with the same ISBN |
55 |
possible in the breeding |
56 |
C<$encoding> => USMARC |
57 |
or UNIMARC. used for char_decoding. |
58 |
If not present, the parameter marcflavour is used instead |
59 |
C<$z3950random> => the random value created during a z3950 search result. |
60 |
|
50 |
|
61 |
=head1 DESCRIPTION |
51 |
=head1 DESCRIPTION |
62 |
|
52 |
|
63 |
ImportBreeding import MARC records in the reservoir (import_records/import_batches tables). |
53 |
This module contains routines related to Koha's Z39.50 search into |
64 |
the records can be properly encoded or not, we try to reencode them in utf-8 if needed. |
54 |
cataloguing reservoir features. |
65 |
works perfectly with BNF server, that sends UNIMARC latin1 records. Should work with other servers too. |
|
|
66 |
|
67 |
=head2 ImportBreeding |
68 |
|
69 |
ImportBreeding($marcrecords,$overwrite_biblio,$filename,$encoding,$z3950random,$batch_type); |
70 |
|
71 |
TODO description |
72 |
|
73 |
=cut |
74 |
|
75 |
sub ImportBreeding { |
76 |
my ($marcrecords,$overwrite_biblio,$filename,$encoding,$z3950random,$batch_type) = @_; |
77 |
my @marcarray = split /\x1D/, $marcrecords; |
78 |
|
79 |
my $dbh = C4::Context->dbh; |
80 |
|
81 |
my $batch_id = GetZ3950BatchId($filename); |
82 |
my $searchisbn = $dbh->prepare("select biblioitemnumber from biblioitems where isbn=?"); |
83 |
my $searchissn = $dbh->prepare("select biblioitemnumber from biblioitems where issn=?"); |
84 |
# FIXME -- not sure that this kind of checking is actually needed |
85 |
my $searchbreeding = $dbh->prepare("select import_record_id from import_biblios where isbn=? and title=?"); |
86 |
|
87 |
# $encoding = C4::Context->preference("marcflavour") unless $encoding; |
88 |
# fields used for import results |
89 |
my $imported=0; |
90 |
my $alreadyindb = 0; |
91 |
my $alreadyinfarm = 0; |
92 |
my $notmarcrecord = 0; |
93 |
my $breedingid; |
94 |
for (my $i=0;$i<=$#marcarray;$i++) { |
95 |
my ($marcrecord, $charset_result, $charset_errors); |
96 |
($marcrecord, $charset_result, $charset_errors) = |
97 |
MarcToUTF8Record($marcarray[$i]."\x1D", C4::Context->preference("marcflavour"), $encoding); |
98 |
|
99 |
# Normalize the record so it doesn't have separated diacritics |
100 |
SetUTF8Flag($marcrecord); |
101 |
|
102 |
# warn "$i : $marcarray[$i]"; |
103 |
# FIXME - currently this does nothing |
104 |
my @warnings = $marcrecord->warnings(); |
105 |
|
106 |
if (scalar($marcrecord->fields()) == 0) { |
107 |
$notmarcrecord++; |
108 |
} else { |
109 |
my $oldbiblio = TransformMarcToKoha($dbh,$marcrecord,''); |
110 |
# if isbn found and biblio does not exist, add it. If isbn found and biblio exists, |
111 |
# overwrite or ignore depending on user choice |
112 |
# drop every "special" char : spaces, - ... |
113 |
$oldbiblio->{isbn} = C4::Koha::GetNormalizedISBN($oldbiblio->{isbn}); |
114 |
# search if biblio exists |
115 |
my $biblioitemnumber; |
116 |
if ($oldbiblio->{isbn}) { |
117 |
$searchisbn->execute($oldbiblio->{isbn}); |
118 |
($biblioitemnumber) = $searchisbn->fetchrow; |
119 |
} else { |
120 |
if ($oldbiblio->{issn}) { |
121 |
$searchissn->execute($oldbiblio->{issn}); |
122 |
($biblioitemnumber) = $searchissn->fetchrow; |
123 |
} |
124 |
} |
125 |
if ($biblioitemnumber && $overwrite_biblio ne 2) { |
126 |
$alreadyindb++; |
127 |
} else { |
128 |
# FIXME - in context of batch load, |
129 |
# rejecting records because already present in the reservoir |
130 |
# not correct in every case. |
131 |
# search in breeding farm |
132 |
if ($oldbiblio->{isbn}) { |
133 |
$searchbreeding->execute($oldbiblio->{isbn},$oldbiblio->{title}); |
134 |
($breedingid) = $searchbreeding->fetchrow; |
135 |
} elsif ($oldbiblio->{issn}){ |
136 |
$searchbreeding->execute($oldbiblio->{issn},$oldbiblio->{title}); |
137 |
($breedingid) = $searchbreeding->fetchrow; |
138 |
} |
139 |
if ($breedingid && $overwrite_biblio eq '0') { |
140 |
$alreadyinfarm++; |
141 |
} else { |
142 |
if ($breedingid && $overwrite_biblio eq '1') { |
143 |
ModBiblioInBatch($breedingid, $marcrecord); |
144 |
} else { |
145 |
my $import_id = AddBiblioToBatch($batch_id, $imported, $marcrecord, $encoding, $z3950random); |
146 |
$breedingid = $import_id; |
147 |
} |
148 |
$imported++; |
149 |
} |
150 |
} |
151 |
} |
152 |
} |
153 |
return ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported,$breedingid); |
154 |
} |
155 |
|
156 |
|
55 |
|
157 |
=head2 BreedingSearch |
56 |
=head2 BreedingSearch |
158 |
|
57 |
|
Lines 408-414
sub _handle_one_result {
Link Here
|
408 |
my ($marcrecord) = MarcToUTF8Record($raw, C4::Context->preference('marcflavour'), $servhref->{encd}); #ignores charset return values |
307 |
my ($marcrecord) = MarcToUTF8Record($raw, C4::Context->preference('marcflavour'), $servhref->{encd}); #ignores charset return values |
409 |
SetUTF8Flag($marcrecord); |
308 |
SetUTF8Flag($marcrecord); |
410 |
|
309 |
|
411 |
#call to ImportBreeding replaced by next two calls for optimization |
|
|
412 |
my $batch_id = GetZ3950BatchId($servhref->{name}); |
310 |
my $batch_id = GetZ3950BatchId($servhref->{name}); |
413 |
my $breedingid = AddBiblioToBatch($batch_id, $seq, $marcrecord, 'UTF-8', 0, 0); |
311 |
my $breedingid = AddBiblioToBatch($batch_id, $seq, $marcrecord, 'UTF-8', 0, 0); |
414 |
#FIXME passing 0 for z3950random |
312 |
#FIXME passing 0 for z3950random |
415 |
- |
|
|