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

(-)a/tools/stage-marc-import.pl (-30 / +24 lines)
Lines 44-51 use C4::BackgroundJob; Link Here
44
use C4::MarcModificationTemplates;
44
use C4::MarcModificationTemplates;
45
45
46
my $input = new CGI;
46
my $input = new CGI;
47
my $dbh = C4::Context->dbh;
48
$dbh->{AutoCommit} = 0;
49
47
50
my $fileID=$input->param('uploadedfileid');
48
my $fileID=$input->param('uploadedfileid');
51
my $runinbackground = $input->param('runinbackground');
49
my $runinbackground = $input->param('runinbackground');
Lines 91-98 if ($completedJobID) { Link Here
91
89
92
    my $filename = $uploaded_file->name();
90
    my $filename = $uploaded_file->name();
93
    my $job = undef;
91
    my $job = undef;
94
    my $staging_callback = sub { };
92
    my $dbh;
95
    my $matching_callback = sub { };
96
    if ($runinbackground) {
93
    if ($runinbackground) {
97
        my $job_size = () = $marcrecord =~ /\035/g;
94
        my $job_size = () = $marcrecord =~ /\035/g;
98
        # if we're matching, job size is doubled
95
        # if we're matching, job size is doubled
Lines 104-115 if ($completedJobID) { Link Here
104
        if (my $pid = fork) {
101
        if (my $pid = fork) {
105
            # parent
102
            # parent
106
            # return job ID as JSON
103
            # return job ID as JSON
107
            
108
            # prevent parent exiting from
109
            # destroying the kid's database handle
110
            # FIXME: according to DBI doc, this may not work for Oracle
111
            $dbh->{InactiveDestroy}  = 1;
112
113
            my $reply = CGI->new("");
104
            my $reply = CGI->new("");
114
            print $reply->header(-type => 'text/html');
105
            print $reply->header(-type => 'text/html');
115
            print '{"jobID":"' . $jobID . '"}';
106
            print '{"jobID":"' . $jobID . '"}';
Lines 122-142 if ($completedJobID) { Link Here
122
            # close STDERR; # there is no good reason to close STDERR
113
            # close STDERR; # there is no good reason to close STDERR
123
        } else {
114
        } else {
124
            # fork failed, so exit immediately
115
            # fork failed, so exit immediately
125
            warn "fork failed while attempting to run $ENV{'SCRIPT_NAME'} as a background job";
116
            warn "fork failed while attempting to run $ENV{'SCRIPT_NAME'} as a background job: $!";
126
            exit 0;
117
            exit 0;
127
        }
118
        }
128
119
129
        # if we get here, we're a child that has detached
120
        # if we get here, we're a child that has detached
130
        # itself from Apache
121
        # itself from Apache
131
        $staging_callback = staging_progress_callback($job, $dbh);
132
        $matching_callback = matching_progress_callback($job, $dbh);
133
122
134
    }
123
    }
135
124
125
    # New handle, as we're a child.
126
    $dbh = C4::Context->dbh({new => 1});
127
    $dbh->{AutoCommit} = 0;
136
    # FIXME branch code
128
    # FIXME branch code
137
    my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($record_type, $encoding, $marcrecord, $filename, $marc_modification_template, $comments, '', $parse_items, 0, 50, staging_progress_callback($job, $dbh));
129
    my ( $batch_id, $num_valid, $num_items, @import_errors ) =
138
130
      BatchStageMarcRecords(
139
    $dbh->commit();
131
        $record_type,                $encoding,
132
        $marcrecord,                 $filename,
133
        $marc_modification_template, $comments,
134
        '',                          $parse_items,
135
        0,                           50,
136
        staging_progress_callback( $job, $dbh )
137
      );
140
138
141
    my $num_with_matches = 0;
139
    my $num_with_matches = 0;
142
    my $checked_matches = 0;
140
    my $checked_matches = 0;
Lines 147-154 if ($completedJobID) { Link Here
147
        if (defined $matcher) {
145
        if (defined $matcher) {
148
            $checked_matches = 1;
146
            $checked_matches = 1;
149
            $matcher_code = $matcher->code();
147
            $matcher_code = $matcher->code();
150
            $num_with_matches = BatchFindDuplicates($batch_id, $matcher,
148
            $num_with_matches =
151
                                                       10, 50, matching_progress_callback($job, $dbh));
149
              BatchFindDuplicates( $batch_id, $matcher, 10, 50,
150
                matching_progress_callback( $job, $dbh ) );
152
            SetImportBatchMatcher($batch_id, $matcher_id);
151
            SetImportBatchMatcher($batch_id, $matcher_id);
153
            SetImportBatchOverlayAction($batch_id, $overlay_action);
152
            SetImportBatchOverlayAction($batch_id, $overlay_action);
154
            SetImportBatchNoMatchAction($batch_id, $nomatch_action);
153
            SetImportBatchNoMatchAction($batch_id, $nomatch_action);
Lines 160-173 if ($completedJobID) { Link Here
160
    }
159
    }
161
160
162
    my $results = {
161
    my $results = {
163
	    staged => $num_valid,
162
        staged          => $num_valid,
164
 	    matched => $num_with_matches,
163
        matched         => $num_with_matches,
165
        num_items => $num_items,
164
        num_items       => $num_items,
166
        import_errors => scalar(@import_errors),
165
        import_errors   => scalar(@import_errors),
167
        total => $num_valid + scalar(@import_errors),
166
        total           => $num_valid + scalar(@import_errors),
168
        checked_matches => $checked_matches,
167
        checked_matches => $checked_matches,
169
        matcher_failed => $matcher_failed,
168
        matcher_failed  => $matcher_failed,
170
        matcher_code => $matcher_code,
169
        matcher_code    => $matcher_code,
171
        import_batch_id => $batch_id
170
        import_batch_id => $batch_id
172
    };
171
    };
173
    if ($runinbackground) {
172
    if ($runinbackground) {
Lines 183-190 if ($completedJobID) { Link Here
183
                         matcher_code => $matcher_code,
182
                         matcher_code => $matcher_code,
184
                         import_batch_id => $batch_id
183
                         import_batch_id => $batch_id
185
                        );
184
                        );
186
187
188
    }
185
    }
189
186
190
} else {
187
} else {
Lines 210-216 sub staging_progress_callback { Link Here
210
    return sub {
207
    return sub {
211
        my $progress = shift;
208
        my $progress = shift;
212
        $job->progress($progress);
209
        $job->progress($progress);
213
        $dbh->commit();
214
    }
210
    }
215
}
211
}
216
212
Lines 221-226 sub matching_progress_callback { Link Here
221
    return sub {
217
    return sub {
222
        my $progress = shift;
218
        my $progress = shift;
223
        $job->progress($start_progress + $progress);
219
        $job->progress($start_progress + $progress);
224
        $dbh->commit();
225
    }
220
    }
226
}
221
}
227
- 

Return to bug 8970