[Koha-patches] [PATCH 33/55] MT2527 : Adds default empty value for branches when batch modifying items

Henri-Damien LAURENT henridamien.laurent at biblibre.com
Wed Mar 10 22:26:15 CET 2010


From: Matthias Meusburger <matthias.meusburger at biblibre.com>

(so they are not modified by mistake)

Signed-off-by: Henri-Damien LAURENT <henridamien.laurent at biblibre.com>
---
 tools/batchMod.pl |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/tools/batchMod.pl b/tools/batchMod.pl
index b421863..b8e7f74 100755
--- a/tools/batchMod.pl
+++ b/tools/batchMod.pl
@@ -86,9 +86,10 @@ if ($op eq "action") {
     my @ind_tag   = $input->param('ind_tag');
     my @indicator = $input->param('indicator');
 
-    my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
-    my $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
-    my $localitem = TransformMarcToKoha( $dbh, $marcitem, "", 'items' );
+    # Is there something to modify ?
+    # TODO : We shall use this var to warn the user in case no modification was done to the items
+    my $something_to_modify = scalar(grep {!/^$/} @values);
+    
     foreach my $itemnumber(@itemnumbers){
 	    my $itemdata=GetItem($itemnumber);
 	    if ($input->param("del")){
@@ -100,9 +101,14 @@ if ($op eq "action") {
 			push @not_deleted, { itemnumber => $itemdata->{'itemnumber'}, barcode => $itemdata->{'barcode'}, title => $itemdata->{'title'}, $return => 1 };
 		    }
 	    } else {
+		if ($something_to_modify) {
+		    my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
+		    my $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
+    		    my $localitem = TransformMarcToKoha( $dbh, $marcitem, "", 'items' );
 		    my $localmarcitem=Item2Marc($itemdata);
 		    UpdateMarcWith($marcitem,$localmarcitem);
 		    eval{my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($localmarcitem,$itemdata->{biblionumber},$itemnumber)};
+		}
 	    }
     }
     # If we have a reasonable amount of items, we display them
@@ -181,6 +187,11 @@ my $i=0;
 my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
 
 my $branches = GetBranchesLoop();  # build once ahead of time, instead of multiple times later.
+
+# Adding a default choice, in case the user does not want to modify the branch
+my @nochange_branch = { branchname => '', value => '', selected => 1 };
+unshift (@$branches, @nochange_branch);
+
 my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
 
 
-- 
1.6.3.3




More information about the Koha-patches mailing list