Browse Source

warn on attempts to add duplicate item barcodes during batch import

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
3.0.x
Galen Charlton 17 years ago
committed by Joshua Ferraro
parent
commit
ad4e02f91d
  1. 46
      C4/ImportBatch.pm
  2. 1
      koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tmpl
  3. 7
      misc/commit_biblios_file.pl
  4. 11
      misc/migration_tools/bulkmarcimport.pl
  5. 4
      tools/manage-marc-import.pl

46
C4/ImportBatch.pm

@ -412,7 +412,7 @@ sub BatchFindBibDuplicates {
=over 4
my ($num_added, $num_updated, $num_items_added, $num_ignored) =
my ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored) =
BatchCommitBibRecords($batch_id, $progress_interval, $progress_callback);
=back
@ -436,6 +436,7 @@ sub BatchCommitBibRecords {
my $num_added = 0;
my $num_updated = 0;
my $num_items_added = 0;
my $num_items_errored = 0;
my $num_ignored = 0;
# commit (i.e., save, all records in the batch)
# FIXME biblio only at the moment
@ -464,7 +465,9 @@ sub BatchCommitBibRecords {
my $sth = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?");
$sth->execute($biblionumber, $rowref->{'import_record_id'});
$sth->finish();
$num_items_added += BatchCommitItems($rowref->{'import_record_id'}, $biblionumber);
my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $biblionumber);
$num_items_added += $bib_items_added;
$num_items_errored += $bib_items_errored;
SetImportRecordStatus($rowref->{'import_record_id'}, 'imported');
} else {
$num_updated++;
@ -487,21 +490,23 @@ sub BatchCommitBibRecords {
my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?");
$sth2->execute($biblionumber, $rowref->{'import_record_id'});
$sth2->finish();
$num_items_added += BatchCommitItems($rowref->{'import_record_id'}, $biblionumber);
my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $biblionumber);
$num_items_added += $bib_items_added;
$num_items_errored += $bib_items_errored;
SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied');
SetImportRecordStatus($rowref->{'import_record_id'}, 'imported');
}
}
$sth->finish();
SetImportBatchStatus($batch_id, 'imported');
return ($num_added, $num_updated, $num_items_added, $num_ignored);
return ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored);
}
=head2 BatchCommitItems
=over 4
$num_items_added = BatchCommitItems($import_record_id, $biblionumber);
($num_items_added, $num_items_errored) = BatchCommitItems($import_record_id, $biblionumber);
=back
@ -513,6 +518,7 @@ sub BatchCommitItems {
my $dbh = C4::Context->dbh;
my $num_items_added = 0;
my $num_items_errored = 0;
my $sth = $dbh->prepare("SELECT import_items_id, import_items.marcxml, encoding
FROM import_items
JOIN import_records USING (import_record_id)
@ -522,17 +528,29 @@ sub BatchCommitItems {
$sth->execute();
while (my $row = $sth->fetchrow_hashref()) {
my $item_marc = MARC::Record->new_from_xml($row->{'marcxml'}, 'UTF-8', $row->{'encoding'});
my ($item_biblionumber, $biblionumber, $itemnumber) = AddItem($item_marc, $biblionumber);
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
$updsth->bind_param(1, 'imported');
$updsth->bind_param(2, $itemnumber);
$updsth->bind_param(3, $row->{'import_items_id'});
$updsth->execute();
$updsth->finish();
$num_items_added++;
# FIXME - duplicate barcode check needs to become part of AddItem()
my $item = TransformMarcToKoha($dbh, $item_marc);
my $duplicate_barcode = exists($item->{'barcode'}) && GetItemnumberFromBarcode($item->{'barcode'});
if ($duplicate_barcode) {
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, import_error = ? WHERE import_items_id = ?");
$updsth->bind_param(1, 'error');
$updsth->bind_param(2, 'duplicate item barcode');
$updsth->bind_param(3, $row->{'import_items_id'});
$updsth->execute();
$num_items_errored++;
} else {
my ($item_biblionumber, $biblioitemnumber, $itemnumber) = AddItem($item_marc, $biblionumber);
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
$updsth->bind_param(1, 'imported');
$updsth->bind_param(2, $itemnumber);
$updsth->bind_param(3, $row->{'import_items_id'});
$updsth->execute();
$updsth->finish();
$num_items_added++;
}
}
$sth->finish();
return $num_items_added;
return ($num_items_added, $num_items_errored);
}
=head2 BatchRevertBibRecords

1
koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tmpl

@ -98,6 +98,7 @@
<tr><td>Number of records added</td><td><!-- TMPL_VAR name="num_added" --></td></tr>
<tr><td>Number of records updated</td><td><!-- TMPL_VAR name="num_updated" --></td></tr>
<tr><td>Number of items added</td><td><!-- TMPL_VAR name="num_items_added" --></td></tr>
<tr><td>Number of items ignored because of duplicate barcode</td><td><!-- TMPL_VAR name="num_items_errored" --></td></tr>
<tr><td>Number of records ignored</td><td><!-- TMPL_VAR name="num_ignored" --></td></tr>
</table>
<!-- /TMPL_IF -->

7
misc/commit_biblios_file.pl

@ -64,7 +64,8 @@ sub process_batch {
my ($import_batch_id) = @_;
print "... importing MARC records -- please wait\n";
my ($num_added, $num_updated, $num_items_added, $num_ignored) = BatchCommitBibRecords($import_batch_id, 100, \&print_progress);
my ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored) =
BatchCommitBibRecords($import_batch_id, 100, \&print_progress);
print "... finished importing MARC records\n";
print <<_SUMMARY_;
@ -76,6 +77,10 @@ Number of new bibs added: $num_added
Number of bibs replaced: $num_updated
Number of bibs ignored: $num_ignored
Number of items added: $num_items_added
Number of items ignored: $num_items_errored
Note: an item is ignored if its barcode is a
duplicate of one already in the database.
_SUMMARY_
}

11
misc/migration_tools/bulkmarcimport.pl

@ -304,8 +304,15 @@ while ( my $record = $batch->next() ) {
} else {
warn "ADDED biblio NB $bibid in DB\n" if $verbose;
for ( my $it = 0 ; $it <= $#items ; $it++ ) {
eval { AddItem( $items[$it], $bibid, $oldbibitemnum ); };
warn "ERROR: Adding item $it, rec $i failed\n" if ($@);
# FIXME - duplicate barcode check needs to become part of AddItem()
my $itemhash = TransformMarcToKoha($dbh, $items[$it]);
my $duplicate_barcode = exists($itemhash->{'barcode'}) && GetItemnumberFromBarcode($itemhash->{'barcode'});
if ($duplicate_barcode) {
warn "ERROR: cannot add item $itemhash->{'barcode'} for biblio $bibid: duplicate barcode\n" if $verbose;
} else {
eval { AddItem( $items[$it], $bibid, $oldbibitemnum ); };
warn "ERROR: Adding item $it, rec $i failed\n" if ($@);
}
}
}
}

4
tools/manage-marc-import.pl

@ -157,13 +157,15 @@ sub commit_batch {
$job = put_in_background($import_batch_id);
$callback = progress_callback($job);
}
my ($num_added, $num_updated, $num_items_added, $num_ignored) = BatchCommitBibRecords($import_batch_id, 50, $callback);
my ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored) =
BatchCommitBibRecords($import_batch_id, 50, $callback);
my $results = {
did_commit => 1,
num_added => $num_added,
num_updated => $num_updated,
num_items_added => $num_items_added,
num_items_errored => $num_items_errored,
num_ignored => $num_ignored
};
if ($runinbackground) {

Loading…
Cancel
Save