Lines 25-36
use CGI qw ( -utf8 );
Link Here
|
25 |
use C4::Output qw( output_html_with_http_headers ); |
25 |
use C4::Output qw( output_html_with_http_headers ); |
26 |
use C4::Auth qw( get_template_and_user ); |
26 |
use C4::Auth qw( get_template_and_user ); |
27 |
use C4::Context; |
27 |
use C4::Context; |
28 |
use C4::Accounts; |
|
|
29 |
use C4::Circulation qw( barcodedecode AddRenewal AddIssue MarkIssueReturned ); |
28 |
use C4::Circulation qw( barcodedecode AddRenewal AddIssue MarkIssueReturned ); |
30 |
use C4::Items qw( ModDateLastSeen ); |
29 |
use C4::Items qw( ModDateLastSeen ); |
31 |
use C4::Members; |
|
|
32 |
use C4::Stats; |
33 |
use C4::BackgroundJob; |
34 |
use Koha::UploadedFiles; |
30 |
use Koha::UploadedFiles; |
35 |
use Koha::Account; |
31 |
use Koha::Account; |
36 |
use Koha::Checkouts; |
32 |
use Koha::Checkouts; |
Lines 54-73
my ($template, $loggedinuser, $cookie) = get_template_and_user({
Link Here
|
54 |
|
50 |
|
55 |
|
51 |
|
56 |
my $fileID=$query->param('uploadedfileid'); |
52 |
my $fileID=$query->param('uploadedfileid'); |
57 |
my $runinbackground = $query->param('runinbackground'); |
53 |
my $op = $query->param('op') || q{}; |
58 |
my $completedJobID = $query->param('completedJobID'); |
|
|
59 |
my %cookies = CGI::Cookie->fetch(); |
54 |
my %cookies = CGI::Cookie->fetch(); |
60 |
my $sessionID = $cookies{'CGISESSID'}->value; |
55 |
my $sessionID = $cookies{'CGISESSID'}->value; |
61 |
## 'Local' globals. |
56 |
## 'Local' globals. |
62 |
our $dbh = C4::Context->dbh(); |
57 |
our $dbh = C4::Context->dbh(); |
63 |
our @output = (); ## For storing messages to be displayed to the user |
58 |
our @output = (); ## For storing messages to be displayed to the user |
64 |
|
59 |
|
65 |
|
60 |
if ( $op eq 'add_to_queue' ) { |
66 |
if ($completedJobID) { |
|
|
67 |
my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID); |
68 |
my $results = $job->results(); |
69 |
$template->param(transactions_loaded => 1); |
61 |
$template->param(transactions_loaded => 1); |
70 |
$template->param(messages => $results->{results}); |
|
|
71 |
} elsif ($fileID) { |
62 |
} elsif ($fileID) { |
72 |
my $upload = Koha::UploadedFiles->find( $fileID ); |
63 |
my $upload = Koha::UploadedFiles->find( $fileID ); |
73 |
my $fh = $upload? $upload->file_handle: undef; |
64 |
my $fh = $upload? $upload->file_handle: undef; |
Lines 75-119
if ($completedJobID) {
Link Here
|
75 |
my @input_lines = $fh? <$fh>: (); |
66 |
my @input_lines = $fh? <$fh>: (); |
76 |
$fh->close if $fh; |
67 |
$fh->close if $fh; |
77 |
|
68 |
|
78 |
my $job = undef; |
|
|
79 |
|
80 |
if ($runinbackground) { |
81 |
my $job_size = scalar(@input_lines); |
82 |
$job = C4::BackgroundJob->new($sessionID, $filename, '/cgi-bin/koha/offline_circ/process_koc.pl', $job_size); |
83 |
my $jobID = $job->id(); |
84 |
|
85 |
# fork off |
86 |
if (my $pid = fork) { |
87 |
# parent |
88 |
# return job ID as JSON |
89 |
|
90 |
# prevent parent exiting from |
91 |
# destroying the kid's database handle |
92 |
# FIXME: according to DBI doc, this may not work for Oracle |
93 |
$dbh->{InactiveDestroy} = 1; |
94 |
|
95 |
my $reply = CGI->new(""); |
96 |
print $reply->header(-type => 'text/html'); |
97 |
print '{"jobID":"' . $jobID . '"}'; |
98 |
exit 0; |
99 |
} elsif (defined $pid) { |
100 |
# child |
101 |
# close STDOUT to signal to Apache that |
102 |
# we're now running in the background |
103 |
close STDOUT; |
104 |
close STDERR; |
105 |
} else { |
106 |
# fork failed, so exit immediately |
107 |
# fork failed, so exit immediately |
108 |
warn "fork failed while attempting to run offline_circ/process_koc.pl as a background job"; |
109 |
exit 0; |
110 |
} |
111 |
|
112 |
# if we get here, we're a child that has detached |
113 |
# itself from Apache |
114 |
|
115 |
} |
116 |
|
117 |
my $header_line = shift @input_lines; |
69 |
my $header_line = shift @input_lines; |
118 |
my $file_info = parse_header_line($header_line); |
70 |
my $file_info = parse_header_line($header_line); |
119 |
if ($file_info->{'Version'} ne $FILE_VERSION) { |
71 |
if ($file_info->{'Version'} ne $FILE_VERSION) { |
Lines 143-160
if ($completedJobID) {
Link Here
|
143 |
} else { |
95 |
} else { |
144 |
warn "unknown command: '$command_line->{command}' not processed"; |
96 |
warn "unknown command: '$command_line->{command}' not processed"; |
145 |
} |
97 |
} |
146 |
|
|
|
147 |
if ($runinbackground) { |
148 |
$job->progress($i); |
149 |
} |
150 |
} |
98 |
} |
151 |
|
99 |
|
152 |
if ($runinbackground) { |
100 |
$template->param(transactions_loaded => 1); |
153 |
$job->finish({ results => \@output }) if defined($job); |
101 |
$template->param(messages => \@output); |
154 |
} else { |
|
|
155 |
$template->param(transactions_loaded => 1); |
156 |
$template->param(messages => \@output); |
157 |
} |
158 |
} |
102 |
} |
159 |
|
103 |
|
160 |
output_html_with_http_headers $query, $cookie, $template->output; |
104 |
output_html_with_http_headers $query, $cookie, $template->output; |
161 |
- |
|
|