|
Lines 35-40
use C4::Charset qw( MarcToUTF8Record SetUTF8Flag StripNonXmlChars );
Link Here
|
| 35 |
use C4::AuthoritiesMarc qw( AddAuthority GuessAuthTypeCode GetAuthorityXML ModAuthority DelAuthority ); |
35 |
use C4::AuthoritiesMarc qw( AddAuthority GuessAuthTypeCode GetAuthorityXML ModAuthority DelAuthority ); |
| 36 |
use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate ); |
36 |
use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate ); |
| 37 |
use Koha::Items; |
37 |
use Koha::Items; |
|
|
38 |
use Koha::SearchEngine; |
| 39 |
use Koha::SearchEngine::Indexer; |
| 38 |
use Koha::Plugins::Handler; |
40 |
use Koha::Plugins::Handler; |
| 39 |
use Koha::Logger; |
41 |
use Koha::Logger; |
| 40 |
|
42 |
|
|
Lines 582-587
sub BatchCommitRecords {
Link Here
|
| 582 |
my $logged_in_patron = Koha::Patrons->find( $userenv->{number} ); |
584 |
my $logged_in_patron = Koha::Patrons->find( $userenv->{number} ); |
| 583 |
|
585 |
|
| 584 |
my $rec_num = 0; |
586 |
my $rec_num = 0; |
|
|
587 |
my @biblionumbers; |
| 585 |
while (my $rowref = $sth->fetchrow_hashref) { |
588 |
while (my $rowref = $sth->fetchrow_hashref) { |
| 586 |
$record_type = $rowref->{'record_type'}; |
589 |
$record_type = $rowref->{'record_type'}; |
| 587 |
$rec_num++; |
590 |
$rec_num++; |
|
Lines 621-627
sub BatchCommitRecords {
Link Here
|
| 621 |
$num_added++; |
624 |
$num_added++; |
| 622 |
if ($record_type eq 'biblio') { |
625 |
if ($record_type eq 'biblio') { |
| 623 |
my $biblioitemnumber; |
626 |
my $biblioitemnumber; |
| 624 |
($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework); |
627 |
( $recordid, $biblioitemnumber ) = AddBiblio( $marc_record, $framework, { skip_record_index => 1 } ); |
| 625 |
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead |
628 |
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead |
| 626 |
if ($item_result eq 'create_new' || $item_result eq 'replace') { |
629 |
if ($item_result eq 'create_new' || $item_result eq 'replace') { |
| 627 |
my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result, $biblioitemnumber); |
630 |
my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result, $biblioitemnumber); |
|
Lines 661-667
sub BatchCommitRecords {
Link Here
|
| 661 |
} |
664 |
} |
| 662 |
|
665 |
|
| 663 |
ModBiblio($marc_record, $recordid, $oldbiblio->frameworkcode, { |
666 |
ModBiblio($marc_record, $recordid, $oldbiblio->frameworkcode, { |
| 664 |
overlay_context => $context |
667 |
overlay_context => $context, |
|
|
668 |
skip_record_index => 1, |
| 665 |
}); |
669 |
}); |
| 666 |
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead |
670 |
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead |
| 667 |
|
671 |
|
|
Lines 701-709
sub BatchCommitRecords {
Link Here
|
| 701 |
} |
705 |
} |
| 702 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'ignored'); |
706 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'ignored'); |
| 703 |
} |
707 |
} |
|
|
708 |
push @biblionumbers, $recordid if $record_type eq 'biblio'; |
| 704 |
} |
709 |
} |
| 705 |
$sth->finish(); |
710 |
$sth->finish(); |
| 706 |
SetImportBatchStatus($batch_id, 'imported'); |
711 |
SetImportBatchStatus($batch_id, 'imported'); |
|
|
712 |
|
| 713 |
if ( @biblionumbers ) { |
| 714 |
my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); |
| 715 |
$indexer->index_records( \@biblionumbers, "specialUpdate", "biblioserver" ); |
| 716 |
} |
| 717 |
|
| 707 |
return ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored); |
718 |
return ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored); |
| 708 |
} |
719 |
} |
| 709 |
|
720 |
|
|
Lines 748-754
sub BatchCommitItems {
Link Here
|
| 748 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?"); |
759 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?"); |
| 749 |
if ( $action eq "replace" && $duplicate_itemnumber ) { |
760 |
if ( $action eq "replace" && $duplicate_itemnumber ) { |
| 750 |
# Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying |
761 |
# Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying |
| 751 |
ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber} ); |
762 |
ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber}, { skip_record_index => 1 } ); |
| 752 |
$updsth->bind_param( 1, 'imported' ); |
763 |
$updsth->bind_param( 1, 'imported' ); |
| 753 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
764 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
| 754 |
$updsth->bind_param( 3, undef ); |
765 |
$updsth->bind_param( 3, undef ); |
|
Lines 758-764
sub BatchCommitItems {
Link Here
|
| 758 |
$num_items_replaced++; |
769 |
$num_items_replaced++; |
| 759 |
} elsif ( $action eq "replace" && $duplicate_barcode ) { |
770 |
} elsif ( $action eq "replace" && $duplicate_barcode ) { |
| 760 |
my $itemnumber = $duplicate_barcode->itemnumber; |
771 |
my $itemnumber = $duplicate_barcode->itemnumber; |
| 761 |
ModItemFromMarc( $item_marc, $biblionumber, $itemnumber ); |
772 |
ModItemFromMarc( $item_marc, $biblionumber, $itemnumber, { skip_record_index => 1 } ); |
| 762 |
$updsth->bind_param( 1, 'imported' ); |
773 |
$updsth->bind_param( 1, 'imported' ); |
| 763 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
774 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
| 764 |
$updsth->bind_param( 3, undef ); |
775 |
$updsth->bind_param( 3, undef ); |
|
Lines 778-784
sub BatchCommitItems {
Link Here
|
| 778 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" ); |
789 |
my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" ); |
| 779 |
$item_marc->field($itemtag)->delete_subfield( code => $itemsubfield ); |
790 |
$item_marc->field($itemtag)->delete_subfield( code => $itemsubfield ); |
| 780 |
|
791 |
|
| 781 |
my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber, {biblioitemnumber => $biblioitemnumber} ); |
792 |
my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber, { biblioitemnumber => $biblioitemnumber, skip_record_index => 1 } ); |
| 782 |
if( $itemnumber ) { |
793 |
if( $itemnumber ) { |
| 783 |
$updsth->bind_param( 1, 'imported' ); |
794 |
$updsth->bind_param( 1, 'imported' ); |
| 784 |
$updsth->bind_param( 2, $itemnumber ); |
795 |
$updsth->bind_param( 2, $itemnumber ); |
|
Lines 827-832
sub BatchRevertRecords {
Link Here
|
| 827 |
$sth->execute($batch_id); |
838 |
$sth->execute($batch_id); |
| 828 |
my $marc_type; |
839 |
my $marc_type; |
| 829 |
my $marcflavour = C4::Context->preference('marcflavour'); |
840 |
my $marcflavour = C4::Context->preference('marcflavour'); |
|
|
841 |
my ( @deleted_biblionumbers, @updated_biblionumbers ); |
| 830 |
while (my $rowref = $sth->fetchrow_hashref) { |
842 |
while (my $rowref = $sth->fetchrow_hashref) { |
| 831 |
$record_type = $rowref->{'record_type'}; |
843 |
$record_type = $rowref->{'record_type'}; |
| 832 |
if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'reverted') { |
844 |
if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'reverted') { |
|
Lines 847-853
sub BatchRevertRecords {
Link Here
|
| 847 |
my $error = undef; |
859 |
my $error = undef; |
| 848 |
if ($record_type eq 'biblio') { |
860 |
if ($record_type eq 'biblio') { |
| 849 |
$num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'}); |
861 |
$num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'}); |
| 850 |
$error = DelBiblio($rowref->{'matched_biblionumber'}); |
862 |
$error = DelBiblio($rowref->{'matched_biblionumber'}, { skip_record_index => 1 } ); |
|
|
863 |
push @deleted_biblionumbers, $rowref->{'matched_biblionumber'}; |
| 851 |
} else { |
864 |
} else { |
| 852 |
DelAuthority({ authid => $rowref->{'matched_authid'} }); |
865 |
DelAuthority({ authid => $rowref->{'matched_authid'} }); |
| 853 |
} |
866 |
} |
|
Lines 868-874
sub BatchRevertRecords {
Link Here
|
| 868 |
next unless $oldbiblio; # Record has since been deleted. Deleted records should stay deleted. |
881 |
next unless $oldbiblio; # Record has since been deleted. Deleted records should stay deleted. |
| 869 |
|
882 |
|
| 870 |
$num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'}); |
883 |
$num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'}); |
| 871 |
ModBiblio($old_record, $biblionumber, $oldbiblio->frameworkcode); |
884 |
ModBiblio($old_record, $biblionumber, $oldbiblio->frameworkcode, { skip_record_index => 1 }); |
|
|
885 |
push @updated_biblionumbers, $biblionumber; |
| 872 |
} else { |
886 |
} else { |
| 873 |
my $authid = $rowref->{'matched_authid'}; |
887 |
my $authid = $rowref->{'matched_authid'}; |
| 874 |
ModAuthority($authid, $old_record, GuessAuthTypeCode($old_record)); |
888 |
ModAuthority($authid, $old_record, GuessAuthTypeCode($old_record)); |
|
Lines 877-882
sub BatchRevertRecords {
Link Here
|
| 877 |
} elsif ($record_result eq 'ignore') { |
891 |
} elsif ($record_result eq 'ignore') { |
| 878 |
if ($record_type eq 'biblio') { |
892 |
if ($record_type eq 'biblio') { |
| 879 |
$num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'}); |
893 |
$num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'}); |
|
|
894 |
push @updated_biblionumbers, $rowref->{'matched_biblionumber'}; |
| 880 |
} |
895 |
} |
| 881 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted'); |
896 |
SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted'); |
| 882 |
} |
897 |
} |
|
Lines 892-897
sub BatchRevertRecords {
Link Here
|
| 892 |
$sth2->execute($rowref->{'import_record_id'}); |
907 |
$sth2->execute($rowref->{'import_record_id'}); |
| 893 |
} |
908 |
} |
| 894 |
|
909 |
|
|
|
910 |
if ( $record_type eq 'biblio' && ( @updated_biblionumbers || @deleted_biblionumbers ) ) { |
| 911 |
my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); |
| 912 |
if ( @deleted_biblionumbers ) { |
| 913 |
$indexer->index_records( \@deleted_biblionumbers, "recordDelete", "biblioserver" ); |
| 914 |
} else { |
| 915 |
$indexer->index_records( \@updated_biblionumbers, "specialUpdate", "biblioserver" ); |
| 916 |
} |
| 917 |
} |
| 918 |
|
| 895 |
$sth->finish(); |
919 |
$sth->finish(); |
| 896 |
SetImportBatchStatus($batch_id, 'reverted'); |
920 |
SetImportBatchStatus($batch_id, 'reverted'); |
| 897 |
return ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored); |
921 |
return ($num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored); |
|
Lines 917-923
sub BatchRevertItems {
Link Here
|
| 917 |
$sth->execute(); |
941 |
$sth->execute(); |
| 918 |
while (my $row = $sth->fetchrow_hashref()) { |
942 |
while (my $row = $sth->fetchrow_hashref()) { |
| 919 |
my $item = Koha::Items->find($row->{itemnumber}); |
943 |
my $item = Koha::Items->find($row->{itemnumber}); |
| 920 |
if ($item->safe_delete){ |
944 |
if ($item->safe_delete({ skip_record_index => 1 })){ |
| 921 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ? WHERE import_items_id = ?"); |
945 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ? WHERE import_items_id = ?"); |
| 922 |
$updsth->bind_param(1, 'reverted'); |
946 |
$updsth->bind_param(1, 'reverted'); |
| 923 |
$updsth->bind_param(2, $row->{'import_items_id'}); |
947 |
$updsth->bind_param(2, $row->{'import_items_id'}); |
| 924 |
- |
|
|