MT2527 : Adds default empty value for branches when batch modifying items
authorMatthias Meusburger <matthias.meusburger@biblibre.com>
Wed, 10 Mar 2010 21:26:15 +0000 (22:26 +0100)
committerGalen Charlton <gmcharlt@gmail.com>
Fri, 30 Apr 2010 01:52:17 +0000 (21:52 -0400)
(so they are not modified by mistake)

Signed-off-by: Henri-Damien LAURENT <henridamien.laurent@biblibre.com>
Signed-off-by: Galen Charlton <gmcharlt@gmail.com>

tools/batchMod.pl

index f7e9557..4962607 100755 (executable)
@@ -87,9 +87,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")){
@@ -101,9 +102,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
@@ -182,6 +188,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');