Lines 683-737
sub BatchCommitRecords {
Link Here
|
683 |
=cut |
683 |
=cut |
684 |
|
684 |
|
685 |
sub BatchCommitItems { |
685 |
sub BatchCommitItems { |
686 |
my ($import_record_id, $biblionumber, $action) = @_; |
686 |
my ( $import_record_id, $biblionumber, $action ) = @_; |
687 |
|
687 |
|
688 |
my $dbh = C4::Context->dbh; |
688 |
my $dbh = C4::Context->dbh; |
689 |
|
689 |
|
690 |
my ($num_items_added, $num_items_errored, $num_items_replaced) = 0; |
690 |
my ( $num_items_added, $num_items_errored, $num_items_replaced ) = 0; |
691 |
my $sth = $dbh->prepare("SELECT import_items_id, import_items.marcxml, encoding |
691 |
my $sth = $dbh->prepare(" |
692 |
FROM import_items |
692 |
SELECT import_items_id, import_items.marcxml, encoding |
693 |
JOIN import_records USING (import_record_id) |
693 |
FROM import_items |
694 |
WHERE import_record_id = ? |
694 |
JOIN import_records USING (import_record_id) |
695 |
ORDER BY import_items_id"); |
695 |
WHERE import_record_id = ? |
696 |
$sth->bind_param(1, $import_record_id); |
696 |
ORDER BY import_items_id |
|
|
697 |
"); |
698 |
$sth->bind_param( 1, $import_record_id ); |
697 |
$sth->execute(); |
699 |
$sth->execute(); |
698 |
while (my $row = $sth->fetchrow_hashref()) { |
700 |
while ( my $row = $sth->fetchrow_hashref() ) { |
699 |
my $item_marc = MARC::Record->new_from_xml(StripNonXmlChars($row->{'marcxml'}), 'UTF-8', $row->{'encoding'}); |
701 |
my $item_marc = MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} ); |
700 |
#delete date_due subfield as to not accidentally delete item checkout due dates |
702 |
|
701 |
my ($MARCfield,$MARCsubfield) = GetMarcFromKohaField('items.onloan', GetFrameworkCode($biblionumber)); |
703 |
#delete date_due subfield as to not accidentally delete item checkout due dates |
702 |
$item_marc->field($MARCfield)->delete_subfield(code => $MARCsubfield); |
704 |
my ( $MARCfield, $MARCsubfield ) = GetMarcFromKohaField( 'items.onloan', GetFrameworkCode($biblionumber) ); |
703 |
# FIXME - duplicate barcode check needs to become part of AddItemFromMarc() |
705 |
$item_marc->field($MARCfield)->delete_subfield( code => $MARCsubfield ); |
704 |
my $item = TransformMarcToKoha($dbh, $item_marc); |
706 |
|
705 |
my $duplicate_barcode = exists($item->{'barcode'}) && GetItemnumberFromBarcode($item->{'barcode'}); |
707 |
my $item = TransformMarcToKoha( $dbh, $item_marc ); |
706 |
my $duplicate_itemnumber = exists($item->{'itemnumber'}); |
708 |
|
707 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?"); |
709 |
my $duplicate_barcode = exists( $item->{'barcode'} ) && GetItemnumberFromBarcode( $item->{'barcode'} ); |
708 |
if($action eq "replace" && $duplicate_itemnumber){ |
710 |
my $duplicate_itemnumber = exists( $item->{'itemnumber'} ); |
709 |
ModItemFromMarc($item_marc, $biblionumber, $item->{itemnumber}); |
711 |
|
710 |
$updsth->bind_param(1, 'imported'); |
712 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?"); |
711 |
$updsth->bind_param(2, $item->{itemnumber}); |
713 |
if ( $action eq "replace" && $duplicate_itemnumber ) { |
712 |
$updsth->bind_param(3, $row->{'import_items_id'}); |
714 |
ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber} ); |
|
|
715 |
$updsth->bind_param( 1, 'imported' ); |
716 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
717 |
$updsth->bind_param( 3, $row->{'import_items_id'} ); |
713 |
$updsth->execute(); |
718 |
$updsth->execute(); |
714 |
$updsth->finish(); |
719 |
$updsth->finish(); |
715 |
$num_items_replaced++; |
720 |
$num_items_replaced++; |
716 |
} |
721 |
} elsif ($duplicate_barcode) { |
717 |
elsif ($duplicate_barcode) { |
722 |
$updsth->bind_param( 1, 'error' ); |
718 |
$updsth->bind_param(1, 'error'); |
723 |
$updsth->bind_param( 2, 'duplicate item barcode' ); |
719 |
$updsth->bind_param(2, 'duplicate item barcode'); |
724 |
$updsth->bind_param( 3, $row->{'import_items_id'} ); |
720 |
$updsth->bind_param(3, $row->{'import_items_id'}); |
|
|
721 |
$updsth->execute(); |
725 |
$updsth->execute(); |
722 |
$num_items_errored++; |
726 |
$num_items_errored++; |
723 |
} else { |
727 |
} else { |
724 |
my ($item_biblionumber, $biblioitemnumber, $itemnumber) = AddItemFromMarc($item_marc, $biblionumber); |
728 |
my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber ); |
725 |
$updsth->bind_param(1, 'imported'); |
729 |
$updsth->bind_param( 1, 'imported' ); |
726 |
$updsth->bind_param(2, $itemnumber); |
730 |
$updsth->bind_param( 2, $itemnumber ); |
727 |
$updsth->bind_param(3, $row->{'import_items_id'}); |
731 |
$updsth->bind_param( 3, $row->{'import_items_id'} ); |
728 |
$updsth->execute(); |
732 |
$updsth->execute(); |
729 |
$updsth->finish(); |
733 |
$updsth->finish(); |
730 |
$num_items_added++; |
734 |
$num_items_added++; |
731 |
} |
735 |
} |
732 |
} |
736 |
} |
733 |
$sth->finish(); |
737 |
|
734 |
return ($num_items_added, $num_items_replaced, $num_items_errored); |
738 |
return ( $num_items_added, $num_items_replaced, $num_items_errored ); |
735 |
} |
739 |
} |
736 |
|
740 |
|
737 |
=head2 BatchRevertRecords |
741 |
=head2 BatchRevertRecords |
738 |
- |
|
|