1 package C4::ImportBatch;
3 # Copyright (C) 2007 LibLime
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
28 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
30 # set the version for version checking
35 C4::ImportBatch - manage batches of imported MARC records
59 BatchFindBibDuplicates
63 GetImportBatchRangeDesc
64 GetNumberOfNonZ3950ImportBatches
69 GetImportBatchOverlayAction
70 SetImportBatchOverlayAction
71 GetImportRecordOverlayStatus
72 SetImportRecordOverlayStatus
75 GetImportRecordMatches
76 SetImportRecordMatches
79 =head2 GetZ3950BatchId
83 my $batchid = GetZ3950BatchId($z3950server);
87 Retrieves the ID of the import batch for the Z39.50
88 reservoir for the given target. If necessary,
89 creates the import batch.
94 my ($z3950server) = @_;
96 my $dbh = C4::Context->dbh;
97 my $sth = $dbh->prepare("SELECT import_batch_id FROM import_batches
98 WHERE batch_type = 'z3950'
100 $sth->execute($z3950server);
101 my $rowref = $sth->fetchrow_arrayref();
103 if (defined $rowref) {
106 my $batch_id = AddImportBatch('create_new', 'staged', 'z3950', $z3950server, '');
112 =head2 GetImportRecordMarc
116 my ($marcblob, $encoding) = GetImportRecordMarc($import_record_id);
122 sub GetImportRecordMarc {
123 my ($import_record_id) = @_;
125 my $dbh = C4::Context->dbh;
126 my $sth = $dbh->prepare("SELECT marc, encoding FROM import_records WHERE import_record_id = ?");
127 $sth->execute($import_record_id);
128 my ($marc, $encoding) = $sth->fetchrow();
134 =head2 AddImportBatch
138 my $batch_id = AddImportBatch($overlay_action, $import_status, $type, $file_name, $comments);
145 my ($overlay_action, $import_status, $type, $file_name, $comments) = @_;
147 my $dbh = C4::Context->dbh;
148 my $sth = $dbh->prepare("INSERT INTO import_batches (overlay_action, import_status, batch_type,
150 VALUES (?, ?, ?, ?, ?)");
151 $sth->execute($overlay_action, $import_status, $type, $file_name, $comments);
152 my $batch_id = $dbh->{'mysql_insertid'};
159 =head2 GetImportBatch
163 my $row = GetImportBatch($batch_id);
167 Retrieve a hashref of an import_batches row.
174 my $dbh = C4::Context->dbh;
175 my $sth = $dbh->prepare_cached("SELECT * FROM import_batches WHERE import_batch_id = ?");
176 $sth->bind_param(1, $batch_id);
178 my $result = $sth->fetchrow_hashref;
184 =head2 AddBiblioToBatch
188 my $import_record_id = AddBiblioToBatch($batch_id, $record_sequence, $marc_record, $encoding, $z3950random, $update_counts);
194 sub AddBiblioToBatch {
195 my $batch_id = shift;
196 my $record_sequence = shift;
197 my $marc_record = shift;
198 my $encoding = shift;
199 my $z3950random = shift;
200 my $update_counts = @_ ? shift : 1;
202 my $import_record_id = _create_import_record($batch_id, $record_sequence, $marc_record, 'biblio', $encoding, $z3950random);
203 _add_biblio_fields($import_record_id, $marc_record);
204 _update_batch_record_counts($batch_id) if $update_counts;
205 return $import_record_id;
208 =head2 ModBiblioInBatch
212 ModBiblioInBatch($import_record_id, $marc_record);
218 sub ModBiblioInBatch {
219 my ($import_record_id, $marc_record) = @_;
221 _update_import_record_marc($import_record_id, $marc_record);
222 _update_biblio_fields($import_record_id, $marc_record);
226 =head2 BatchStageMarcRecords
230 ($batch_id, $num_records, $num_items, @invalid_records) =
231 BatchStageMarcRecords($marc_flavor, $marc_records, $file_name,
232 $comments, $branch_code, $parse_items,
239 sub BatchStageMarcRecords {
240 my ($marc_flavor, $marc_records, $file_name, $comments, $branch_code, $parse_items, $leave_as_staging) = @_;
242 my $batch_id = AddImportBatch('create_new', 'staging', 'batch', $file_name, $comments);
243 my @invalid_records = ();
246 # FIXME - for now, we're dealing only with bibs
248 foreach my $marc_blob (split(/\x1D/, $marc_records)) {
250 my $marc_record = FixEncoding($marc_blob, "\x1D");
251 my $import_record_id;
252 if (scalar($marc_record->fields()) == 0) {
253 push @invalid_records, $marc_blob;
256 $import_record_id = AddBiblioToBatch($batch_id, $rec_num, $marc_record, $marc_flavor, int(rand(99999)), 0);
258 my @import_items_ids = AddItemsToImportBiblio($batch_id, $import_record_id, $marc_record, 0);
259 $num_items += scalar(@import_items_ids);
263 unless ($leave_as_staging) {
264 SetImportBatchStatus($batch_id, 'staged');
266 # FIXME branch_code, number of bibs, number of items
267 _update_batch_record_counts($batch_id);
268 return ($batch_id, $num_valid, $num_items, @invalid_records);
271 =head2 AddItemsToImportBiblio
275 my @import_items_ids = AddItemsToImportBiblio($batch_id, $import_record_id, $marc_record, $update_counts);
281 sub AddItemsToImportBiblio {
282 my $batch_id = shift;
283 my $import_record_id = shift;
284 my $marc_record = shift;
285 my $update_counts = @_ ? shift : 0;
287 my @import_items_ids = ();
289 my $dbh = C4::Context->dbh;
290 my ($item_tag,$item_subfield) = &GetMarcFromKohaField("items.itemnumber",'');
291 foreach my $item_field ($marc_record->field($item_tag)) {
292 my $item_marc = MARC::Record->new();
293 $item_marc->append_fields($item_field);
294 $marc_record->delete_field($item_field);
295 my $sth = $dbh->prepare_cached("INSERT INTO import_items (import_record_id, status, marcxml)
297 $sth->bind_param(1, $import_record_id);
298 $sth->bind_param(2, 'staged');
299 $sth->bind_param(3, $item_marc->as_xml());
301 push @import_items_ids, $dbh->{'mysql_insertid'};
305 if ($#import_items_ids > -1) {
306 _update_batch_record_counts($batch_id) if $update_counts;
307 _update_import_record_marc($import_record_id, $marc_record);
309 return @import_items_ids;
312 =head2 BatchFindBibDuplicates
316 my $num_with_matches = BatchFindBibDuplicates($batch_id, $matcher, $max_matches);
320 Goes through the records loaded in the batch and attempts to
321 find duplicates for each one. Sets the overlay action to
322 "replace" if it was "create_new", and sets the overlay status
323 of each record to "no_match" or "auto_match" as appropriate.
325 The $max_matches parameter is optional; if it is not supplied,
330 sub BatchFindBibDuplicates {
331 my $batch_id = shift;
333 my $max_matches = @_ ? shift : 10;
335 my $dbh = C4::Context->dbh;
336 my $old_overlay_action = GetImportBatchOverlayAction($batch_id);
337 if ($old_overlay_action eq "create_new") {
338 SetImportBatchOverlayAction($batch_id, 'replace');
341 my $sth = $dbh->prepare("SELECT import_record_id, marc
343 JOIN import_biblios USING (import_record_id)
344 WHERE import_batch_id = ?");
345 $sth->execute($batch_id);
346 my $num_with_matches = 0;
347 while (my $rowref = $sth->fetchrow_hashref) {
348 my $marc_record = MARC::Record->new_from_usmarc($rowref->{'marc'});
349 my @matches = $matcher->get_matches($marc_record, $max_matches);
350 if (scalar(@matches) > 0) {
352 SetImportRecordMatches($rowref->{'import_record_id'}, @matches);
353 SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'auto_match');
355 SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'no_match');
359 return $num_with_matches;
362 =head2 BatchCommitBibRecords
366 my ($num_added, $num_updated, $num_items_added, $num_ignored) = BatchCommitBibRecords($batch_id);
372 sub BatchCommitBibRecords {
373 my $batch_id = shift;
377 my $num_items_added = 0;
379 # commit (i.e., save, all records in the batch)
380 # FIXME biblio only at the moment
381 SetImportBatchStatus('importing');
382 my $overlay_action = GetImportBatchOverlayAction($batch_id);
383 my $dbh = C4::Context->dbh;
384 my $sth = $dbh->prepare("SELECT import_record_id, status, overlay_status, marc
386 JOIN import_biblios USING (import_record_id)
387 WHERE import_batch_id = ?");
388 $sth->execute($batch_id);
389 while (my $rowref = $sth->fetchrow_hashref) {
390 if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'imported') {
393 my $marc_record = MARC::Record->new_from_usmarc($rowref->{'marc'});
394 if ($overlay_action eq 'create_new' or
395 ($overlay_action eq 'replace' and $rowref->{'overlay_status'} eq 'no_match')) {
397 my ($biblionumber, $biblioitemnumber) = AddBiblio($marc_record, '');
398 my $sth = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?");
399 $sth->execute($biblionumber, $rowref->{'import_record_id'});
401 $num_items_added += BatchCommitItems($rowref->{'import_record_id'}, $biblionumber);
402 SetImportRecordStatus($rowref->{'import_record_id'}, 'imported');
405 my $biblionumber = GetBestRecordMatch($rowref->{'import_record_id'});
406 my ($count, $oldbiblio) = GetBiblio($biblionumber);
407 my $oldxml = GetXmlBiblio($biblionumber);
408 ModBiblio($marc_record, $biblionumber, $oldbiblio->{'frameworkcode'});
409 my $sth = $dbh->prepare_cached("UPDATE import_records SET marcxml_old = ? WHERE import_record_id = ?");
410 $sth->execute($oldxml, $rowref->{'import_record_id'});
412 my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?");
413 $sth2->execute($biblionumber, $rowref->{'import_record_id'});
415 $num_items_added += BatchCommitItems($rowref->{'import_record_id'}, $biblionumber);
416 SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied');
417 SetImportRecordStatus($rowref->{'import_record_id'}, 'imported');
421 SetImportBatchStatus($batch_id, 'imported');
422 return ($num_added, $num_updated, $num_items_added, $num_ignored);
425 =head2 BatchCommitItems
429 $num_items_added = BatchCommitItems($import_record_id, $biblionumber);
435 sub BatchCommitItems {
436 my ($import_record_id, $biblionumber) = @_;
438 my $dbh = C4::Context->dbh;
440 my $num_items_added = 0;
441 my $sth = $dbh->prepare("SELECT import_items_id, import_items.marcxml, encoding
443 JOIN import_records USING (import_record_id)
444 WHERE import_record_id = ?
445 ORDER BY import_items_id");
446 $sth->bind_param(1, $import_record_id);
448 while (my $row = $sth->fetchrow_hashref()) {
449 my $item_marc = MARC::Record->new_from_xml($row->{'marcxml'}, 'UTF-8', $row->{'encoding'});
450 my ($item_biblionumber, $biblionumber, $itemnumber) = AddItem($item_marc, $biblionumber);
451 my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
452 $updsth->bind_param(1, 'imported');
453 $updsth->bind_param(2, $itemnumber);
454 $updsth->bind_param(3, $row->{'import_items_id'});
460 return $num_items_added;
463 =head2 BatchRevertBibRecords
467 my ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored) = BatchRevertBibRecords($batch_id);
473 sub BatchRevertBibRecords {
474 my $batch_id = shift;
478 my $num_reverted = 0;
479 my $num_items_deleted = 0;
481 # commit (i.e., save, all records in the batch)
482 # FIXME biblio only at the moment
483 SetImportBatchStatus('reverting');
484 my $overlay_action = GetImportBatchOverlayAction($batch_id);
485 my $dbh = C4::Context->dbh;
486 my $sth = $dbh->prepare("SELECT import_record_id, status, overlay_status, marcxml_old, encoding, matched_biblionumber
488 JOIN import_biblios USING (import_record_id)
489 WHERE import_batch_id = ?");
490 $sth->execute($batch_id);
491 while (my $rowref = $sth->fetchrow_hashref) {
492 if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'reverted') {
495 if ($overlay_action eq 'create_new' or
496 ($overlay_action eq 'replace' and $rowref->{'overlay_status'} eq 'no_match')) {
497 $num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'});
498 my $error = DelBiblio($rowref->{'matched_biblionumber'});
499 if (defined $error) {
503 SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted');
507 my $old_record = MARC::Record->new_from_xml($rowref->{'marcxml_old'}, 'UTF-8', $rowref->{'encoding'});
508 my $biblionumber = $rowref->{'matched_biblionumber'};
509 my ($count, $oldbiblio) = GetBiblio($biblionumber);
510 $num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'});
511 ModBiblio($old_record, $biblionumber, $oldbiblio->{'frameworkcode'});
512 SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted');
516 SetImportBatchStatus($batch_id, 'reverted');
517 return ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored);
520 =head2 BatchRevertItems
524 my $num_items_deleted = BatchRevertItems($import_record_id, $biblionumber);
530 sub BatchRevertItems {
531 my ($import_record_id, $biblionumber) = @_;
533 my $dbh = C4::Context->dbh;
534 my $num_items_deleted = 0;
536 my $sth = $dbh->prepare_cached("SELECT import_items_id, itemnumber
538 WHERE import_record_id = ?");
539 $sth->bind_param(1, $import_record_id);
541 while (my $row = $sth->fetchrow_hashref()) {
542 DelItem($dbh, $biblionumber, $row->{'itemnumber'});
543 my $updsth = $dbh->prepare("UPDATE import_items SET status = ? WHERE import_items_id = ?");
544 $updsth->bind_param(1, 'reverted');
545 $updsth->bind_param(2, $row->{'import_items_id'});
548 $num_items_deleted++;
551 return $num_items_deleted;
554 =head2 GetImportBatchRangeDesc
558 my $results = GetImportBatchRangeDesc($offset, $results_per_group);
562 Returns a reference to an array of hash references corresponding to
563 import_batches rows (sorted in descending order by import_batch_id)
564 start at the given offset.
568 sub GetImportBatchRangeDesc {
569 my ($offset, $results_per_group) = @_;
571 my $dbh = C4::Context->dbh;
572 my $sth = $dbh->prepare_cached("SELECT * FROM import_batches
573 WHERE batch_type = 'batch'
574 ORDER BY import_batch_id DESC
576 $sth->bind_param(1, $results_per_group);
577 $sth->bind_param(2, $offset);
581 while (my $row = $sth->fetchrow_hashref) {
582 push @$results, $row;
588 =head2 GetNumberOfImportBatches
592 my $count = GetNumberOfImportBatches();
598 sub GetNumberOfNonZ3950ImportBatches {
599 my $dbh = C4::Context->dbh;
600 my $sth = $dbh->prepare("SELECT COUNT(*) FROM import_batches WHERE batch_type='batch'");
602 my ($count) = $sth->fetchrow_array();
607 =head2 GetImportBibliosRange
611 my $results = GetImportBibliosRange($batch_id, $offset, $results_per_group);
615 Returns a reference to an array of hash references corresponding to
616 import_biblios/import_records rows for a given batch
617 starting at the given offset.
621 sub GetImportBibliosRange {
622 my ($batch_id, $offset, $results_per_group) = @_;
624 my $dbh = C4::Context->dbh;
625 my $sth = $dbh->prepare_cached("SELECT title, author, isbn, issn, import_record_id, record_sequence,
626 status, overlay_status
628 JOIN import_biblios USING (import_record_id)
629 WHERE import_batch_id = ?
630 ORDER BY import_record_id LIMIT ? OFFSET ?");
631 $sth->bind_param(1, $batch_id);
632 $sth->bind_param(2, $results_per_group);
633 $sth->bind_param(3, $offset);
636 while (my $row = $sth->fetchrow_hashref) {
637 push @$results, $row;
644 =head2 GetBestRecordMatch
648 my $record_id = GetBestRecordMatch($import_record_id);
654 sub GetBestRecordMatch {
655 my ($import_record_id) = @_;
657 my $dbh = C4::Context->dbh;
658 my $sth = $dbh->prepare("SELECT candidate_match_id
659 FROM import_record_matches
660 WHERE import_record_id = ?
661 ORDER BY score DESC, candidate_match_id DESC");
662 $sth->execute($import_record_id);
663 my ($record_id) = $sth->fetchrow_array();
668 =head2 GetImportBatchStatus
672 my $status = GetImportBatchStatus($batch_id);
678 sub GetImportBatchStatus {
681 my $dbh = C4::Context->dbh;
682 my $sth = $dbh->prepare("SELECT import_status FROM import_batches WHERE batch_id = ?");
683 $sth->execute($batch_id);
684 my ($status) = $sth->fetchrow_array();
691 =head2 SetImportBatchStatus
695 SetImportBatchStatus($batch_id, $new_status);
701 sub SetImportBatchStatus {
702 my ($batch_id, $new_status) = @_;
704 my $dbh = C4::Context->dbh;
705 my $sth = $dbh->prepare("UPDATE import_batches SET import_status = ? WHERE import_batch_id = ?");
706 $sth->execute($new_status, $batch_id);
711 =head2 GetImportBatchOverlayAction
715 my $overlay_action = GetImportBatchOverlayAction($batch_id);
721 sub GetImportBatchOverlayAction {
724 my $dbh = C4::Context->dbh;
725 my $sth = $dbh->prepare("SELECT overlay_action FROM import_batches WHERE import_batch_id = ?");
726 $sth->execute($batch_id);
727 my ($overlay_action) = $sth->fetchrow_array();
729 return $overlay_action;
734 =head2 SetImportBatchOverlayAction
738 SetImportBatchOverlayAction($batch_id, $new_overlay_action);
744 sub SetImportBatchOverlayAction {
745 my ($batch_id, $new_overlay_action) = @_;
747 my $dbh = C4::Context->dbh;
748 my $sth = $dbh->prepare("UPDATE import_batches SET overlay_action = ? WHERE import_batch_id = ?");
749 $sth->execute($new_overlay_action, $batch_id);
754 =head2 GetImportRecordOverlayStatus
758 my $overlay_status = GetImportRecordOverlayStatus($import_record_id);
764 sub GetImportRecordOverlayStatus {
765 my ($import_record_id) = @_;
767 my $dbh = C4::Context->dbh;
768 my $sth = $dbh->prepare("SELECT overlay_status FROM import_records WHERE import_record_id = ?");
769 $sth->execute($import_record_id);
770 my ($overlay_status) = $sth->fetchrow_array();
772 return $overlay_status;
777 =head2 SetImportRecordOverlayStatus
781 SetImportRecordOverlayStatus($import_record_id, $new_overlay_status);
787 sub SetImportRecordOverlayStatus {
788 my ($import_record_id, $new_overlay_status) = @_;
790 my $dbh = C4::Context->dbh;
791 my $sth = $dbh->prepare("UPDATE import_records SET overlay_status = ? WHERE import_record_id = ?");
792 $sth->execute($new_overlay_status, $import_record_id);
797 =head2 GetImportRecordStatus
801 my $overlay_status = GetImportRecordStatus($import_record_id);
807 sub GetImportRecordStatus {
808 my ($import_record_id) = @_;
810 my $dbh = C4::Context->dbh;
811 my $sth = $dbh->prepare("SELECT status FROM import_records WHERE import_record_id = ?");
812 $sth->execute($import_record_id);
813 my ($overlay_status) = $sth->fetchrow_array();
815 return $overlay_status;
820 =head2 SetImportRecordStatus
824 SetImportRecordStatus($import_record_id, $new_overlay_status);
830 sub SetImportRecordStatus {
831 my ($import_record_id, $new_overlay_status) = @_;
833 my $dbh = C4::Context->dbh;
834 my $sth = $dbh->prepare("UPDATE import_records SET status = ? WHERE import_record_id = ?");
835 $sth->execute($new_overlay_status, $import_record_id);
840 =head2 GetImportRecordMatches
844 my $results = GetImportRecordMatches($import_record_id, $best_only);
850 sub GetImportRecordMatches {
851 my $import_record_id = shift;
852 my $best_only = @_ ? shift : 0;
854 my $dbh = C4::Context->dbh;
855 # FIXME currently biblio only
856 my $sth = $dbh->prepare_cached("SELECT title, author, biblionumber, score
858 JOIN import_record_matches USING (import_record_id)
859 JOIN biblio ON (biblionumber = candidate_match_id)
860 WHERE import_record_id = ?
861 ORDER BY score DESC, biblionumber DESC");
862 $sth->bind_param(1, $import_record_id);
865 while (my $row = $sth->fetchrow_hashref) {
866 push @$results, $row;
876 =head2 SetImportRecordMatches
880 SetImportRecordMatches($import_record_id, @matches);
886 sub SetImportRecordMatches {
887 my $import_record_id = shift;
890 my $dbh = C4::Context->dbh;
891 my $delsth = $dbh->prepare("DELETE FROM import_record_matches WHERE import_record_id = ?");
892 $delsth->execute($import_record_id);
895 my $sth = $dbh->prepare("INSERT INTO import_record_matches (import_record_id, candidate_match_id, score)
897 foreach my $match (@matches) {
898 $sth->execute($import_record_id, $match->{'record_id'}, $match->{'score'});
905 sub _create_import_record {
906 my ($batch_id, $record_sequence, $marc_record, $record_type, $encoding, $z3950random) = @_;
908 my $dbh = C4::Context->dbh;
909 my $sth = $dbh->prepare("INSERT INTO import_records (import_batch_id, record_sequence, marc, marcxml,
910 record_type, encoding, z3950random)
911 VALUES (?, ?, ?, ?, ?, ?, ?)");
912 $sth->execute($batch_id, $record_sequence, $marc_record->as_usmarc(), $marc_record->as_xml(),
913 $record_type, $encoding, $z3950random);
914 my $import_record_id = $dbh->{'mysql_insertid'};
916 return $import_record_id;
919 sub _update_import_record_marc {
920 my ($import_record_id, $marc_record) = @_;
922 my $dbh = C4::Context->dbh;
923 my $sth = $dbh->prepare("UPDATE import_records SET marc = ?, marcxml = ?
924 WHERE import_record_id = ?");
925 $sth->execute($marc_record->as_usmarc(), $marc_record->as_xml(), $import_record_id);
929 sub _add_biblio_fields {
930 my ($import_record_id, $marc_record) = @_;
932 my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
933 my $dbh = C4::Context->dbh;
934 # FIXME no controlnumber, originalsource
935 # FIXME 2 - should regularize normalization of ISBN wherever it is done
939 my $sth = $dbh->prepare("INSERT INTO import_biblios (import_record_id, title, author, isbn, issn) VALUES (?, ?, ?, ?, ?)");
940 $sth->execute($import_record_id, $title, $author, $isbn, $issn);
945 sub _update_biblio_fields {
946 my ($import_record_id, $marc_record) = @_;
948 my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
949 my $dbh = C4::Context->dbh;
950 # FIXME no controlnumber, originalsource
951 # FIXME 2 - should regularize normalization of ISBN wherever it is done
955 my $sth = $dbh->prepare("UPDATE import_biblios SET title = ?, author = ?, isbn = ?, issn = ?
956 WHERE import_record_id = ?");
957 $sth->execute($title, $author, $isbn, $issn, $import_record_id);
961 sub _parse_biblio_fields {
962 my ($marc_record) = @_;
964 my $dbh = C4::Context->dbh;
965 my $bibliofields = TransformMarcToKoha($dbh, $marc_record, '');
966 return ($bibliofields->{'title'}, $bibliofields->{'author'}, $bibliofields->{'isbn'}, $bibliofields->{'issn'});
970 sub _update_batch_record_counts {
973 my $dbh = C4::Context->dbh;
974 my $sth = $dbh->prepare_cached("UPDATE import_batches SET num_biblios = (
977 WHERE import_batch_id = import_batches.import_batch_id
978 AND record_type = 'biblio')
979 WHERE import_batch_id = ?");
980 $sth->bind_param(1, $batch_id);
983 $sth = $dbh->prepare_cached("UPDATE import_batches SET num_items = (
986 JOIN import_items USING (import_record_id)
987 WHERE import_batch_id = import_batches.import_batch_id
988 AND record_type = 'biblio')
989 WHERE import_batch_id = ?");
990 $sth->bind_param(1, $batch_id);
1000 Koha Development Team <info@koha.org>
1002 Galen Charlton <galen.charlton@liblime.com>