View | Details | Raw Unified | Return to bug 33962
Collapse All | Expand All

(-)a/debian/templates/apache-shared-intranet-plack.conf (-1 lines)
Lines 11-17 Link Here
11
11
12
        # FIXME: These scripts should be fixed so they
12
        # FIXME: These scripts should be fixed so they
13
        # don't break under plack/starman
13
        # don't break under plack/starman
14
        ProxyPass "/cgi-bin/koha/offline_circ/process_koc.pl" "!"
15
        ProxyPass "/cgi-bin/koha/tools/background-job-progress.pl" "!"
14
        ProxyPass "/cgi-bin/koha/tools/background-job-progress.pl" "!"
16
        ProxyPass "/cgi-bin/koha/tools/export.pl" "!"
15
        ProxyPass "/cgi-bin/koha/tools/export.pl" "!"
17
        ProxyPass "/cgi-bin/koha/tools/upload-cover-image.pl" "!"
16
        ProxyPass "/cgi-bin/koha/tools/upload-cover-image.pl" "!"
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/offline_circ/process_koc.tt (-12 / +3 lines)
Lines 81-97 Link Here
81
81
82
   <form action="enqueue_koc.pl" id="processfile" method="post" enctype="multipart/form-data">
82
   <form action="enqueue_koc.pl" id="processfile" method="post" enctype="multipart/form-data">
83
     <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
83
     <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
84
     <input type="hidden" name="action" value="add_to_queue" />
84
     <input type="submit" value="Add to offline circulation queue" id="queueformsubmit" />
85
     <input type="submit" value="Add to offline circulation queue" id="queueformsubmit" />
85
   </form>
86
   </form>
86
87
87
   <form action="process_koc.pl" id="enqueuefile" method="post" enctype="multipart/form-data">
88
   <form action="process_koc.pl" id="enqueuefile" method="post" enctype="multipart/form-data">
88
     <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
89
     <input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" />
89
     <input type="hidden" name="runinbackground" id="runinbackground" value="" />
90
     <input type="hidden" name="completedJobID" id="completedJobID" value="" />
91
     <!-- <input type="submit" value="Apply directly" id="mainformsubmit" /> -->
90
     <!-- <input type="submit" value="Apply directly" id="mainformsubmit" /> -->
92
     <!-- FIXME: Job freezes when submitted, disabling button as a temporary mitigation -->
93
     <div id="jobstatus" style="display:none">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
94
     <div id="jobfailed" style="display:none"></div>
95
   </form>
91
   </form>
96
[% END %]
92
[% END %]
97
93
Lines 100-106 Link Here
100
</div>
96
</div>
101
97
102
[% MACRO jsinclude BLOCK %]
98
[% MACRO jsinclude BLOCK %]
103
    [% Asset.js("js/background-job-progressbar.js") | $raw %]
104
    [% Asset.js("js/file-upload.js") | $raw %]
99
    [% Asset.js("js/file-upload.js") | $raw %]
105
    <script>
100
    <script>
106
        var xhr;
101
        var xhr;
Lines 128-134 Link Here
128
            $("#fileuploadstatus").show();
123
            $("#fileuploadstatus").show();
129
            $("form#processfile #uploadedfileid").val('');
124
            $("form#processfile #uploadedfileid").val('');
130
            $("form#enqueuefile #uploadedfileid").val('');
125
            $("form#enqueuefile #uploadedfileid").val('');
131
            xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
126
            xhr = AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload );
132
        }
127
        }
133
128
134
        function cbUpload( status, fileid, errors ) {
129
        function cbUpload( status, fileid, errors ) {
Lines 154-164 Link Here
154
            if (f.uploadedfileid.value == '') {
149
            if (f.uploadedfileid.value == '') {
155
                alert(_("Please upload a file first."));
150
                alert(_("Please upload a file first."));
156
            } else {
151
            } else {
157
                $("#fileuploadstatus").hide();
152
                return f.submit();
158
                $("#fileuploadform").slideUp();
159
                $("#mainformsubmit").prop('disabled',true);
160
                $("#queueformsubmit").prop('disabled',true);
161
                return submitBackgroundJob(f);
162
            }
153
            }
163
            return false;
154
            return false;
164
        }
155
        }
(-)a/offline_circ/process_koc.pl (-61 / +4 lines)
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
- 

Return to bug 33962