From c6c2e7b619b2e3cb0f52ecb438146b17f6346730 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 14 Oct 2021 12:18:36 +0200 Subject: [PATCH] Bug 22204: Remove whitespaces in barcode before saving MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test plan: 1. Create an item with barcode "1" 2. Try to create an item with barcode " 1 " and verify that it is blocked 3. Create an item with barcode " XXXXX " and verify that it is saved without spaces in database: SELECT barcode FROM items WHERE barcode LIKE '%XXXXX%' Co-authored-by: Jérémy Breuillard --- cataloguing/additem.pl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index d3f9456db5..e309aacb60 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -84,6 +84,19 @@ sub get_item_from_barcode { return($result); } +sub _trim_barcode { + my ($record) = @_; + + my ($tagfield, $tagsubfield) = GetMarcFromKohaField('items.barcode'); + my $item_field = $record->field($tagfield); + my $barcode = $item_field->subfield($tagsubfield); + if ($barcode) { + $barcode =~ s/^\s+//; + $barcode =~ s/\s+$//; + $item_field->update($tagsubfield => $barcode); + } +} + # NOTE: This code is subject to change in the future with the implemenation of ajax based autobarcode code # NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript sub _increment_barcode { @@ -512,6 +525,8 @@ if ($op eq "additem") { $add_duplicate_submit = 1 if ($prefillitem); $justaddeditem = 1; + _trim_barcode($record); + # if autoBarcode is set to 'incremental', calculate barcode... if ( C4::Context->preference('autoBarcode') eq 'incremental' ) { $record = _increment_barcode($record, $frameworkcode); -- 2.20.1