Lines 55-61
my $op = $input->param('op');
Link Here
|
55 |
my $del = $input->param('del'); |
55 |
my $del = $input->param('del'); |
56 |
my $del_records = $input->param('del_records'); |
56 |
my $del_records = $input->param('del_records'); |
57 |
my $completedJobID = $input->param('completedJobID'); |
57 |
my $completedJobID = $input->param('completedJobID'); |
58 |
my $runinbackground = $input->param('runinbackground'); |
|
|
59 |
my $src = $input->param('src'); |
58 |
my $src = $input->param('src'); |
60 |
my $use_default_values = $input->param('use_default_values'); |
59 |
my $use_default_values = $input->param('use_default_values'); |
61 |
my $exclude_from_local_holds_priority = $input->param('exclude_from_local_holds_priority'); |
60 |
my $exclude_from_local_holds_priority = $input->param('exclude_from_local_holds_priority'); |
Lines 150-173
if ($op eq "action") {
Link Here
|
150 |
$template->param( "job_completed" => 1 ); |
149 |
$template->param( "job_completed" => 1 ); |
151 |
} |
150 |
} |
152 |
|
151 |
|
153 |
# Setting the job as done |
|
|
154 |
my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID); |
155 |
|
156 |
# Calling the template |
157 |
add_saved_job_results_to_template($template, $completedJobID, $items_display_hashref); |
158 |
|
159 |
} else { |
152 |
} else { |
160 |
# While the job is getting done |
153 |
# While the job is getting done |
161 |
|
154 |
|
162 |
# Job size is the number of items we have to process |
|
|
163 |
my $job_size = scalar(@itemnumbers); |
164 |
my $job = undef; |
165 |
|
166 |
# If we asked for background processing |
167 |
if ($runinbackground) { |
168 |
$job = put_in_background($job_size); |
169 |
} |
170 |
|
171 |
#initializing values for updates |
155 |
#initializing values for updates |
172 |
my ( $itemtagfield, $itemtagsubfield) = &GetMarcFromKohaField( "items.itemnumber" ); |
156 |
my ( $itemtagfield, $itemtagsubfield) = &GetMarcFromKohaField( "items.itemnumber" ); |
173 |
if ($values_to_modify){ |
157 |
if ($values_to_modify){ |
Lines 203-209
if ($op eq "action") {
Link Here
|
203 |
my $i = 1; |
187 |
my $i = 1; |
204 |
my $extra_headers = {}; |
188 |
my $extra_headers = {}; |
205 |
foreach my $itemnumber (@itemnumbers) { |
189 |
foreach my $itemnumber (@itemnumbers) { |
206 |
$job->progress($i) if $runinbackground; |
|
|
207 |
my $item = Koha::Items->find($itemnumber); |
190 |
my $item = Koha::Items->find($itemnumber); |
208 |
next |
191 |
next |
209 |
unless $item |
192 |
unless $item |
Lines 250-257
if ($op eq "action") {
Link Here
|
250 |
$item->exclude_from_local_holds_priority($exclude_from_local_holds_priority)->store; |
233 |
$item->exclude_from_local_holds_priority($exclude_from_local_holds_priority)->store; |
251 |
$modified_holds_priority = 1; |
234 |
$modified_holds_priority = 1; |
252 |
} |
235 |
} |
253 |
$extra_headers->{exclude_from_local_holds_priority} = {name => 'Exclude from local holds priority', items => {}} unless defined $extra_headers->{exclude_from_local_holds_priority}; |
|
|
254 |
$extra_headers->{exclude_from_local_holds_priority}->{items}->{$item->itemnumber} = $ynhash->{'av'.$item->exclude_from_local_holds_priority}; |
255 |
} |
236 |
} |
256 |
my $modified = 0; |
237 |
my $modified = 0; |
257 |
if ( $values_to_modify || $values_to_blank ) { |
238 |
if ( $values_to_modify || $values_to_blank ) { |
Lines 320-336
if ($op eq "action") {
Link Here
|
320 |
push @$upd_biblionumbers, $itemdata->{'biblionumber'}; |
301 |
push @$upd_biblionumbers, $itemdata->{'biblionumber'}; |
321 |
} |
302 |
} |
322 |
} |
303 |
} |
323 |
if ($runinbackground) { |
304 |
$modified_items++ if $modified || $modified_holds_priority; |
324 |
$modified_items++ if $modified || $modified_holds_priority; |
305 |
$modified_fields += $modified + $modified_holds_priority; |
325 |
$modified_fields += $modified + $modified_holds_priority; |
|
|
326 |
$job->set( |
327 |
{ |
328 |
modified_items => $modified_items, |
329 |
modified_fields => $modified_fields, |
330 |
extra_headers => $extra_headers, |
331 |
} |
332 |
); |
333 |
} |
334 |
} |
306 |
} |
335 |
$i++; |
307 |
$i++; |
336 |
} |
308 |
} |
Lines 358-363
if ($op eq "action") {
Link Here
|
358 |
$indexer->index_records( $upd_biblionumbers, 'specialUpdate', "biblioserver", undef ) if @$upd_biblionumbers; |
330 |
$indexer->index_records( $upd_biblionumbers, 'specialUpdate', "biblioserver", undef ) if @$upd_biblionumbers; |
359 |
$indexer->index_records( $del_biblionumbers, 'recordDelete', "biblioserver", undef ) if @$del_biblionumbers; |
331 |
$indexer->index_records( $del_biblionumbers, 'recordDelete', "biblioserver", undef ) if @$del_biblionumbers; |
360 |
} |
332 |
} |
|
|
333 |
|
334 |
# Calling the template |
335 |
$template->param( |
336 |
modified_items => $modified_items, |
337 |
modified_fields => $modified_fields, |
338 |
); |
339 |
|
361 |
} |
340 |
} |
362 |
# |
341 |
# |
363 |
#------------------------------------------------------------------------------- |
342 |
#------------------------------------------------------------------------------- |
Lines 795-869
sub find_value {
Link Here
|
795 |
} |
774 |
} |
796 |
return($indicator,$result); |
775 |
return($indicator,$result); |
797 |
} |
776 |
} |
798 |
|
|
|
799 |
# ---------------------------- |
800 |
# Background functions |
801 |
|
802 |
|
803 |
sub add_results_to_template { |
804 |
my $template = shift; |
805 |
my $results = shift; |
806 |
$template->param(map { $_ => $results->{$_} } keys %{ $results }); |
807 |
} |
808 |
|
809 |
sub add_saved_job_results_to_template { |
810 |
my $template = shift; |
811 |
my $completedJobID = shift; |
812 |
my $items_display_hashref= shift; |
813 |
my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID); |
814 |
my $results = $job->results(); |
815 |
add_results_to_template($template, $results); |
816 |
|
817 |
my $fields = $job->get("modified_fields"); |
818 |
my $items = $job->get("modified_items"); |
819 |
my $extra_headers = $job->get("extra_headers"); |
820 |
|
821 |
foreach my $header (keys %{$extra_headers}) { |
822 |
push @{$items_display_hashref->{item_header_loop}}, {header_value => $extra_headers->{$header}->{name}}; |
823 |
foreach my $row (@{$items_display_hashref->{item_loop}}) { |
824 |
push @{$row->{item_value}}, {field => $extra_headers->{$header}->{items}->{$row->{itemnumber}}}; |
825 |
} |
826 |
} |
827 |
|
828 |
$template->param( |
829 |
modified_items => $items, |
830 |
modified_fields => $fields, |
831 |
); |
832 |
} |
833 |
|
834 |
sub put_in_background { |
835 |
my $job_size = shift; |
836 |
|
837 |
my $job = C4::BackgroundJob->new($sessionID, "test", '/cgi-bin/koha/tools/batchMod.pl', $job_size); |
838 |
my $jobID = $job->id(); |
839 |
|
840 |
# fork off |
841 |
if (my $pid = fork) { |
842 |
# parent |
843 |
# return job ID as JSON |
844 |
|
845 |
# prevent parent exiting from |
846 |
# destroying the kid's database handle |
847 |
# FIXME: according to DBI doc, this may not work for Oracle |
848 |
$dbh->{InactiveDestroy} = 1; |
849 |
|
850 |
my $reply = CGI->new(""); |
851 |
print $reply->header(-type => 'text/html'); |
852 |
print '{"jobID":"' . $jobID . '"}'; |
853 |
exit 0; |
854 |
} elsif (defined $pid) { |
855 |
# child |
856 |
# close STDOUT to signal to Apache that |
857 |
# we're now running in the background |
858 |
close STDOUT; |
859 |
close STDERR; |
860 |
} else { |
861 |
# fork failed, so exit immediately |
862 |
warn "fork failed while attempting to run tools/batchMod.pl as a background job"; |
863 |
exit 0; |
864 |
} |
865 |
return $job; |
866 |
} |
867 |
|
868 |
|
869 |
|
870 |
- |