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) = BatchStageMarcRecords($marc_flavor, $marc_records, $file_name,
231 $comments, $branch_code, $parse_items,
238 sub BatchStageMarcRecords {
239 my ($marc_flavor, $marc_records, $file_name, $comments, $branch_code, $parse_items, $leave_as_staging) = @_;
241 my $batch_id = AddImportBatch('create_new', 'staging', 'batch', $file_name, $comments);
242 my @invalid_records = ();
245 # FIXME - for now, we're dealing only with bibs
247 foreach my $marc_blob (split(/\x1D/, $marc_records)) {
249 my $marc_record = FixEncoding($marc_blob, "\x1D");
250 my $import_record_id;
251 if (scalar($marc_record->fields()) == 0) {
252 push @invalid_records, $marc_blob;
255 $import_record_id = AddBiblioToBatch($batch_id, $rec_num, $marc_record, $marc_flavor, int(rand(99999)), 0);
257 my @import_items_ids = AddItemsToImportBiblio($batch_id, $import_record_id, $marc_record, 0);
258 $num_items += scalar(@import_items_ids);
262 unless ($leave_as_staging) {
263 SetImportBatchStatus($batch_id, 'staged');
265 # FIXME branch_code, number of bibs, number of items
266 _update_batch_record_counts($batch_id);
267 return ($batch_id, $num_valid, $num_items, @invalid_records);
270 =head2 AddItemsToImportBiblio
274 my @import_items_ids = AddItemsToImportBiblio($batch_id, $import_record_id, $marc_record, $update_counts);
280 sub AddItemsToImportBiblio {
281 my $batch_id = shift;
282 my $import_record_id = shift;
283 my $marc_record = shift;
284 my $update_counts = @_ ? shift : 0;
286 my @import_items_ids = ();
288 my $dbh = C4::Context->dbh;
289 my ($item_tag,$item_subfield) = &GetMarcFromKohaField("items.itemnumber",'');
290 foreach my $item_field ($marc_record->field($item_tag)) {
291 my $item_marc = MARC::Record->new();
292 $item_marc->append_fields($item_field);
293 $marc_record->delete_field($item_field);
294 my $sth = $dbh->prepare_cached("INSERT INTO import_items (import_record_id, status, marcxml)
296 $sth->bind_param(1, $import_record_id);
297 $sth->bind_param(2, 'staged');
298 $sth->bind_param(3, $item_marc->as_xml());
300 push @import_items_ids, $dbh->{'mysql_insertid'};
304 if ($#import_items_ids > -1) {
305 _update_batch_record_counts($batch_id) if $update_counts;
306 _update_import_record_marc($import_record_id, $marc_record);
308 return @import_items_ids;
311 =head2 BatchFindBibDuplicates
315 my $num_with_matches = BatchFindBibDuplicates($batch_id, $matcher, $max_matches);
319 Goes through the records loaded in the batch and attempts to
320 find duplicates for each one. Sets the overlay action to
321 'replace' if it was 'create_new', and sets the overlay status
322 of each record to 'no_match' or 'auto_match' as appropriate.
324 The $max_matches parameter is optional; if it is not supplied,
329 sub BatchFindBibDuplicates {
330 my $batch_id = shift;
332 my $max_matches = @_ ? shift : 10;
334 my $dbh = C4::Context->dbh;
335 my $old_overlay_action = GetImportBatchOverlayAction($batch_id);
336 if ($old_overlay_action eq "create_new") {
337 SetImportBatchOverlayAction($batch_id, 'replace');
340 my $sth = $dbh->prepare("SELECT import_record_id, marc
342 JOIN import_biblios USING (import_record_id)
343 WHERE import_batch_id = ?");
344 $sth->execute($batch_id);
345 my $num_with_matches = 0;
346 while (my $rowref = $sth->fetchrow_hashref) {
347 my $marc_record = MARC::Record->new_from_usmarc($rowref->{'marc'});
348 my @matches = $matcher->get_matches($marc_record, $max_matches);
349 if (scalar(@matches) > 0) {
351 SetImportRecordMatches($rowref->{'import_record_id'}, @matches);
352 SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'auto_match');
354 SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'no_match');
358 return $num_with_matches;
361 =head2 BatchCommitBibRecords
365 my ($num_added, $num_updated, $num_items_added, $num_ignored) = BatchCommitBibRecords($batch_id);
371 sub BatchCommitBibRecords {
372 my $batch_id = shift;
376 my $num_items_added = 0;
378 # commit (i.e., save, all records in the batch)
379 # FIXME biblio only at the moment
380 SetImportBatchStatus('importing');
381 my $overlay_action = GetImportBatchOverlayAction($batch_id);
382 my $dbh = C4::Context->dbh;
383 my $sth = $dbh->prepare("SELECT import_record_id, status, overlay_status, marc
385 JOIN import_biblios USING (import_record_id)
386 WHERE import_batch_id = ?");
387 $sth->execute($batch_id);
388 while (my $rowref = $sth->fetchrow_hashref) {
389 if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'imported') {
392 my $marc_record = MARC::Record->new_from_usmarc($rowref->{'marc'});
393 if ($overlay_action eq 'create_new' or
394 ($overlay_action eq 'replace' and $rowref->{'overlay_status'} eq 'no_match')) {
396 my ($biblionumber, $biblioitemnumber) = AddBiblio($marc_record, '');
397 my $sth = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?");
398 $sth->execute($biblionumber, $rowref->{'import_record_id'});
400 $num_items_added += BatchCommitItems($rowref->{'import_record_id'}, $biblionumber);
401 SetImportRecordStatus($rowref->{'import_record_id'}, 'imported');
404 my $biblionumber = GetBestRecordMatch($rowref->{'import_record_id'});
405 my ($count, $oldbiblio) = GetBiblio($biblionumber);
406 my $oldxml = GetXmlBiblio($biblionumber);
407 ModBiblio($marc_record, $biblionumber, $oldbiblio->{'frameworkcode'});
408 my $sth = $dbh->prepare_cached("UPDATE import_records SET marcxml_old = ? WHERE import_record_id = ?");
409 $sth->execute($oldxml, $rowref->{'import_record_id'});
411 my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?");
412 $sth2->execute($biblionumber, $rowref->{'import_record_id'});
414 $num_items_added += BatchCommitItems($rowref->{'import_record_id'}, $biblionumber);
415 SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied');
416 SetImportRecordStatus($rowref->{'import_record_id'}, 'imported');
420 SetImportBatchStatus($batch_id, 'imported');
421 return ($num_added, $num_updated, $num_items_added, $num_ignored);
424 =head2 BatchCommitItems
428 $num_items_added = BatchCommitItems($import_record_id, $biblionumber);
434 sub BatchCommitItems {
435 my ($import_record_id, $biblionumber) = @_;
437 my $dbh = C4::Context->dbh;
439 my $num_items_added = 0;
440 my $sth = $dbh->prepare("SELECT import_items_id, import_items.marcxml, encoding
442 JOIN import_records USING (import_record_id)
443 WHERE import_record_id = ?
444 ORDER BY import_items_id");
445 $sth->bind_param(1, $import_record_id);
447 while (my $row = $sth->fetchrow_hashref()) {
448 my $item_marc = MARC::Record->new_from_xml($row->{'marcxml'}, 'UTF-8', $row->{'encoding'});
449 my ($item_biblionumber, $biblionumber, $itemnumber) = AddItem($item_marc, $biblionumber);
450 my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
451 $updsth->bind_param(1, 'imported');
452 $updsth->bind_param(2, $itemnumber);
453 $updsth->bind_param(3, $row->{'import_items_id'});
459 return $num_items_added;
462 =head2 BatchRevertBibRecords
466 my ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored) = BatchRevertBibRecords($batch_id);
472 sub BatchRevertBibRecords {
473 my $batch_id = shift;
477 my $num_reverted = 0;
478 my $num_items_deleted = 0;
480 # commit (i.e., save, all records in the batch)
481 # FIXME biblio only at the moment
482 SetImportBatchStatus('reverting');
483 my $overlay_action = GetImportBatchOverlayAction($batch_id);
484 my $dbh = C4::Context->dbh;
485 my $sth = $dbh->prepare("SELECT import_record_id, status, overlay_status, marcxml_old, encoding, matched_biblionumber
487 JOIN import_biblios USING (import_record_id)
488 WHERE import_batch_id = ?");
489 $sth->execute($batch_id);
490 while (my $rowref = $sth->fetchrow_hashref) {
491 if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'reverted') {
494 if ($overlay_action eq 'create_new' or
495 ($overlay_action eq 'replace' and $rowref->{'overlay_status'} eq 'no_match')) {
496 $num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'});
497 my $error = DelBiblio($rowref->{'matched_biblionumber'});
498 if (defined $error) {
502 SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted');
506 my $old_record = MARC::Record->new_from_xml($rowref->{'marcxml_old'}, 'UTF-8', $rowref->{'encoding'});
507 my $biblionumber = $rowref->{'matched_biblionumber'};
508 my ($count, $oldbiblio) = GetBiblio($biblionumber);
509 $num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'});
510 ModBiblio($old_record, $biblionumber, $oldbiblio->{'frameworkcode'});
511 SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted');
515 SetImportBatchStatus($batch_id, 'reverted');
516 return ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored);
519 =head2 BatchRevertItems
523 my $num_items_deleted = BatchRevertItems($import_record_id, $biblionumber);
529 sub BatchRevertItems {
530 my ($import_record_id, $biblionumber) = @_;
532 my $dbh = C4::Context->dbh;
533 my $num_items_deleted = 0;
535 my $sth = $dbh->prepare_cached("SELECT import_items_id, itemnumber
537 WHERE import_record_id = ?");
538 $sth->bind_param(1, $import_record_id);
540 while (my $row = $sth->fetchrow_hashref()) {
541 DelItem($dbh, $biblionumber, $row->{'itemnumber'});
542 my $updsth = $dbh->prepare("UPDATE import_items SET status = ? WHERE import_items_id = ?");
543 $updsth->bind_param(1, 'reverted');
544 $updsth->bind_param(2, $row->{'import_items_id'});
547 $num_items_deleted++;
550 return $num_items_deleted;
553 =head2 GetImportBatchRangeDesc
557 my $results = GetImportBatchRangeDesc($offset, $results_per_group);
561 Returns a reference to an array of hash references corresponding to
562 import_batches rows (sorted in descending order by import_batch_id)
563 start at the given offset.
567 sub GetImportBatchRangeDesc {
568 my ($offset, $results_per_group) = @_;
570 my $dbh = C4::Context->dbh;
571 my $sth = $dbh->prepare_cached("SELECT * FROM import_batches
572 WHERE batch_type = 'batch'
573 ORDER BY import_batch_id DESC
575 $sth->bind_param(1, $results_per_group);
576 $sth->bind_param(2, $offset);
580 while (my $row = $sth->fetchrow_hashref) {
581 push @$results, $row;
587 =head2 GetNumberOfImportBatches
591 my $count = GetNumberOfImportBatches();
597 sub GetNumberOfNonZ3950ImportBatches {
598 my $dbh = C4::Context->dbh;
599 my $sth = $dbh->prepare("SELECT COUNT(*) FROM import_batches WHERE batch_type='batch'");
601 my ($count) = $sth->fetchrow_array();
606 =head2 GetImportBibliosRange
610 my $results = GetImportBibliosRange($batch_id, $offset, $results_per_group);
614 Returns a reference to an array of hash references corresponding to
615 import_biblios/import_records rows for a given batch
616 starting at the given offset.
620 sub GetImportBibliosRange {
621 my ($batch_id, $offset, $results_per_group) = @_;
623 my $dbh = C4::Context->dbh;
624 my $sth = $dbh->prepare_cached("SELECT title, author, isbn, issn, import_record_id, record_sequence,
625 status, overlay_status
627 JOIN import_biblios USING (import_record_id)
628 WHERE import_batch_id = ?
629 ORDER BY import_record_id LIMIT ? OFFSET ?");
630 $sth->bind_param(1, $batch_id);
631 $sth->bind_param(2, $results_per_group);
632 $sth->bind_param(3, $offset);
635 while (my $row = $sth->fetchrow_hashref) {
636 push @$results, $row;
643 =head2 GetBestRecordMatch
647 my $record_id = GetBestRecordMatch($import_record_id);
653 sub GetBestRecordMatch {
654 my ($import_record_id) = @_;
656 my $dbh = C4::Context->dbh;
657 my $sth = $dbh->prepare("SELECT candidate_match_id
658 FROM import_record_matches
659 WHERE import_record_id = ?
660 ORDER BY score DESC, candidate_match_id DESC");
661 $sth->execute($import_record_id);
662 my ($record_id) = $sth->fetchrow_array();
667 =head2 GetImportBatchStatus
671 my $status = GetImportBatchStatus($batch_id);
677 sub GetImportBatchStatus {
680 my $dbh = C4::Context->dbh;
681 my $sth = $dbh->prepare("SELECT import_status FROM import_batches WHERE batch_id = ?");
682 $sth->execute($batch_id);
683 my ($status) = $sth->fetchrow_array();
690 =head2 SetImportBatchStatus
694 SetImportBatchStatus($batch_id, $new_status);
700 sub SetImportBatchStatus {
701 my ($batch_id, $new_status) = @_;
703 my $dbh = C4::Context->dbh;
704 my $sth = $dbh->prepare("UPDATE import_batches SET import_status = ? WHERE import_batch_id = ?");
705 $sth->execute($new_status, $batch_id);
710 =head2 GetImportBatchOverlayAction
714 my $overlay_action = GetImportBatchOverlayAction($batch_id);
720 sub GetImportBatchOverlayAction {
723 my $dbh = C4::Context->dbh;
724 my $sth = $dbh->prepare("SELECT overlay_action FROM import_batches WHERE import_batch_id = ?");
725 $sth->execute($batch_id);
726 my ($overlay_action) = $sth->fetchrow_array();
728 return $overlay_action;
733 =head2 SetImportBatchOverlayAction
737 SetImportBatchOverlayAction($batch_id, $new_overlay_action);
743 sub SetImportBatchOverlayAction {
744 my ($batch_id, $new_overlay_action) = @_;
746 my $dbh = C4::Context->dbh;
747 my $sth = $dbh->prepare("UPDATE import_batches SET overlay_action = ? WHERE import_batch_id = ?");
748 $sth->execute($new_overlay_action, $batch_id);
753 =head2 GetImportRecordOverlayStatus
757 my $overlay_status = GetImportRecordOverlayStatus($import_record_id);
763 sub GetImportRecordOverlayStatus {
764 my ($import_record_id) = @_;
766 my $dbh = C4::Context->dbh;
767 my $sth = $dbh->prepare("SELECT overlay_status FROM import_records WHERE import_record_id = ?");
768 $sth->execute($import_record_id);
769 my ($overlay_status) = $sth->fetchrow_array();
771 return $overlay_status;
776 =head2 SetImportRecordOverlayStatus
780 SetImportRecordOverlayStatus($import_record_id, $new_overlay_status);
786 sub SetImportRecordOverlayStatus {
787 my ($import_record_id, $new_overlay_status) = @_;
789 my $dbh = C4::Context->dbh;
790 my $sth = $dbh->prepare("UPDATE import_records SET overlay_status = ? WHERE import_record_id = ?");
791 $sth->execute($new_overlay_status, $import_record_id);
796 =head2 GetImportRecordStatus
800 my $overlay_status = GetImportRecordStatus($import_record_id);
806 sub GetImportRecordStatus {
807 my ($import_record_id) = @_;
809 my $dbh = C4::Context->dbh;
810 my $sth = $dbh->prepare("SELECT status FROM import_records WHERE import_record_id = ?");
811 $sth->execute($import_record_id);
812 my ($overlay_status) = $sth->fetchrow_array();
814 return $overlay_status;
819 =head2 SetImportRecordStatus
823 SetImportRecordStatus($import_record_id, $new_overlay_status);
829 sub SetImportRecordStatus {
830 my ($import_record_id, $new_overlay_status) = @_;
832 my $dbh = C4::Context->dbh;
833 my $sth = $dbh->prepare("UPDATE import_records SET status = ? WHERE import_record_id = ?");
834 $sth->execute($new_overlay_status, $import_record_id);
839 =head2 GetImportRecordMatches
843 my $results = GetImportRecordMatches($import_record_id, $best_only);
849 sub GetImportRecordMatches {
850 my $import_record_id = shift;
851 my $best_only = @_ ? shift : 0;
853 my $dbh = C4::Context->dbh;
854 # FIXME currently biblio only
855 my $sth = $dbh->prepare_cached("SELECT title, author, biblionumber, score
857 JOIN import_record_matches USING (import_record_id)
858 JOIN biblio ON (biblionumber = candidate_match_id)
859 WHERE import_record_id = ?
860 ORDER BY score DESC, biblionumber DESC");
861 $sth->bind_param(1, $import_record_id);
864 while (my $row = $sth->fetchrow_hashref) {
865 push @$results, $row;
875 =head2 SetImportRecordMatches
879 SetImportRecordMatches($import_record_id, @matches);
885 sub SetImportRecordMatches {
886 my $import_record_id = shift;
889 my $dbh = C4::Context->dbh;
890 my $delsth = $dbh->prepare("DELETE FROM import_record_matches WHERE import_record_id = ?");
891 $delsth->execute($import_record_id);
894 my $sth = $dbh->prepare("INSERT INTO import_record_matches (import_record_id, candidate_match_id, score)
896 foreach my $match (@matches) {
897 $sth->execute($import_record_id, $match->{'record_id'}, $match->{'score'});
904 sub _create_import_record {
905 my ($batch_id, $record_sequence, $marc_record, $record_type, $encoding, $z3950random) = @_;
907 my $dbh = C4::Context->dbh;
908 my $sth = $dbh->prepare("INSERT INTO import_records (import_batch_id, record_sequence, marc, marcxml,
909 record_type, encoding, z3950random)
910 VALUES (?, ?, ?, ?, ?, ?, ?)");
911 $sth->execute($batch_id, $record_sequence, $marc_record->as_usmarc(), $marc_record->as_xml(),
912 $record_type, $encoding, $z3950random);
913 my $import_record_id = $dbh->{'mysql_insertid'};
915 return $import_record_id;
918 sub _update_import_record_marc {
919 my ($import_record_id, $marc_record) = @_;
921 my $dbh = C4::Context->dbh;
922 my $sth = $dbh->prepare("UPDATE import_records SET marc = ?, marcxml = ?
923 WHERE import_record_id = ?");
924 $sth->execute($marc_record->as_usmarc(), $marc_record->as_xml(), $import_record_id);
928 sub _add_biblio_fields {
929 my ($import_record_id, $marc_record) = @_;
931 my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
932 my $dbh = C4::Context->dbh;
933 # FIXME no controlnumber, originalsource
934 # FIXME 2 - should regularize normalization of ISBN wherever it is done
938 my $sth = $dbh->prepare("INSERT INTO import_biblios (import_record_id, title, author, isbn, issn) VALUES (?, ?, ?, ?, ?)");
939 $sth->execute($import_record_id, $title, $author, $isbn, $issn);
944 sub _update_biblio_fields {
945 my ($import_record_id, $marc_record) = @_;
947 my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
948 my $dbh = C4::Context->dbh;
949 # FIXME no controlnumber, originalsource
950 # FIXME 2 - should regularize normalization of ISBN wherever it is done
954 my $sth = $dbh->prepare("UPDATE import_biblios SET title = ?, author = ?, isbn = ?, issn = ?
955 WHERE import_record_id = ?");
956 $sth->execute($title, $author, $isbn, $issn, $import_record_id);
960 sub _parse_biblio_fields {
961 my ($marc_record) = @_;
963 my $dbh = C4::Context->dbh;
964 my $bibliofields = TransformMarcToKoha($dbh, $marc_record, '');
965 return ($bibliofields->{'title'}, $bibliofields->{'author'}, $bibliofields->{'isbn'}, $bibliofields->{'issn'});
969 sub _update_batch_record_counts {
972 my $dbh = C4::Context->dbh;
973 my $sth = $dbh->prepare_cached("UPDATE import_batches SET num_biblios = (
976 WHERE import_batch_id = import_batches.import_batch_id
977 AND record_type = 'biblio')
978 WHERE import_batch_id = ?");
979 $sth->bind_param(1, $batch_id);
982 $sth = $dbh->prepare_cached("UPDATE import_batches SET num_items = (
985 JOIN import_items USING (import_record_id)
986 WHERE import_batch_id = import_batches.import_batch_id
987 AND record_type = 'biblio')
988 WHERE import_batch_id = ?");
989 $sth->bind_param(1, $batch_id);
999 Koha Development Team <info@koha.org>
1001 Galen Charlton <galen.charlton@liblime.com>