fix for 1521, boolean test for 'autobarcode' syspref fixed, and test for non-existant...
authorMason James <mtj@liblime.com>
Wed, 31 Oct 2007 08:44:46 +0000 (03:44 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Wed, 31 Oct 2007 10:58:14 +0000 (05:58 -0500)
Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
serials/serials-edit.pl

index 016b6a7..b1299be 100755 (executable)
@@ -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