Bug Fixing batchmod.pl
[koha.git] / tools / batchMod.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 use CGI;
22 use strict;
23 #use warnings; FIXME - Bug 2505
24 use C4::Auth;
25 use C4::Output;
26 use C4::Biblio;
27 use C4::Items;
28 use C4::Context;
29 use C4::Koha; # XXX subfield_is_koha_internal_p
30 use C4::Branch; # XXX subfield_is_koha_internal_p
31 use C4::BackgroundJob;
32 use C4::ClassSource;
33 use C4::Dates;
34 use C4::Debug;
35 use YAML;
36 use Switch;
37 use MARC::File::XML;
38
39 my $input = new CGI;
40 my $dbh = C4::Context->dbh;
41 my $error        = $input->param('error');
42 my @itemnumbers  = $input->param('itemnumber');
43 my $op           = $input->param('op');
44 my $del          = $input->param('del');
45 my $completedJobID = $input->param('completedJobID');
46 my $runinbackground = $input->param('runinbackground');
47
48
49 my $template_name;
50 my $template_flag;
51 if (!defined $op) {
52     $template_name = "tools/batchMod.tmpl";
53     $template_flag = { tools => '*' };
54 } else {
55     $template_name = ($del) ? "tools/batchMod-del.tmpl" : "tools/batchMod-edit.tmpl";
56     $template_flag = ($del) ? { tools => 'items_batchdel' }   : { tools => 'items_batchmod' };
57 }
58
59
60 my ($template, $loggedinuser, $cookie)
61     = get_template_and_user({template_name => $template_name,
62                  query => $input,
63                  type => "intranet",
64                  authnotrequired => 0,
65                  flagsrequired => $template_flag,
66                  });
67
68
69 my $today_iso = C4::Dates->today('iso');
70 $template->param(today_iso => $today_iso);
71 $template->param(del       => $del);
72
73 my $itemrecord;
74 my $nextop="";
75 my @errors; # store errors found while checking data BEFORE saving item.
76 my $items_display_hashref;
77 my $frameworkcode="";
78 my $tagslib = &GetMarcStructure(1,$frameworkcode);
79
80 my $deleted_items = 0;     # Numbers of deleted items
81 my $not_deleted_items = 0; # Numbers of items that could not be deleted
82 my @not_deleted;           # List of the itemnumbers that could not be deleted
83
84 my %cookies = parse CGI::Cookie($cookie);
85 my $sessionID = $cookies{'CGISESSID'}->value;
86 my $dbh = C4::Context->dbh;
87
88
89 #--- ----------------------------------------------------------------------------
90 if ($op eq "action") {
91 #-------------------------------------------------------------------------------
92     my @tags      = $input->param('tag');
93     my @subfields = $input->param('subfield');
94     my @values    = $input->param('field_value');
95     # build indicator hash.
96     my @ind_tag   = $input->param('ind_tag');
97     my @indicator = $input->param('indicator');
98
99     # Is there something to modify ?
100     # TODO : We shall use this var to warn the user in case no modification was done to the items
101     my $something_to_modify = scalar(grep {!/^$/} @values);
102
103     # Once the job is done
104     if ($completedJobID) {
105         # If we have a reasonable amount of items, we display them
106         if (scalar(@itemnumbers) <= 1000) {
107             $items_display_hashref=BuildItemsData(@itemnumbers);
108         } else {
109             # Else, we only display the barcode
110             my @simple_items_display = map {{ itemnumber => $_, barcode => (GetBarcodeFromItemnumber($_) or ""), biblionumber => (GetBiblionumberFromItemnumber($_) or "") }} @itemnumbers;
111             $template->param("simple_items_display" => \@simple_items_display);
112         }
113
114         # Setting the job as done
115         my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID);
116
117         # Calling the template
118         add_saved_job_results_to_template($template, $completedJobID);
119
120     # While the job is getting done
121     } else {
122
123         # Job size is the number of items we have to process
124         my $job_size = scalar(@itemnumbers);
125         my $job = undef;
126         $dbh->{AutoCommit} = 0;
127         my $callback = sub {};
128
129         # If we asked for background processing
130         if ($runinbackground) {
131             $job = put_in_background($job_size);
132             $callback = progress_callback($job, $dbh);
133         }
134
135         # For each item
136         my $i = 1; 
137         foreach my $itemnumber(@itemnumbers){
138
139                 $job->progress($i) if $runinbackground;
140                 my $itemdata=GetItem($itemnumber);
141                 if ($input->param("del")){
142                         my $return = DelItemCheck(C4::Context->dbh, $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'});
143                         if ($return == 1) {
144                             $deleted_items++;
145                         } else {
146                             $not_deleted_items++;
147                             push @not_deleted, { biblionumber => $itemdata->{'biblionumber'}, itemnumber => $itemdata->{'itemnumber'}, barcode => $itemdata->{'barcode'}, title => $itemdata->{'title'}, $return => 1 };
148                         }
149                 } else {
150                     if ($something_to_modify) {
151                         my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
152                         my $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
153                         my $localitem = TransformMarcToKoha( $dbh, $marcitem, "", 'items' );
154                         my $localmarcitem=Item2Marc($itemdata);
155                         UpdateMarcWith($marcitem,$localmarcitem);
156                         eval{my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($localmarcitem,$itemdata->{biblionumber},$itemnumber)};
157                     }
158                 }
159                 $i++;
160         }
161     }
162 }
163 #
164 #-------------------------------------------------------------------------------
165 # build screen with existing items. and "new" one
166 #-------------------------------------------------------------------------------
167
168 if ($op eq "show"){
169         my $filefh = $input->upload('uploadfile');
170         my $filecontent = $input->param('filecontent');
171         my @notfoundbarcodes;
172
173     my @contentlist;
174     if ($filefh){
175         while (my $content=<$filefh>){
176             chomp $content;
177             push @contentlist, $content if $content;
178         }
179
180         switch ($filecontent) {
181             case "barcode_file" {
182                 foreach my $barcode (@contentlist) {
183
184                     my $itemnumber = GetItemnumberFromBarcode($barcode);
185                     if ($itemnumber) {
186                         push @itemnumbers,$itemnumber;
187                     } else {
188                         push @notfoundbarcodes, $barcode;
189                     }
190                 }
191
192             }
193
194             case "itemid_file" {
195                 @itemnumbers = @contentlist;
196             }
197         }
198     } else {
199        if ( my $list=$input->param('barcodelist')){
200         push my @barcodelist, split(/\s\n/, $list);
201
202         foreach my $barcode (@barcodelist) {
203
204             my $itemnumber = GetItemnumberFromBarcode($barcode);
205             if ($itemnumber) {
206                 push @itemnumbers,$itemnumber;
207             } else {
208                 push @notfoundbarcodes, $barcode;
209             }
210         }
211
212     }
213 }
214     # Only display the items if there are no more than 1000
215     if (scalar(@itemnumbers) <= 1000) {
216         $items_display_hashref=BuildItemsData(@itemnumbers);
217     } else {
218         $template->param("too_many_items" => scalar(@itemnumbers));
219         # Even if we do not display the items, we need the itemnumbers
220         my @itemnumbers_hashref = map {{itemnumber => $_}} @itemnumbers;
221         $template->param("itemnumbers_hashref" => \@itemnumbers_hashref);
222     }
223 # now, build the item form for entering a new item
224 my @loop_data =();
225 my $i=0;
226 my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
227
228 my $branches = GetBranchesLoop();  # build once ahead of time, instead of multiple times later.
229
230 # Adding a default choice, in case the user does not want to modify the branch
231 my @nochange_branch = { branchname => '', value => '', selected => 1 };
232 unshift (@$branches, @nochange_branch);
233
234 my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
235
236
237 foreach my $tag (sort keys %{$tagslib}) {
238     # loop through each subfield
239     foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
240         next if subfield_is_koha_internal_p($subfield);
241         next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10");
242         # barcode and stocknumber are not meant to be batch-modified
243         next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.barcode';
244         next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.stocknumber';
245         my %subfield_data;
246  
247         my $index_subfield = int(rand(1000000)); 
248         if ($subfield eq '@'){
249             $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_subfield;
250         } else {
251             $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
252         }
253         $subfield_data{tag}        = $tag;
254         $subfield_data{subfield}   = $subfield;
255         $subfield_data{random}     = int(rand(1000000));    # why do we need 2 different randoms?
256     #   $subfield_data{marc_lib}   = $tagslib->{$tag}->{$subfield}->{lib};
257         $subfield_data{marc_lib}   ="<span id=\"error$i\" title=\"".$tagslib->{$tag}->{$subfield}->{lib}."\">".$tagslib->{$tag}->{$subfield}->{lib}."</span>";
258         $subfield_data{mandatory}  = $tagslib->{$tag}->{$subfield}->{mandatory};
259         $subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable};
260         my ($x,$value);
261         $value =~ s/"/&quot;/g;
262         unless ($value) {
263             $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
264             # get today date & replace YYYY, MM, DD if provided in the default value
265             my ( $year, $month, $day ) = split ',', $today_iso;     # FIXME: iso dates don't have commas!
266             $value =~ s/YYYY/$year/g;
267             $value =~ s/MM/$month/g;
268             $value =~ s/DD/$day/g;
269         }
270         $subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} > 4) || ($tagslib->{$tag}->{$subfield}->{hidden} < -4));
271         # testing branch value if IndependantBranches.
272
273         my $attributes_no_value = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="255" );
274         my $attributes          = qq($attributes_no_value value="$value" );
275
276         if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
277         my @authorised_values;
278         my %authorised_lib;
279         # builds list, depending on authorised value...
280   
281         if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
282             foreach my $thisbranch (@$branches) {
283                 push @authorised_values, $thisbranch->{value};
284                 $authorised_lib{$thisbranch->{value}} = $thisbranch->{branchname};
285                 $value = $thisbranch->{value} if $thisbranch->{selected};
286             }
287         }
288         elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
289             push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
290             my $sth = $dbh->prepare("select itemtype,description from itemtypes order by description");
291             $sth->execute;
292             while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
293                 push @authorised_values, $itemtype;
294                 $authorised_lib{$itemtype} = $description;
295             }
296
297           #---- class_sources
298       }
299       elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
300           push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
301             
302           my $class_sources = GetClassSources();
303           my $default_source = C4::Context->preference("DefaultClassificationSource");
304           
305           foreach my $class_source (sort keys %$class_sources) {
306               next unless $class_sources->{$class_source}->{'used'} or
307                           ($value and $class_source eq $value)      or
308                           ($class_source eq $default_source);
309               push @authorised_values, $class_source;
310               $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
311           }
312                   $value = $default_source unless ($value);
313
314           #---- "true" authorised value
315       }
316       else {
317           push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
318           $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value} );
319           while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
320               push @authorised_values, $value;
321               $authorised_lib{$value} = $lib;
322           }
323       }
324       $subfield_data{marc_value} =CGI::scrolling_list(      # FIXME: factor out scrolling_list
325           -name     => "field_value",
326           -values   => \@authorised_values,
327           -default  => $value,
328           -labels   => \%authorised_lib,
329           -override => 1,
330           -size     => 1,
331           -multiple => 0,
332           -tabindex => 1,
333           -id       => "tag_".$tag."_subfield_".$subfield."_".$index_subfield,
334           -class    => "input_marceditor",
335       );
336     # it's a thesaurus / authority field
337     }
338     elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
339         $subfield_data{marc_value} = "<input type=\"text\" $attributes />
340             <a href=\"#\" class=\"buttonDot\"
341                 onclick=\"Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=".$tagslib->{$tag}->{$subfield}->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}'); return false;\" title=\"Tag Editor\">...</a>
342     ";
343     # it's a plugin field
344     }
345     elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) {
346         # opening plugin
347         my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $tagslib->{$tag}->{$subfield}->{'value_builder'};
348         if (do $plugin) {
349                         my $temp;
350             my $extended_param = plugin_parameters( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
351             my ( $function_name, $javascript ) = plugin_javascript( $dbh, $temp, $tagslib, $subfield_data{id}, \@loop_data );
352             $subfield_data{marc_value} = qq[<input $attributes
353                 onfocus="Focus$function_name($subfield_data{random}, '$subfield_data{id}');"
354                  onblur=" Blur$function_name($subfield_data{random}, '$subfield_data{id}');" />
355                 <a href="#" class="buttonDot" onclick="Clic$function_name('$subfield_data{id}'); return false;" title="Tag Editor">...</a>
356                 $javascript];
357         } else {
358             warn "Plugin Failed: $plugin";
359             $subfield_data{marc_value} = "<input $attributes />"; # supply default input form
360         }
361     }
362     elsif ( $tag eq '' ) {       # it's an hidden field
363         $subfield_data{marc_value} = qq(<input type="hidden" $attributes />);
364     }
365     elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) {   # FIXME: shouldn't input type be "hidden" ?
366         $subfield_data{marc_value} = qq(<input type="text" $attributes />);
367     }
368     elsif ( length($value) > 100
369             or (C4::Context->preference("marcflavour") eq "UNIMARC" and
370                   300 <= $tag && $tag < 400 && $subfield eq 'a' )
371             or (C4::Context->preference("marcflavour") eq "MARC21"  and
372                   500 <= $tag && $tag < 600                     )
373           ) {
374         # oversize field (textarea)
375         $subfield_data{marc_value} = "<textarea $attributes_no_value>$value</textarea>\n";
376     } else {
377         # it's a standard field
378          $subfield_data{marc_value} = "<input $attributes />";
379     }
380 #   $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
381     push (@loop_data, \%subfield_data);
382     $i++
383   }
384 } # -- End foreach tag
385
386
387     # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
388     $template->param(item => \@loop_data);
389     if (@notfoundbarcodes) { 
390         my @notfoundbarcodesloop = map{{barcode=>$_}}@notfoundbarcodes;
391         $template->param(notfoundbarcodes => \@notfoundbarcodesloop);
392     }
393     $nextop="action"
394 } # -- End action="show"
395
396 $template->param(%$items_display_hashref) if $items_display_hashref;
397 $template->param(
398     op      => $nextop,
399     $op => 1,
400 );
401
402 if ($op eq "action") {
403
404     #my @not_deleted_loop = map{{itemnumber=>$_}}@not_deleted;
405
406     $template->param(
407         not_deleted_items => $not_deleted_items,
408         deleted_items => $deleted_items,
409         not_deleted_loop => \@not_deleted 
410     );
411 }
412
413 foreach my $error (@errors) {
414     $template->param($error => 1);
415 }
416 output_html_with_http_headers $input, $cookie, $template->output;
417 exit;
418
419
420 # ---------------- Functions
421
422 sub BuildItemsData{
423         my @itemnumbers=@_;
424                 # now, build existiing item list
425                 my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
426                 my @big_array;
427                 #---- finds where items.itemnumber is stored
428                 my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
429                 my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", "");
430                 foreach my $itemnumber (@itemnumbers){
431                         my $itemdata=GetItem($itemnumber);
432                         my $itemmarc=Item2Marc($itemdata);
433                         my %this_row;
434                         foreach my $field (grep {$_->tag() eq $itemtagfield} $itemmarc->fields()) {
435                                 # loop through each subfield
436                                 if (my $itembranchcode=$field->subfield($branchtagsubfield) && C4::Context->preference("IndependantBranches")) {
437                                                 #verifying rights
438                                                 my $userenv = C4::Context->userenv();
439                                                 unless (($userenv->{'flags'} == 1) or (($userenv->{'branch'} eq $itembranchcode))){
440                                                                 $this_row{'nomod'}=1;
441                                                 }
442                                 }
443                                 my $tag=$field->tag();
444                                 foreach my $subfield ($field->subfields) {
445                                         my ($subfcode,$subfvalue)=@$subfield;
446                                         next if ($tagslib->{$tag}->{$subfcode}->{tab} ne 10 
447                                                         && $tag        ne $itemtagfield 
448                                                         && $subfcode   ne $itemtagsubfield);
449
450                                         $witness{$subfcode} = $tagslib->{$tag}->{$subfcode}->{lib} if ($tagslib->{$tag}->{$subfcode}->{tab}  eq 10);
451                                         if ($tagslib->{$tag}->{$subfcode}->{tab}  eq 10) {
452                                                 $this_row{$subfcode}=GetAuthorisedValueDesc( $tag,
453                                                                         $subfcode, $subfvalue, '', $tagslib) 
454                                                                         || $subfvalue;
455                                         }
456
457                                         $this_row{itemnumber} = $subfvalue if ($tag eq $itemtagfield && $subfcode eq $itemtagsubfield);
458                                 }
459                         }
460
461             # grab title, author, and ISBN to identify bib that the item
462             # belongs to in the display
463                         my $biblio=GetBiblioData($$itemdata{biblionumber});
464             $this_row{bibinfo} = join("\n", @$biblio{qw(title author ISBN)});
465
466                         if (%this_row) {
467                                 push(@big_array, \%this_row);
468                         }
469                 }
470                 @big_array = sort {$a->{0} cmp $b->{0}} @big_array;
471
472                 # now, construct template !
473                 # First, the existing items for display
474                 my @item_value_loop;
475                 my @witnesscodessorted=sort keys %witness;
476                 for my $row ( @big_array ) {
477                         my %row_data;
478                         my @item_fields = map +{ field => $_ || '' }, @$row{ @witnesscodessorted };
479                         $row_data{item_value} = [ @item_fields ];
480                         $row_data{itemnumber} = $row->{itemnumber};
481                         #reporting this_row values
482                         $row_data{'nomod'} = $row->{'nomod'};
483             $row_data{bibinfo} = $row->{bibinfo};
484                         push(@item_value_loop,\%row_data);
485                 }
486                 my @header_loop=map { { header_value=> $witness{$_}} } @witnesscodessorted;
487
488         return { item_loop        => \@item_value_loop, item_header_loop => \@header_loop };
489 }
490
491 #BE WARN : it is not the general case 
492 # This function can be OK in the item marc record special case
493 # Where subfield is not repeated
494 # And where we are sure that field should correspond
495 # And $tag>10
496 sub UpdateMarcWith($$){
497   my ($marcfrom,$marcto)=@_;
498   #warn "FROM :",$marcfrom->as_formatted;
499         my (  $itemtag,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
500         my $fieldfrom=$marcfrom->field($itemtag);
501         my @fields_to=$marcto->field($itemtag);
502     foreach my $subfield ($fieldfrom->subfields()){
503                 foreach my $field_to_update (@fields_to){
504                                 $field_to_update->update($$subfield[0]=>$$subfield[1]) if ($$subfield[1]);
505                 }
506     }
507   #warn "TO edited:",$marcto->as_formatted;
508 }
509
510 sub find_value {
511     my ($tagfield,$insubfield,$record) = @_;
512     my $result;
513     my $indicator;
514     foreach my $field ($record->field($tagfield)) {
515         my @subfields = $field->subfields();
516         foreach my $subfield (@subfields) {
517             if (@$subfield[0] eq $insubfield) {
518                 $result .= @$subfield[1];
519                 $indicator = $field->indicator(1).$field->indicator(2);
520             }
521         }
522     }
523     return($indicator,$result);
524 }
525
526 # ----------------------------
527 # Background functions
528
529
530 sub add_results_to_template {
531     my $template = shift;
532     my $results = shift;
533     $template->param(map { $_ => $results->{$_} } keys %{ $results });
534 }
535
536 sub add_saved_job_results_to_template {
537     my $template = shift;
538     my $completedJobID = shift;
539     my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID);
540     my $results = $job->results();
541     add_results_to_template($template, $results);
542 }
543
544 sub put_in_background {
545     my $job_size = shift;
546
547     my $job = C4::BackgroundJob->new($sessionID, "test", $ENV{'SCRIPT_NAME'}, $job_size);
548     my $jobID = $job->id();
549
550     # fork off
551     if (my $pid = fork) {
552         # parent
553         # return job ID as JSON
554
555         # prevent parent exiting from
556         # destroying the kid's database handle
557         # FIXME: according to DBI doc, this may not work for Oracle
558         $dbh->{InactiveDestroy}  = 1;
559
560         my $reply = CGI->new("");
561         print $reply->header(-type => 'text/html');
562         print "{ jobID: '$jobID' }";
563         exit 0;
564     } elsif (defined $pid) {
565         # child
566         # close STDOUT to signal to Apache that
567         # we're now running in the background
568         close STDOUT;
569         close STDERR;
570     } else {
571         # fork failed, so exit immediately
572         warn "fork failed while attempting to run $ENV{'SCRIPT_NAME'} as a background job";
573         exit 0;
574     }
575     return $job;
576 }
577
578 sub progress_callback {
579     my $job = shift;
580     my $dbh = shift;
581     return sub {
582         my $progress = shift;
583         $job->progress($progress);
584         $dbh->commit();
585     }
586 }
587
588