4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
30 use C4::BackgroundJob;
35 use List::MoreUtils qw/uniq/;
37 use Koha::AuthorisedValues;
45 my $dbh = C4::Context->dbh;
46 my $error = $input->param('error');
47 my @itemnumbers = $input->multi_param('itemnumber');
48 my $biblionumber = $input->param('biblionumber');
49 my $op = $input->param('op');
50 my $del = $input->param('del');
51 my $del_records = $input->param('del_records');
52 my $completedJobID = $input->param('completedJobID');
53 my $runinbackground = $input->param('runinbackground');
54 my $src = $input->param('src');
55 my $use_default_values = $input->param('use_default_values');
60 $template_name = "tools/batchMod.tt";
61 $template_flag = { tools => '*' };
64 $template_name = ($del) ? "tools/batchMod-del.tt" : "tools/batchMod-edit.tt";
65 $template_flag = ($del) ? { tools => 'items_batchdel' } : { tools => 'items_batchmod' };
69 my ($template, $loggedinuser, $cookie)
70 = get_template_and_user({template_name => $template_name,
74 flagsrequired => $template_flag,
77 # Does the user have a restricted item edition permission?
78 my $uid = $loggedinuser ? Koha::Patrons->find( $loggedinuser )->userid : undef;
79 my $restrictededition = $uid ? haspermission($uid, {'tools' => 'items_batchmod_restricted'}) : undef;
80 # In case user is a superlibrarian, edition is not restricted
81 $restrictededition = 0 if ($restrictededition != 0 && C4::Context->IsSuperLibrarian());
83 $template->param(del => $del);
87 my @errors; # store errors found while checking data BEFORE saving item.
88 my $items_display_hashref;
89 our $tagslib = &GetMarcStructure(1);
91 my $deleted_items = 0; # Number of deleted items
92 my $deleted_records = 0; # Number of deleted records ( with no items attached )
93 my $not_deleted_items = 0; # Number of items that could not be deleted
94 my @not_deleted; # List of the itemnumbers that could not be deleted
95 my $modified_items = 0; # Numbers of modified items
96 my $modified_fields = 0; # Numbers of modified fields
98 my %cookies = parse CGI::Cookie($cookie);
99 my $sessionID = $cookies{'CGISESSID'}->value;
102 #--- ----------------------------------------------------------------------------
103 if ($op eq "action") {
104 #-------------------------------------------------------------------------------
105 my @tags = $input->multi_param('tag');
106 my @subfields = $input->multi_param('subfield');
107 my @values = $input->multi_param('field_value');
108 my @disabled = $input->multi_param('disable_input');
109 # build indicator hash.
110 my @ind_tag = $input->multi_param('ind_tag');
111 my @indicator = $input->multi_param('indicator');
113 # Is there something to modify ?
114 # TODO : We shall use this var to warn the user in case no modification was done to the items
115 my $values_to_modify = scalar(grep {!/^$/} @values);
116 my $values_to_blank = scalar(@disabled);
119 # Once the job is done
120 if ($completedJobID) {
121 # If we have a reasonable amount of items, we display them
122 my $max_items = $del ? C4::Context->preference("MaxItemsToDisplayForBatchDel") : C4::Context->preference("MaxItemsToDisplayForBatchMod");
123 if (scalar(@itemnumbers) <= $max_items ){
124 if (scalar(@itemnumbers) <= 1000 ) {
125 $items_display_hashref=BuildItemsData(@itemnumbers);
127 # Else, we only display the barcode
128 my @simple_items_display = map {
130 my $item = Koha::Items->find($itemnumber);
132 itemnumber => $itemnumber,
133 barcode => $item ? ( $item->barcode // q{} ) : q{},
134 biblionumber => $item ? $item->biblio->biblionumber : q{},
137 $template->param("simple_items_display" => \@simple_items_display);
140 $template->param( "too_many_items_display" => scalar(@itemnumbers) );
141 $template->param( "job_completed" => 1 );
144 # Setting the job as done
145 my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID);
147 # Calling the template
148 add_saved_job_results_to_template($template, $completedJobID);
151 # While the job is getting done
153 # Job size is the number of items we have to process
154 my $job_size = scalar(@itemnumbers);
157 # If we asked for background processing
158 if ($runinbackground) {
159 $job = put_in_background($job_size);
162 #initializing values for updates
163 my ( $itemtagfield, $itemtagsubfield) = &GetMarcFromKohaField( "items.itemnumber" );
164 if ($values_to_modify){
165 my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
166 $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
168 if ($values_to_blank){
169 foreach my $disabledsubf (@disabled){
170 if ($marcitem && $marcitem->field($itemtagfield)){
171 $marcitem->field($itemtagfield)->update( $disabledsubf => "" );
174 $marcitem = MARC::Record->new();
175 $marcitem->append_fields( MARC::Field->new( $itemtagfield, '', '', $disabledsubf => "" ) );
182 foreach my $itemnumber(@itemnumbers){
184 $job->progress($i) if $runinbackground;
185 my $itemdata = Koha::Items->find($itemnumber);
186 next unless $itemdata; # Should have been tested earlier, but just in case...
187 $itemdata = $itemdata->unblessed;
189 my $return = DelItemCheck( $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'});
193 $not_deleted_items++;
195 { biblionumber => $itemdata->{'biblionumber'},
196 itemnumber => $itemdata->{'itemnumber'},
197 barcode => $itemdata->{'barcode'},
198 title => $itemdata->{'title'},
203 # If there are no items left, delete the biblio
205 my $itemscount = Koha::Biblios->find( $itemdata->{'biblionumber'} )->items->count;
206 if ( $itemscount == 0 ) {
207 my $error = DelBiblio( $itemdata->{'biblionumber'} );
210 if ( $src eq 'CATALOGUING' ) {
211 # We are coming catalogue/detail.pl, there were items from a single bib record
212 $template->param( biblio_deleted => 1 );
218 if ($values_to_modify || $values_to_blank) {
219 my $localmarcitem = Item2Marc($itemdata);
221 my $modified = UpdateMarcWith( $marcitem, $localmarcitem );
224 if ( my $item = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) ) {
225 LostItem($itemnumber, 'batchmod') if $item->{itemlost} and not $itemdata->{itemlost};
229 if ( $runinbackground ) {
230 $modified_items++ if $modified;
231 $modified_fields += $modified;
233 modified_items => $modified_items,
234 modified_fields => $modified_fields,
244 #-------------------------------------------------------------------------------
245 # build screen with existing items. and "new" one
246 #-------------------------------------------------------------------------------
249 my $filefh = $input->upload('uploadfile');
250 my $filecontent = $input->param('filecontent');
251 my ( @notfoundbarcodes, @notfounditemnumbers);
253 my $split_chars = C4::Context->preference('BarcodeSeparators');
255 binmode $filefh, ':encoding(UTF-8)';
257 while (my $content=<$filefh>){
258 $content =~ s/[\r\n]*$//;
259 push @contentlist, $content if $content;
262 if ($filecontent eq 'barcode_file') {
263 @contentlist = grep /\S/, ( map { split /[$split_chars]/ } @contentlist );
264 @contentlist = uniq @contentlist;
265 # Note: adding lc for case insensitivity
266 my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => \@contentlist }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed };
267 my @barcodes = grep { exists $itemdata{lc $_} } @contentlist;
268 @itemnumbers = map { exists $itemdata{lc $_} ? $itemdata{lc $_} : () } @contentlist;
269 @notfoundbarcodes = grep { !exists $itemdata{lc $_} } @contentlist;
271 elsif ( $filecontent eq 'itemid_file') {
272 @contentlist = uniq @contentlist;
273 my %itemdata = map { $_->{itemnumber} => 1 } @{ Koha::Items->search({ itemnumber => \@contentlist }, { columns => [ 'itemnumber' ] } )->unblessed };
274 @itemnumbers = grep { exists $itemdata{$_} } @contentlist;
275 @notfounditemnumbers = grep { !exists $itemdata{$_} } @contentlist;
278 if (defined $biblionumber){
279 my @all_items = GetItemsInfo( $biblionumber );
280 foreach my $itm (@all_items) {
281 push @itemnumbers, $itm->{itemnumber};
284 if ( my $list = $input->param('barcodelist') ) {
285 my @barcodelist = grep /\S/, ( split /[$split_chars]/, $list );
286 @barcodelist = uniq @barcodelist;
287 # Note: adding lc for case insensitivity
288 my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => \@barcodelist }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed };
289 @itemnumbers = map { exists $itemdata{lc $_} ? $itemdata{lc $_} : () } @barcodelist;
290 @notfoundbarcodes = grep { !exists $itemdata{lc $_} } @barcodelist;
294 # Flag to tell the template there are valid results, hidden or not
295 if(scalar(@itemnumbers) > 0){ $template->param("itemresults" => 1); }
296 # Only display the items if there are no more than pref MaxItemsToProcessForBatchMod or MaxItemsToDisplayForBatchDel
297 my $max_display_items = $del
298 ? C4::Context->preference("MaxItemsToDisplayForBatchDel")
299 : C4::Context->preference("MaxItemsToDisplayForBatchMod");
300 $template->param("too_many_items_process" => scalar(@itemnumbers)) if !$del && scalar(@itemnumbers) >= C4::Context->preference("MaxItemsToProcessForBatchMod");
301 if (scalar(@itemnumbers) <= ( $max_display_items // 1000 ) ) {
302 $items_display_hashref=BuildItemsData(@itemnumbers);
304 $template->param("too_many_items_display" => scalar(@itemnumbers));
305 # Even if we do not display the items, we need the itemnumbers
306 $template->param(itemnumbers_array => \@itemnumbers);
308 # now, build the item form for entering a new item
311 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
313 my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;# build once ahead of time, instead of multiple times later.
315 # Adding a default choice, in case the user does not want to modify the branch
316 my $nochange_branch = { branchname => '', value => '', selected => 1 };
317 unshift (@$libraries, $nochange_branch);
319 my $pref_itemcallnumber = C4::Context->preference('itemcallnumber');
321 # Getting list of subfields to keep when restricted batchmod edit is enabled
322 my $subfieldsToAllowForBatchmod = C4::Context->preference('SubfieldsToAllowForRestrictedBatchmod');
323 my $allowAllSubfields = (
324 not defined $subfieldsToAllowForBatchmod
325 or $subfieldsToAllowForBatchmod eq q||
327 my @subfieldsToAllow = split(/ /, $subfieldsToAllowForBatchmod);
329 foreach my $tag (sort keys %{$tagslib}) {
330 # loop through each subfield
331 foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
332 next if IsMarcStructureInternal( $tagslib->{$tag}{$subfield} );
333 next if (not $allowAllSubfields and $restrictededition && !grep { $tag . '$' . $subfield eq $_ } @subfieldsToAllow );
334 next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10");
335 # barcode and stocknumber are not meant to be batch-modified
336 next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.barcode';
337 next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.stocknumber';
340 my $index_subfield = int(rand(1000000));
341 if ($subfield eq '@'){
342 $subfield_data{id} = "tag_".$tag."_subfield_00_".$index_subfield;
344 $subfield_data{id} = "tag_".$tag."_subfield_".$subfield."_".$index_subfield;
346 $subfield_data{tag} = $tag;
347 $subfield_data{subfield} = $subfield;
348 $subfield_data{marc_lib} ="<span id=\"error$i\" title=\"".$tagslib->{$tag}->{$subfield}->{lib}."\">".$tagslib->{$tag}->{$subfield}->{lib}."</span>";
349 $subfield_data{mandatory} = $tagslib->{$tag}->{$subfield}->{mandatory};
350 $subfield_data{repeatable} = $tagslib->{$tag}->{$subfield}->{repeatable};
352 if ( $use_default_values) {
353 $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
354 # get today date & replace YYYY, MM, DD if provided in the default value
355 my $today = dt_from_string;
356 my $year = $today->year;
357 my $month = $today->month;
358 my $day = $today->day;
359 $value =~ s/YYYY/$year/g;
360 $value =~ s/MM/$month/g;
361 $value =~ s/DD/$day/g;
363 $subfield_data{visibility} = "display:none;" if (($tagslib->{$tag}->{$subfield}->{hidden} > 4) || ($tagslib->{$tag}->{$subfield}->{hidden} < -4));
364 # testing branch value if IndependentBranches.
366 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
367 my @authorised_values;
369 # builds list, depending on authorised value...
371 if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
372 foreach my $library (@$libraries) {
373 push @authorised_values, $library->{branchcode};
374 $authorised_lib{$library->{branchcode}} = $library->{branchname};
378 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
379 push @authorised_values, "";
380 my $itemtypes = Koha::ItemTypes->search_with_localization;
381 while ( my $itemtype = $itemtypes->next ) {
382 push @authorised_values, $itemtype->itemtype;
383 $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
389 elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
390 push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
392 my $class_sources = GetClassSources();
393 my $default_source = C4::Context->preference("DefaultClassificationSource");
395 foreach my $class_source (sort keys %$class_sources) {
396 next unless $class_sources->{$class_source}->{'used'} or
397 ($value and $class_source eq $value) or
398 ($class_source eq $default_source);
399 push @authorised_values, $class_source;
400 $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
404 #---- "true" authorised value
407 push @authorised_values, ""; # unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
409 my @avs = Koha::AuthorisedValues->search({ category => $tagslib->{$tag}->{$subfield}->{authorised_value}, branchcode => $branch_limit },{order_by=>'lib'});
410 for my $av ( @avs ) {
411 push @authorised_values, $av->authorised_value;
412 $authorised_lib{$av->authorised_value} = $av->lib;
416 $subfield_data{marc_value} = {
418 id => "tag_".$tag."_subfield_".$subfield."_".$index_subfield,
419 name => "field_value",
420 values => \@authorised_values,
421 labels => \%authorised_lib,
424 # it's a thesaurus / authority field
426 elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
427 $subfield_data{marc_value} = {
429 id => $subfield_data{id},
431 authtypecode => $tagslib->{$tag}->{$subfield}->{authtypecode},
434 elsif ( $tagslib->{$tag}->{$subfield}->{value_builder} ) { # plugin
435 require Koha::FrameworkPlugin;
436 my $plugin = Koha::FrameworkPlugin->new( {
437 name => $tagslib->{$tag}->{$subfield}->{'value_builder'},
441 my $pars= { dbh => $dbh, record => $temp, tagslib => $tagslib,
442 id => $subfield_data{id}, tabloop => \@loop_data };
443 $plugin->build( $pars );
444 if( !$plugin->errstr ) {
445 $subfield_data{marc_value} = {
447 id => $subfield_data{id},
449 javascript => $plugin->javascript,
450 noclick => $plugin->noclick,
453 warn $plugin->errstr;
454 $subfield_data{marc_value} = { # supply default input form
456 id => $subfield_data{id},
461 elsif ( $tag eq '' ) { # it's an hidden field
462 $subfield_data{marc_value} = {
464 id => $subfield_data{id},
468 elsif ( $tagslib->{$tag}->{$subfield}->{'hidden'} ) { # FIXME: shouldn't input type be "hidden" ?
469 $subfield_data{marc_value} = {
471 id => $subfield_data{id},
475 elsif ( length($value) > 100
476 or (C4::Context->preference("marcflavour") eq "UNIMARC" and
477 300 <= $tag && $tag < 400 && $subfield eq 'a' )
478 or (C4::Context->preference("marcflavour") eq "MARC21" and
479 500 <= $tag && $tag < 600 )
481 # oversize field (textarea)
482 $subfield_data{marc_value} = {
484 id => $subfield_data{id},
488 # it's a standard field
489 $subfield_data{marc_value} = {
491 id => $subfield_data{id},
495 # $subfield_data{marc_value}="<input type=\"text\" name=\"field_value\">";
496 push (@loop_data, \%subfield_data);
499 } # -- End foreach tag
503 # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
506 notfoundbarcodes => \@notfoundbarcodes,
507 notfounditemnumbers => \@notfounditemnumbers
510 } # -- End action="show"
512 $template->param(%$items_display_hashref) if $items_display_hashref;
516 $template->param( $op => 1 ) if $op;
518 if ($op eq "action") {
520 #my @not_deleted_loop = map{{itemnumber=>$_}}@not_deleted;
523 not_deleted_items => $not_deleted_items,
524 deleted_items => $deleted_items,
525 delete_records => $del_records,
526 deleted_records => $deleted_records,
527 not_deleted_loop => \@not_deleted
531 foreach my $error (@errors) {
532 $template->param($error => 1) if $error;
534 $template->param(src => $src);
535 $template->param(biblionumber => $biblionumber);
536 output_html_with_http_headers $input, $cookie, $template->output;
540 # ---------------- Functions
544 # now, build existiing item list
545 my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
547 #---- finds where items.itemnumber is stored
548 my ( $itemtagfield, $itemtagsubfield) = &GetMarcFromKohaField( "items.itemnumber" );
549 my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField( "items.homebranch" );
550 foreach my $itemnumber (@itemnumbers){
551 my $itemdata = Koha::Items->find($itemnumber);
552 next unless $itemdata; # Should have been tested earlier, but just in case...
553 $itemdata = $itemdata->unblessed;
554 my $itemmarc=Item2Marc($itemdata);
556 foreach my $field (grep {$_->tag() eq $itemtagfield} $itemmarc->fields()) {
557 # loop through each subfield
558 my $itembranchcode=$field->subfield($branchtagsubfield);
559 if ($itembranchcode && C4::Context->preference("IndependentBranches")) {
561 my $userenv = C4::Context->userenv();
562 unless (C4::Context->IsSuperLibrarian() or (($userenv->{'branch'} eq $itembranchcode))){
563 $this_row{'nomod'}=1;
566 my $tag=$field->tag();
567 foreach my $subfield ($field->subfields) {
568 my ($subfcode,$subfvalue)=@$subfield;
569 next if ($tagslib->{$tag}->{$subfcode}->{tab} ne 10
570 && $tag ne $itemtagfield
571 && $subfcode ne $itemtagsubfield);
573 $witness{$subfcode} = $tagslib->{$tag}->{$subfcode}->{lib} if ($tagslib->{$tag}->{$subfcode}->{tab} eq 10);
574 if ($tagslib->{$tag}->{$subfcode}->{tab} eq 10) {
575 $this_row{$subfcode}=GetAuthorisedValueDesc( $tag,
576 $subfcode, $subfvalue, '', $tagslib)
580 $this_row{itemnumber} = $subfvalue if ($tag eq $itemtagfield && $subfcode eq $itemtagsubfield);
584 # grab title, author, and ISBN to identify bib that the item
585 # belongs to in the display
586 my $biblio = Koha::Biblios->find( $itemdata->{biblionumber} );
587 $this_row{title} = $biblio->title;
588 $this_row{author} = $biblio->author;
589 $this_row{isbn} = $biblio->biblioitem->isbn;
590 $this_row{biblionumber} = $biblio->biblionumber;
591 $this_row{holds} = $biblio->holds->count;
592 $this_row{item_holds} = Koha::Holds->search( itemnumber => $itemnumber )->count;
595 push(@big_array, \%this_row);
598 @big_array = sort {$a->{0} cmp $b->{0}} @big_array;
600 # now, construct template !
601 # First, the existing items for display
603 my @witnesscodessorted=sort keys %witness;
604 for my $row ( @big_array ) {
606 my @item_fields = map +{ field => $_ || '' }, @$row{ @witnesscodessorted };
607 $row_data{item_value} = [ @item_fields ];
608 $row_data{itemnumber} = $row->{itemnumber};
609 #reporting this_row values
610 $row_data{'nomod'} = $row->{'nomod'};
611 $row_data{bibinfo} = $row->{bibinfo};
612 $row_data{author} = $row->{author};
613 $row_data{title} = $row->{title};
614 $row_data{isbn} = $row->{isbn};
615 $row_data{biblionumber} = $row->{biblionumber};
616 $row_data{holds} = $row->{holds};
617 $row_data{item_holds} = $row->{item_holds};
618 my $is_on_loan = C4::Circulation::IsItemIssued( $row->{itemnumber} );
619 $row_data{onloan} = $is_on_loan ? 1 : 0;
620 push(@item_value_loop,\%row_data);
622 my @header_loop=map { { header_value=> $witness{$_}} } @witnesscodessorted;
624 return { item_loop => \@item_value_loop, item_header_loop => \@header_loop };
627 #BE WARN : it is not the general case
628 # This function can be OK in the item marc record special case
629 # Where subfield is not repeated
630 # And where we are sure that field should correspond
633 my ($marcfrom,$marcto)=@_;
634 my ( $itemtag, $itemtagsubfield) = &GetMarcFromKohaField( "items.itemnumber" );
635 my $fieldfrom=$marcfrom->field($itemtag);
636 my @fields_to=$marcto->field($itemtag);
638 foreach my $subfield ( $fieldfrom->subfields() ) {
639 foreach my $field_to_update ( @fields_to ) {
640 if ( $subfield->[1] ) {
641 unless ( $field_to_update->subfield($subfield->[0]) eq $subfield->[1] ) {
643 $field_to_update->update( $subfield->[0] => $subfield->[1] );
648 $field_to_update->delete_subfield( code => $subfield->[0] );
656 my ($tagfield,$insubfield,$record) = @_;
659 foreach my $field ($record->field($tagfield)) {
660 my @subfields = $field->subfields();
661 foreach my $subfield (@subfields) {
662 if (@$subfield[0] eq $insubfield) {
663 $result .= @$subfield[1];
664 $indicator = $field->indicator(1).$field->indicator(2);
668 return($indicator,$result);
671 # ----------------------------
672 # Background functions
675 sub add_results_to_template {
676 my $template = shift;
678 $template->param(map { $_ => $results->{$_} } keys %{ $results });
681 sub add_saved_job_results_to_template {
682 my $template = shift;
683 my $completedJobID = shift;
684 my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID);
685 my $results = $job->results();
686 add_results_to_template($template, $results);
688 my $fields = $job->get("modified_fields");
689 my $items = $job->get("modified_items");
691 modified_items => $items,
692 modified_fields => $fields,
696 sub put_in_background {
697 my $job_size = shift;
699 my $job = C4::BackgroundJob->new($sessionID, "test", '/cgi-bin/koha/tools/batchMod.pl', $job_size);
700 my $jobID = $job->id();
703 if (my $pid = fork) {
705 # return job ID as JSON
707 # prevent parent exiting from
708 # destroying the kid's database handle
709 # FIXME: according to DBI doc, this may not work for Oracle
710 $dbh->{InactiveDestroy} = 1;
712 my $reply = CGI->new("");
713 print $reply->header(-type => 'text/html');
714 print '{"jobID":"' . $jobID . '"}';
716 } elsif (defined $pid) {
718 # close STDOUT to signal to Apache that
719 # we're now running in the background
723 # fork failed, so exit immediately
724 warn "fork failed while attempting to run tools/batchMod.pl as a background job";