Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# Script for testing progressbar, part 2 - json submit handler |
4 |
# and Z39.50 lookups |
5 |
|
6 |
# Koha library project www.koha.org |
7 |
|
8 |
# Licensed under the GPL |
9 |
|
10 |
# Copyright 2000-2002 Katipo Communications |
11 |
# |
12 |
# This file is part of Koha. |
13 |
# |
14 |
# Koha is free software; you can redistribute it and/or modify it under the |
15 |
# terms of the GNU General Public License as published by the Free Software |
16 |
# Foundation; either version 2 of the License, or (at your option) any later |
17 |
# version. |
18 |
# |
19 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
20 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
21 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
22 |
# |
23 |
# You should have received a copy of the GNU General Public License along |
24 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
25 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
26 |
|
27 |
use strict; |
28 |
#use warnings; FIXME - Bug 2505 |
29 |
|
30 |
# standard or CPAN modules used |
31 |
use CGI; |
32 |
use CGI::Cookie; |
33 |
|
34 |
# Koha modules used |
35 |
use C4::Context; |
36 |
use C4::Auth; |
37 |
use C4::Output; |
38 |
use C4::BackgroundJob; |
39 |
|
40 |
my $input = new CGI; |
41 |
|
42 |
my $submitted=$input->param('submitted'); |
43 |
my $runinbackground = $input->param('runinbackground'); |
44 |
my $jobID = $input->param('jobID'); |
45 |
my $completedJobID = $input->param('completedJobID'); |
46 |
|
47 |
my ($template, $loggedinuser, $cookie) |
48 |
= get_template_and_user({template_name => "test/progressbar.tmpl", |
49 |
query => $input, |
50 |
type => "intranet", |
51 |
debug => 1, |
52 |
}); |
53 |
|
54 |
my %cookies = parse CGI::Cookie($cookie); |
55 |
my $sessionID = $cookies{'CGISESSID'}->value; |
56 |
if ($completedJobID) { |
57 |
} elsif ($submitted) { |
58 |
my $job = undef; |
59 |
if ($runinbackground) { |
60 |
my $job_size = 100; |
61 |
$job = C4::BackgroundJob->new($sessionID, undef, $ENV{'SCRIPT_NAME'}, $job_size); |
62 |
$jobID = $job->id(); |
63 |
|
64 |
# fork off |
65 |
if (my $pid = fork) { |
66 |
# parent |
67 |
# return job ID as JSON |
68 |
|
69 |
# prevent parent exiting from |
70 |
# destroying the kid's database handle |
71 |
# FIXME: according to DBI doc, this may not work for Oracle |
72 |
|
73 |
my $reply = CGI->new(""); |
74 |
print $reply->header(-type => 'text/html'); |
75 |
print "{ jobID: '$jobID' }"; |
76 |
exit 0; |
77 |
} elsif (defined $pid) { |
78 |
# if we get here, we're a child that has detached |
79 |
# itself from Apache |
80 |
|
81 |
# close STDOUT to signal to Apache that |
82 |
# we're now running in the background |
83 |
close STDOUT; |
84 |
close STDERR; |
85 |
|
86 |
foreach (1..100) { |
87 |
sleep 1; |
88 |
$job->progress( $_ ); |
89 |
} |
90 |
$job->finish(); |
91 |
} else { |
92 |
# fork failed, so exit immediately |
93 |
die "fork failed while attempting to run $ENV{'SCRIPT_NAME'} as a background job"; |
94 |
} |
95 |
|
96 |
} |
97 |
} else { |
98 |
# initial form |
99 |
die "We should not be here"; |
100 |
} |
101 |
|
102 |
exit 0; |
103 |
|
104 |
|