Lines 1-6
Link Here
|
1 |
package C4::ImportBatch; |
1 |
package C4::ImportBatch; |
2 |
|
2 |
|
3 |
# Copyright (C) 2007 LibLime |
3 |
# Copyright (C) 2007 LibLime, 2012 C & P Bibliography Services |
4 |
# |
4 |
# |
5 |
# This file is part of Koha. |
5 |
# This file is part of Koha. |
6 |
# |
6 |
# |
Lines 40-53
BEGIN {
Link Here
|
40 |
GetImportRecordMarcXML |
40 |
GetImportRecordMarcXML |
41 |
AddImportBatch |
41 |
AddImportBatch |
42 |
GetImportBatch |
42 |
GetImportBatch |
|
|
43 |
AddAuthorityToBatch |
43 |
AddBiblioToBatch |
44 |
AddBiblioToBatch |
44 |
AddItemsToImportBiblio |
45 |
AddItemsToImportBiblio |
|
|
46 |
ModAuthorityInBatch |
45 |
ModBiblioInBatch |
47 |
ModBiblioInBatch |
46 |
|
48 |
|
47 |
BatchStageMarcRecords |
49 |
BatchStageMarcRecords |
48 |
BatchFindBibDuplicates |
50 |
BatchFindDuplicates |
49 |
BatchCommitBibRecords |
51 |
BatchCommitRecords |
50 |
BatchRevertBibRecords |
52 |
BatchRevertRecords |
51 |
CleanBatch |
53 |
CleanBatch |
52 |
|
54 |
|
53 |
GetAllImportBatches |
55 |
GetAllImportBatches |
Lines 272-281
sub ModBiblioInBatch {
Link Here
|
272 |
|
274 |
|
273 |
} |
275 |
} |
274 |
|
276 |
|
|
|
277 |
=head2 AddAuthToBatch |
278 |
|
279 |
my $import_record_id = AddAuthToBatch($batch_id, $record_sequence, |
280 |
$marc_record, $encoding, $z3950random, $update_counts); |
281 |
|
282 |
=cut |
283 |
|
284 |
sub AddAuthToBatch { |
285 |
my $batch_id = shift; |
286 |
my $record_sequence = shift; |
287 |
my $marc_record = shift; |
288 |
my $encoding = shift; |
289 |
my $z3950random = shift; |
290 |
my $update_counts = @_ ? shift : 1; |
291 |
|
292 |
my $import_record_id = _create_import_record($batch_id, $record_sequence, $marc_record, 'auth', $encoding, $z3950random); |
293 |
_update_batch_record_counts($batch_id) if $update_counts; |
294 |
return $import_record_id; |
295 |
} |
296 |
|
297 |
=head2 ModAuthInBatch |
298 |
|
299 |
ModAuthInBatch($import_record_id, $marc_record); |
300 |
|
301 |
=cut |
302 |
|
303 |
sub ModAuthInBatch { |
304 |
my ($import_record_id, $marc_record) = @_; |
305 |
|
306 |
_update_import_record_marc($import_record_id, $marc_record); |
307 |
|
308 |
} |
309 |
|
275 |
=head2 BatchStageMarcRecords |
310 |
=head2 BatchStageMarcRecords |
276 |
|
311 |
|
277 |
($batch_id, $num_records, $num_items, @invalid_records) = |
312 |
($batch_id, $num_records, $num_items, @invalid_records) = |
278 |
BatchStageMarcRecords($encoding, $marc_records, $file_name, |
313 |
BatchStageMarcRecords($record_type, $encoding, $marc_records, $file_name, |
279 |
$comments, $branch_code, $parse_items, |
314 |
$comments, $branch_code, $parse_items, |
280 |
$leave_as_staging, |
315 |
$leave_as_staging, |
281 |
$progress_interval, $progress_callback); |
316 |
$progress_interval, $progress_callback); |
Lines 283-288
sub ModBiblioInBatch {
Link Here
|
283 |
=cut |
318 |
=cut |
284 |
|
319 |
|
285 |
sub BatchStageMarcRecords { |
320 |
sub BatchStageMarcRecords { |
|
|
321 |
my $record_type = shift; |
286 |
my $encoding = shift; |
322 |
my $encoding = shift; |
287 |
my $marc_records = shift; |
323 |
my $marc_records = shift; |
288 |
my $file_name = shift; |
324 |
my $file_name = shift; |
Lines 338-347
sub BatchStageMarcRecords {
Link Here
|
338 |
push @invalid_records, $marc_blob; |
374 |
push @invalid_records, $marc_blob; |
339 |
} else { |
375 |
} else { |
340 |
$num_valid++; |
376 |
$num_valid++; |
341 |
$import_record_id = AddBiblioToBatch($batch_id, $rec_num, $marc_record, $encoding, int(rand(99999)), 0); |
377 |
if ($record_type eq 'biblio') { |
342 |
if ($parse_items) { |
378 |
$import_record_id = AddBiblioToBatch($batch_id, $rec_num, $marc_record, $encoding, int(rand(99999)), 0); |
343 |
my @import_items_ids = AddItemsToImportBiblio($batch_id, $import_record_id, $marc_record, 0); |
379 |
if ($parse_items) { |
344 |
$num_items += scalar(@import_items_ids); |
380 |
my @import_items_ids = AddItemsToImportBiblio($batch_id, $import_record_id, $marc_record, 0); |
|
|
381 |
$num_items += scalar(@import_items_ids); |
382 |
} |
383 |
} elsif ($record_type eq 'auth') { |
384 |
$import_record_id = AddAuthToBatch($batch_id, $rec_num, $marc_record, $encoding, int(rand(99999)), 0); |
345 |
} |
385 |
} |
346 |
} |
386 |
} |
347 |
} |
387 |
} |
Lines 392-400
sub AddItemsToImportBiblio {
Link Here
|
392 |
return @import_items_ids; |
432 |
return @import_items_ids; |
393 |
} |
433 |
} |
394 |
|
434 |
|
395 |
=head2 BatchFindBibDuplicates |
435 |
=head2 BatchFindDuplicates |
396 |
|
436 |
|
397 |
my $num_with_matches = BatchFindBibDuplicates($batch_id, $matcher, |
437 |
my $num_with_matches = BatchFindDuplicates($batch_id, $matcher, |
398 |
$max_matches, $progress_interval, $progress_callback); |
438 |
$max_matches, $progress_interval, $progress_callback); |
399 |
|
439 |
|
400 |
Goes through the records loaded in the batch and attempts to |
440 |
Goes through the records loaded in the batch and attempts to |
Lines 412-418
singular argument.
Link Here
|
412 |
|
452 |
|
413 |
=cut |
453 |
=cut |
414 |
|
454 |
|
415 |
sub BatchFindBibDuplicates { |
455 |
sub BatchFindDuplicates { |
416 |
my $batch_id = shift; |
456 |
my $batch_id = shift; |
417 |
my $matcher = shift; |
457 |
my $matcher = shift; |
418 |
my $max_matches = @_ ? shift : 10; |
458 |
my $max_matches = @_ ? shift : 10; |
Lines 430-438
sub BatchFindBibDuplicates {
Link Here
|
430 |
|
470 |
|
431 |
my $dbh = C4::Context->dbh; |
471 |
my $dbh = C4::Context->dbh; |
432 |
|
472 |
|
433 |
my $sth = $dbh->prepare("SELECT import_record_id, marc |
473 |
my $sth = $dbh->prepare("SELECT import_records.import_record_id, record_type, marc |
434 |
FROM import_records |
474 |
FROM import_records |
435 |
JOIN import_biblios USING (import_record_id) |
475 |
LEFT JOIN import_auths ON (import_records.import_record_id=import_auths.import_record_id) |
|
|
476 |
LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id) |
436 |
WHERE import_batch_id = ?"); |
477 |
WHERE import_batch_id = ?"); |
437 |
$sth->execute($batch_id); |
478 |
$sth->execute($batch_id); |
438 |
my $num_with_matches = 0; |
479 |
my $num_with_matches = 0; |
Lines 460-474
sub BatchFindBibDuplicates {
Link Here
|
460 |
return $num_with_matches; |
501 |
return $num_with_matches; |
461 |
} |
502 |
} |
462 |
|
503 |
|
463 |
=head2 BatchCommitBibRecords |
504 |
=head2 BatchCommitRecords |
464 |
|
505 |
|
465 |
my ($num_added, $num_updated, $num_items_added, $num_items_errored, |
506 |
my ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored) = |
466 |
$num_ignored) = BatchCommitBibRecords($batch_id, $framework, |
507 |
BatchCommitRecords($batch_id, $framework, |
467 |
$progress_interval, $progress_callback); |
508 |
$progress_interval, $progress_callback); |
468 |
|
509 |
|
469 |
=cut |
510 |
=cut |
470 |
|
511 |
|
471 |
sub BatchCommitBibRecords { |
512 |
sub BatchCommitRecords { |
472 |
my $batch_id = shift; |
513 |
my $batch_id = shift; |
473 |
my $framework = shift; |
514 |
my $framework = shift; |
474 |
|
515 |
|
Lines 483-507
sub BatchCommitBibRecords {
Link Here
|
483 |
$progress_interval = 0 unless 'CODE' eq ref $progress_callback; |
524 |
$progress_interval = 0 unless 'CODE' eq ref $progress_callback; |
484 |
} |
525 |
} |
485 |
|
526 |
|
|
|
527 |
my $record_type; |
486 |
my $num_added = 0; |
528 |
my $num_added = 0; |
487 |
my $num_updated = 0; |
529 |
my $num_updated = 0; |
488 |
my $num_items_added = 0; |
530 |
my $num_items_added = 0; |
489 |
my $num_items_errored = 0; |
531 |
my $num_items_errored = 0; |
490 |
my $num_ignored = 0; |
532 |
my $num_ignored = 0; |
491 |
# commit (i.e., save, all records in the batch) |
533 |
# commit (i.e., save, all records in the batch) |
492 |
# FIXME biblio only at the moment |
|
|
493 |
SetImportBatchStatus('importing'); |
534 |
SetImportBatchStatus('importing'); |
494 |
my $overlay_action = GetImportBatchOverlayAction($batch_id); |
535 |
my $overlay_action = GetImportBatchOverlayAction($batch_id); |
495 |
my $nomatch_action = GetImportBatchNoMatchAction($batch_id); |
536 |
my $nomatch_action = GetImportBatchNoMatchAction($batch_id); |
496 |
my $item_action = GetImportBatchItemAction($batch_id); |
537 |
my $item_action = GetImportBatchItemAction($batch_id); |
|
|
538 |
my $item_tag; |
539 |
my $item_subfield; |
497 |
my $dbh = C4::Context->dbh; |
540 |
my $dbh = C4::Context->dbh; |
498 |
my $sth = $dbh->prepare("SELECT import_record_id, status, overlay_status, marc, encoding |
541 |
my $sth = $dbh->prepare("SELECT import_records.import_record_id, record_type, status, overlay_status, marc, encoding |
499 |
FROM import_records |
542 |
FROM import_records |
500 |
JOIN import_biblios USING (import_record_id) |
543 |
LEFT JOIN import_auths ON (import_records.import_record_id=import_auths.import_record_id) |
|
|
544 |
LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id) |
501 |
WHERE import_batch_id = ?"); |
545 |
WHERE import_batch_id = ?"); |
502 |
$sth->execute($batch_id); |
546 |
$sth->execute($batch_id); |
503 |
my $rec_num = 0; |
547 |
my $rec_num = 0; |
504 |
while (my $rowref = $sth->fetchrow_hashref) { |
548 |
while (my $rowref = $sth->fetchrow_hashref) { |
|
|
549 |
$record_type = $rowref->{'record_type'}; |
505 |
$rec_num++; |
550 |
$rec_num++; |
506 |
if ($progress_interval and (0 == ($rec_num % $progress_interval))) { |
551 |
if ($progress_interval and (0 == ($rec_num % $progress_interval))) { |
507 |
&$progress_callback($rec_num); |
552 |
&$progress_callback($rec_num); |
Lines 513-579
sub BatchCommitBibRecords {
Link Here
|
513 |
|
558 |
|
514 |
my $marc_record = MARC::Record->new_from_usmarc($rowref->{'marc'}); |
559 |
my $marc_record = MARC::Record->new_from_usmarc($rowref->{'marc'}); |
515 |
|
560 |
|
516 |
# remove any item tags - rely on BatchCommitItems |
561 |
if ($record_type eq 'biblio') { |
517 |
my ($item_tag,$item_subfield) = &GetMarcFromKohaField("items.itemnumber",''); |
562 |
# remove any item tags - rely on BatchCommitItems |
518 |
foreach my $item_field ($marc_record->field($item_tag)) { |
563 |
($item_tag,$item_subfield) = &GetMarcFromKohaField("items.itemnumber",''); |
519 |
$marc_record->delete_field($item_field); |
564 |
foreach my $item_field ($marc_record->field($item_tag)) { |
|
|
565 |
$marc_record->delete_field($item_field); |
566 |
} |
520 |
} |
567 |
} |
521 |
|
568 |
|
522 |
# decide what what to do with the bib and item records |
569 |
my ($record_result, $item_result, $record_match) = |
523 |
my ($bib_result, $item_result, $bib_match) = |
|
|
524 |
_get_commit_action($overlay_action, $nomatch_action, $item_action, |
570 |
_get_commit_action($overlay_action, $nomatch_action, $item_action, |
525 |
$rowref->{'overlay_status'}, $rowref->{'import_record_id'}); |
571 |
$rowref->{'overlay_status'}, $rowref->{'import_record_id'}, $record_type); |
526 |
|
572 |
|
527 |
if ($bib_result eq 'create_new') { |
573 |
my $recordid; |
|
|
574 |
my $query; |
575 |
if ($record_result eq 'create_new') { |
528 |
$num_added++; |
576 |
$num_added++; |
529 |
my ($biblionumber, $biblioitemnumber) = AddBiblio($marc_record, $framework); |
577 |
if ($record_type eq 'biblio') { |
530 |
my $sth = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"); |
578 |
my $biblioitemnumber; |
531 |
$sth->execute($biblionumber, $rowref->{'import_record_id'}); |
579 |
($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework); |
532 |
$sth->finish(); |
580 |
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; |
533 |
if ($item_result eq 'create_new') { |
581 |
if ($item_result eq 'create_new') { |
534 |
my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $biblionumber); |
582 |
my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid); |
535 |
$num_items_added += $bib_items_added; |
583 |
$num_items_added += $bib_items_added; |
536 |
$num_items_errored += $bib_items_errored; |
584 |
$num_items_errored += $bib_items_errored; |
|
|
585 |
} |
586 |
} else { |
587 |
my $authid = AddAuthority($marc_record, undef, GuessAuthTypeCode($marc_record)); |
588 |
$query = "UPDATE import_auths SET matched_authid = ? WHERE import_record_id = ?"; |
537 |
} |
589 |
} |
|
|
590 |
my $sth = $dbh->prepare_cached($query); |
591 |
$sth->execute($recordid, $rowref->{'import_record_id'}); |
592 |
$sth->finish(); |
538 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'imported'); |
593 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'imported'); |
539 |
} elsif ($bib_result eq 'replace') { |
594 |
} elsif ($record_result eq 'replace') { |
540 |
$num_updated++; |
595 |
$num_updated++; |
541 |
my $biblionumber = $bib_match; |
596 |
$recordid = $record_match; |
542 |
my ($count, $oldbiblio) = GetBiblio($biblionumber); |
597 |
my $oldxml; |
543 |
my $oldxml = GetXmlBiblio($biblionumber); |
598 |
if ($record_type eq 'biblio') { |
544 |
|
599 |
my ($count, $oldbiblio) = GetBiblio($recordid); |
545 |
# remove item fields so that they don't get |
600 |
$oldxml = GetXmlBiblio($recordid); |
546 |
# added again if record is reverted |
601 |
|
547 |
my $old_marc = MARC::Record->new_from_xml(StripNonXmlChars($oldxml), 'UTF-8', $rowref->{'encoding'}); |
602 |
# remove item fields so that they don't get |
548 |
foreach my $item_field ($old_marc->field($item_tag)) { |
603 |
# added again if record is reverted |
549 |
$old_marc->delete_field($item_field); |
604 |
my $old_marc = MARC::Record->new_from_xml(StripNonXmlChars($oldxml), 'UTF-8', $rowref->{'encoding'}); |
550 |
} |
605 |
foreach my $item_field ($old_marc->field($item_tag)) { |
|
|
606 |
$old_marc->delete_field($item_field); |
607 |
} |
608 |
$oldxml = $old_marc->as_xml(); |
609 |
|
610 |
ModBiblio($marc_record, $recordid, $oldbiblio->{'frameworkcode'}); |
611 |
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; |
612 |
|
613 |
if ($item_result eq 'create_new') { |
614 |
my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid); |
615 |
$num_items_added += $bib_items_added; |
616 |
$num_items_errored += $bib_items_errored; |
617 |
} |
618 |
} else { |
619 |
my $oldxml = GetAuthorityXML($recordid); |
551 |
|
620 |
|
552 |
ModBiblio($marc_record, $biblionumber, $oldbiblio->{'frameworkcode'}); |
621 |
ModAuthority($recordid, $marc_record, GuessAuthTypeCode($marc_record)); |
|
|
622 |
$query = "UPDATE import_auths SET matched_authid = ? WHERE import_record_id = ?"; |
623 |
} |
553 |
my $sth = $dbh->prepare_cached("UPDATE import_records SET marcxml_old = ? WHERE import_record_id = ?"); |
624 |
my $sth = $dbh->prepare_cached("UPDATE import_records SET marcxml_old = ? WHERE import_record_id = ?"); |
554 |
$sth->execute($old_marc->as_xml(), $rowref->{'import_record_id'}); |
625 |
$sth->execute($oldxml, $rowref->{'import_record_id'}); |
555 |
$sth->finish(); |
626 |
$sth->finish(); |
556 |
my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"); |
627 |
my $sth2 = $dbh->prepare_cached($query); |
557 |
$sth2->execute($biblionumber, $rowref->{'import_record_id'}); |
628 |
$sth2->execute($recordid, $rowref->{'import_record_id'}); |
558 |
$sth2->finish(); |
629 |
$sth2->finish(); |
559 |
if ($item_result eq 'create_new') { |
|
|
560 |
my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $biblionumber); |
561 |
$num_items_added += $bib_items_added; |
562 |
$num_items_errored += $bib_items_errored; |
563 |
} |
564 |
SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied'); |
630 |
SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied'); |
565 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'imported'); |
631 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'imported'); |
566 |
} elsif ($bib_result eq 'ignore') { |
632 |
} elsif ($record_result eq 'ignore') { |
567 |
$num_ignored++; |
633 |
$num_ignored++; |
568 |
my $biblionumber = $bib_match; |
634 |
if ($record_type eq 'biblio' and defined $recordid and $item_result eq 'create_new') { |
569 |
if (defined $biblionumber and $item_result eq 'create_new') { |
635 |
my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid); |
570 |
my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $biblionumber); |
|
|
571 |
$num_items_added += $bib_items_added; |
636 |
$num_items_added += $bib_items_added; |
572 |
$num_items_errored += $bib_items_errored; |
637 |
$num_items_errored += $bib_items_errored; |
573 |
# still need to record the matched biblionumber so that the |
638 |
# still need to record the matched biblionumber so that the |
574 |
# items can be reverted |
639 |
# items can be reverted |
575 |
my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"); |
640 |
my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"); |
576 |
$sth2->execute($biblionumber, $rowref->{'import_record_id'}); |
641 |
$sth2->execute($recordid, $rowref->{'import_record_id'}); |
577 |
SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied'); |
642 |
SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied'); |
578 |
} |
643 |
} |
579 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'ignored'); |
644 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'ignored'); |
Lines 632-693
sub BatchCommitItems {
Link Here
|
632 |
return ($num_items_added, $num_items_errored); |
697 |
return ($num_items_added, $num_items_errored); |
633 |
} |
698 |
} |
634 |
|
699 |
|
635 |
=head2 BatchRevertBibRecords |
700 |
=head2 BatchRevertRecords |
636 |
|
701 |
|
637 |
my ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, |
702 |
my ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, |
638 |
$num_ignored) = BatchRevertBibRecords($batch_id); |
703 |
$num_ignored) = BatchRevertRecords($batch_id); |
639 |
|
704 |
|
640 |
=cut |
705 |
=cut |
641 |
|
706 |
|
642 |
sub BatchRevertBibRecords { |
707 |
sub BatchRevertRecords { |
643 |
my $batch_id = shift; |
708 |
my $batch_id = shift; |
644 |
|
709 |
|
|
|
710 |
my $record_type; |
645 |
my $num_deleted = 0; |
711 |
my $num_deleted = 0; |
646 |
my $num_errors = 0; |
712 |
my $num_errors = 0; |
647 |
my $num_reverted = 0; |
713 |
my $num_reverted = 0; |
648 |
my $num_items_deleted = 0; |
|
|
649 |
my $num_ignored = 0; |
714 |
my $num_ignored = 0; |
|
|
715 |
my $num_items_deleted = 0; |
650 |
# commit (i.e., save, all records in the batch) |
716 |
# commit (i.e., save, all records in the batch) |
651 |
# FIXME biblio only at the moment |
|
|
652 |
SetImportBatchStatus('reverting'); |
717 |
SetImportBatchStatus('reverting'); |
653 |
my $overlay_action = GetImportBatchOverlayAction($batch_id); |
718 |
my $overlay_action = GetImportBatchOverlayAction($batch_id); |
654 |
my $nomatch_action = GetImportBatchNoMatchAction($batch_id); |
719 |
my $nomatch_action = GetImportBatchNoMatchAction($batch_id); |
655 |
my $dbh = C4::Context->dbh; |
720 |
my $dbh = C4::Context->dbh; |
656 |
my $sth = $dbh->prepare("SELECT import_record_id, status, overlay_status, marcxml_old, encoding, matched_biblionumber |
721 |
my $sth = $dbh->prepare("SELECT import_records.import_record_id, record_type, status, overlay_status, marcxml_old, encoding, matched_biblionumber, matched_authid |
657 |
FROM import_records |
722 |
FROM import_records |
658 |
JOIN import_biblios USING (import_record_id) |
723 |
LEFT JOIN import_auths ON (import_records.import_record_id=import_auths.import_record_id) |
|
|
724 |
LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id) |
659 |
WHERE import_batch_id = ?"); |
725 |
WHERE import_batch_id = ?"); |
660 |
$sth->execute($batch_id); |
726 |
$sth->execute($batch_id); |
661 |
while (my $rowref = $sth->fetchrow_hashref) { |
727 |
while (my $rowref = $sth->fetchrow_hashref) { |
|
|
728 |
$record_type = $rowref->{'record_type'}; |
662 |
if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'reverted') { |
729 |
if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'reverted') { |
663 |
$num_ignored++; |
730 |
$num_ignored++; |
664 |
next; |
731 |
next; |
665 |
} |
732 |
} |
666 |
|
733 |
|
667 |
my $bib_result = _get_revert_action($overlay_action, $rowref->{'overlay_status'}, $rowref->{'status'}); |
734 |
my $record_result = _get_revert_action($overlay_action, $rowref->{'overlay_status'}, $rowref->{'status'}); |
668 |
|
735 |
|
669 |
if ($bib_result eq 'delete') { |
736 |
if ($record_result eq 'delete') { |
670 |
$num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'}); |
737 |
my $error = undef; |
671 |
my $error = DelBiblio($rowref->{'matched_biblionumber'}); |
738 |
if ($record_type eq 'biblio') { |
|
|
739 |
$num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'}); |
740 |
$error = DelBiblio($rowref->{'matched_biblionumber'}); |
741 |
} else { |
742 |
my $deletedauthid = DelAuthority($rowref->{'matched_authid'}); |
743 |
} |
672 |
if (defined $error) { |
744 |
if (defined $error) { |
673 |
$num_errors++; |
745 |
$num_errors++; |
674 |
} else { |
746 |
} else { |
675 |
$num_deleted++; |
747 |
$num_deleted++; |
676 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted'); |
748 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted'); |
677 |
} |
749 |
} |
678 |
} elsif ($bib_result eq 'restore') { |
750 |
} elsif ($record_result eq 'restore') { |
679 |
$num_reverted++; |
751 |
$num_reverted++; |
680 |
my $old_record = MARC::Record->new_from_xml(StripNonXmlChars($rowref->{'marcxml_old'}), 'UTF-8', $rowref->{'encoding'}); |
752 |
my $old_record = MARC::Record->new_from_xml(StripNonXmlChars($rowref->{'marcxml_old'}), 'UTF-8', $rowref->{'encoding'}); |
681 |
my $biblionumber = $rowref->{'matched_biblionumber'}; |
753 |
if ($record_type eq 'biblio') { |
682 |
my ($count, $oldbiblio) = GetBiblio($biblionumber); |
754 |
my $biblionumber = $rowref->{'matched_biblionumber'}; |
683 |
$num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'}); |
755 |
my ($count, $oldbiblio) = GetBiblio($biblionumber); |
684 |
ModBiblio($old_record, $biblionumber, $oldbiblio->{'frameworkcode'}); |
756 |
$num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'}); |
|
|
757 |
ModBiblio($old_record, $biblionumber, $oldbiblio->{'frameworkcode'}); |
758 |
} else { |
759 |
my $authid = $rowref->{'matched_authid'}; |
760 |
ModAuthority($authid, $old_record, GuessAuthTypeCode($old_record)); |
761 |
} |
685 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted'); |
762 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted'); |
686 |
} elsif ($bib_result eq 'ignore') { |
763 |
} elsif ($record_result eq 'ignore') { |
687 |
$num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'}); |
764 |
if ($record_type eq 'biblio') { |
|
|
765 |
$num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'}); |
766 |
} |
688 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted'); |
767 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted'); |
689 |
} |
768 |
} |
690 |
my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = NULL WHERE import_record_id = ?"); |
769 |
my $query; |
|
|
770 |
if ($record_type eq 'biblio') { |
771 |
$query = "UPDATE import_biblios SET matched_biblionumber = NULL WHERE import_record_id = ?"; |
772 |
} else { |
773 |
$query = "UPDATE import_auths SET matched_authid = NULL WHERE import_record_id = ?"; |
774 |
} |
775 |
my $sth2 = $dbh->prepare_cached($query); |
691 |
$sth2->execute($rowref->{'import_record_id'}); |
776 |
$sth2->execute($rowref->{'import_record_id'}); |
692 |
} |
777 |
} |
693 |
|
778 |
|
Lines 1305-1330
sub _update_batch_record_counts {
Link Here
|
1305 |
} |
1390 |
} |
1306 |
|
1391 |
|
1307 |
sub _get_commit_action { |
1392 |
sub _get_commit_action { |
1308 |
my ($overlay_action, $nomatch_action, $item_action, $overlay_status, $import_record_id) = @_; |
1393 |
my ($overlay_action, $nomatch_action, $item_action, $overlay_status, $import_record_id, $record_type) = @_; |
1309 |
|
1394 |
|
1310 |
my ($bib_result, $bib_match, $item_result); |
1395 |
if ($record_type eq 'biblio') { |
1311 |
|
1396 |
my ($bib_result, $bib_match, $item_result); |
1312 |
if ($overlay_status ne 'no_match') { |
1397 |
|
1313 |
$bib_match = GetBestRecordMatch($import_record_id); |
1398 |
if ($overlay_status ne 'no_match') { |
1314 |
if ($overlay_action eq 'replace') { |
1399 |
$bib_match = GetBestRecordMatch($import_record_id); |
1315 |
$bib_result = defined($bib_match) ? 'replace' : 'create_new'; |
1400 |
if ($overlay_action eq 'replace') { |
1316 |
} elsif ($overlay_action eq 'create_new') { |
1401 |
$bib_result = defined($bib_match) ? 'replace' : 'create_new'; |
1317 |
$bib_result = 'create_new'; |
1402 |
} elsif ($overlay_action eq 'create_new') { |
1318 |
} elsif ($overlay_action eq 'ignore') { |
1403 |
$bib_result = 'create_new'; |
1319 |
$bib_result = 'ignore'; |
1404 |
} elsif ($overlay_action eq 'ignore') { |
1320 |
} |
1405 |
$bib_result = 'ignore'; |
1321 |
$item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_matches') ? 'create_new' : 'ignore'; |
1406 |
} |
1322 |
} else { |
1407 |
$item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_matches') ? 'create_new' : 'ignore'; |
1323 |
$bib_result = $nomatch_action; |
1408 |
} else { |
1324 |
$item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_new') ? 'create_new' : 'ignore'; |
1409 |
$bib_result = $nomatch_action; |
1325 |
} |
1410 |
$item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_new') ? 'create_new' : 'ignore'; |
|
|
1411 |
} |
1412 |
return ($bib_result, $item_result, $bib_match); |
1413 |
} else { # must be auths |
1414 |
my ($auth_result, $auth_match); |
1415 |
|
1416 |
if ($overlay_status ne 'no_match') { |
1417 |
$auth_match = GetBestRecordMatch($import_record_id); |
1418 |
if ($overlay_action eq 'replace') { |
1419 |
$auth_result = defined($auth_match) ? 'replace' : 'create_new'; |
1420 |
} elsif ($overlay_action eq 'create_new') { |
1421 |
$auth_result = 'create_new'; |
1422 |
} elsif ($overlay_action eq 'ignore') { |
1423 |
$auth_result = 'ignore'; |
1424 |
} |
1425 |
} else { |
1426 |
$auth_result = $nomatch_action; |
1427 |
} |
1428 |
|
1429 |
return ($auth_result, undef, $auth_match); |
1326 |
|
1430 |
|
1327 |
return ($bib_result, $item_result, $bib_match); |
1431 |
} |
1328 |
} |
1432 |
} |
1329 |
|
1433 |
|
1330 |
sub _get_revert_action { |
1434 |
sub _get_revert_action { |