From: Mason James Date: Wed, 31 Oct 2007 08:44:46 +0000 (-0500) Subject: fix for 1521, boolean test for 'autobarcode' syspref fixed, and test for non-existant... X-Git-Tag: v3.00.00-alpha~1159 X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=58dfd9c18e22afba6dde651cb2ca154a8e631c58;p=koha.git 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 --- 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