From 5eab203c4f896f423544cfb1db62c2e8ba1e04d5 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 5 Apr 2013 07:53:47 -0400 Subject: [PATCH] Bug 7131 - Followup 2 - Allow overlaying by barcode This patch adds the ability to overlay by either itemnumber, or barcode. Itemnumbers take precendence over barcodes, which allows us to batch update item barcodes with an overlay. --- C4/ImportBatch.pm | 20 ++++++++++++++++---- installer/data/mysql/updatedatabase.pl | 12 ++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 3f1ceab..f5d8842 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -654,8 +654,9 @@ sub BatchCommitRecords { SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied'); SetImportRecordStatus($rowref->{'import_record_id'}, 'imported'); } elsif ($record_result eq 'ignore') { + $recordid = $record_match; $num_ignored++; - if ($record_type eq 'biblio' and defined $recordid and $item_result eq 'create_new') { + if ($record_type eq 'biblio' and defined $recordid and ( $item_result eq 'create_new' || $item_result eq 'replace' ) ) { my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result); $num_items_added += $bib_items_added; $num_items_replaced += $bib_items_replaced; @@ -687,19 +688,20 @@ sub BatchCommitItems { my $dbh = C4::Context->dbh; my ( $num_items_added, $num_items_errored, $num_items_replaced ) = 0; - my $sth = $dbh->prepare(" + my $sth = $dbh->prepare( " SELECT import_items_id, import_items.marcxml, encoding FROM import_items JOIN import_records USING (import_record_id) WHERE import_record_id = ? ORDER BY import_items_id - "); + " ); $sth->bind_param( 1, $import_record_id ); $sth->execute(); + while ( my $row = $sth->fetchrow_hashref() ) { my $item_marc = MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} ); - #delete date_due subfield as to not accidentally delete item checkout due dates + # Delete date_due subfield as to not accidentally delete item checkout due dates my ( $MARCfield, $MARCsubfield ) = GetMarcFromKohaField( 'items.onloan', GetFrameworkCode($biblionumber) ); $item_marc->field($MARCfield)->delete_subfield( code => $MARCsubfield ); @@ -710,6 +712,7 @@ sub BatchCommitItems { my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?"); if ( $action eq "replace" && $duplicate_itemnumber ) { + # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber} ); $updsth->bind_param( 1, 'imported' ); $updsth->bind_param( 2, $item->{itemnumber} ); @@ -717,6 +720,15 @@ sub BatchCommitItems { $updsth->execute(); $updsth->finish(); $num_items_replaced++; + } elsif ( $action eq "replace" && $duplicate_barcode ) { + my $itemnumber = GetItemnumberFromBarcode( $item->{'barcode'} ); + ModItemFromMarc( $item_marc, $biblionumber, $itemnumber ); + $updsth->bind_param( 1, 'imported' ); + $updsth->bind_param( 2, $item->{itemnumber} ); + $updsth->bind_param( 3, $row->{'import_items_id'} ); + $updsth->execute(); + $updsth->finish(); + $num_items_replaced++; } elsif ($duplicate_barcode) { $updsth->bind_param( 1, 'error' ); $updsth->bind_param( 2, 'duplicate item barcode' ); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index bc8375a..dd68ff8 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6758,6 +6758,18 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.11.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do(" + ALTER TABLE `import_batches` + CHANGE `item_action` `item_action` + ENUM( 'always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore', 'replace' ) + NOT NULL DEFAULT 'always_add' + "); + print "Upgrade to $DBversion done (Bug 9498 - Update encoding for Norwegian sample Z39.50 servers)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) -- 1.7.2.5