From 58dfd9c18e22afba6dde651cb2ca154a8e631c58 Mon Sep 17 00:00:00 2001 From: Mason James Date: Wed, 31 Oct 2007 03:44:46 -0500 Subject: [PATCH] fix for 1521, boolean test for 'autobarcode' syspref fixed, and test for non-existant $marc->field before barcode subfield add Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- serials/serials-edit.pl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/serials/serials-edit.pl b/serials/serials-edit.pl index 016b6a72df..b1299bea88 100755 --- a/serials/serials-edit.pl +++ b/serials/serials-edit.pl @@ -221,20 +221,21 @@ if ($op eq 'serialchangestatus') { my $record=MARC::Record::new_from_xml($xml, 'UTF-8'); if ($item=~/^N/){ #New Item + # if autoBarcode is ON, calculate barcode... my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode"); - if (C4::Boolean::true_p(C4::Context->preference("autoBarcode")) != 0 ) { + if (C4::Context->preference("autoBarcode") ne 'OFF' ) { - unless ($record->field($tagfield)->subfield($tagsubfield)) { + eval { $record->field($tagfield)->subfield($tagsubfield) }; + if ($@) { my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items"); $sth_barcode->execute; my ($newbarcode) = $sth_barcode->fetchrow; $newbarcode++; + # OK, we have the new barcode, now create the entry in MARC record - my $fieldItem = $record->field($tagfield); - $record->delete_field($fieldItem); - $fieldItem->add_subfields($tagsubfield => $newbarcode); - $record->insert_fields_ordered($fieldItem); + $record->add_fields( $tagfield, "1", "0", + $tagsubfield => $newbarcode ); } } # check for item barcode # being unique -- 2.39.5