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

(-)a/C4/Biblio.pm (-3 / +9 lines)
Lines 3240-3248 sub _koha_delete_biblio_metadata { Link Here
3240
3240
3241
=head1 UNEXPORTED FUNCTIONS
3241
=head1 UNEXPORTED FUNCTIONS
3242
3242
3243
=head2 Update005Time
3243
=head2 UpdateMarcTimestamp
3244
3244
3245
  &Update005Time( $record );
3245
  &UpdateMarcTimestamp( $record );
3246
3246
3247
Updates the 005 timestamp of the given record to the current time.
3247
Updates the 005 timestamp of the given record to the current time.
3248
3248
Lines 3257-3263 sub UpdateMarcTimestamp { Link Here
3257
        my @a = (localtime) [5,4,3,2,1,0]; $a[0]+=1900; $a[1]++;
3257
        my @a = (localtime) [5,4,3,2,1,0]; $a[0]+=1900; $a[1]++;
3258
        # YY MM DD HH MM SS (update year and month)
3258
        # YY MM DD HH MM SS (update year and month)
3259
        my $f005 = $record->field('005');
3259
        my $f005 = $record->field('005');
3260
        $f005->update( sprintf( "%4d%02d%02d%02d%02d%04.1f",@a ) ) if $f005;
3260
3261
        unless ($f005) {
3262
            $f005 = MARC::Field->new('005');
3263
            $record->insert_fields_ordered( $f005 );
3264
        }
3265
3266
        $f005->update( sprintf( "%4d%02d%02d%02d%02d%04.1f",@a ) );
3261
    }
3267
    }
3262
}
3268
}
3263
3269
(-)a/C4/ImportBatch.pm (-41 / +114 lines)
Lines 29-34 use C4::AuthoritiesMarc; Link Here
29
use C4::MarcModificationTemplates;
29
use C4::MarcModificationTemplates;
30
use DateTime;
30
use DateTime;
31
use DateTime::Format::Strptime;
31
use DateTime::Format::Strptime;
32
use Koha::Database;
32
use Koha::Plugins::Handler;
33
use Koha::Plugins::Handler;
33
use Koha::Logger;
34
use Koha::Logger;
34
35
Lines 49-54 BEGIN { Link Here
49
    AddItemsToImportBiblio
50
    AddItemsToImportBiblio
50
    ModAuthorityInBatch
51
    ModAuthorityInBatch
51
    ModBiblioInBatch
52
    ModBiblioInBatch
53
    CheckRecordControlNumberInBatch
52
54
53
    BatchStageMarcRecords
55
    BatchStageMarcRecords
54
    BatchFindDuplicates
56
    BatchFindDuplicates
Lines 312-317 sub ModBiblioInBatch { Link Here
312
314
313
}
315
}
314
316
317
=head2 CheckRecordControlNumberInBatch
318
319
  CheckRecordControlNumberInBatch( $marc_record, $batch_id[, $import_record_id] );
320
321
Check to see if the given record's control number is already in use in the given batch. If provided,
322
will check only for conflicts in records besides the given C<$import_batch_id>.
323
324
If a record with the given control number in the given batch exists, will return its C<import_record_id>.
325
326
=cut
327
328
sub CheckRecordControlNumberInBatch {
329
    my ( $marc_record, $batch_id, $import_record_id ) = @_;
330
331
    return unless ( $marc_record->field('001') );
332
333
    my %extra_conditions;
334
335
    $extra_conditions{'import_record.import_record_id'} = { '!=', $import_record_id } if ( $import_record_id );
336
337
    my $control_number = $marc_record->field('001')->data;
338
339
    my $schema = Koha::Database->new()->schema();
340
    return $schema->resultset('ImportBiblio')->search(
341
        {
342
            control_number => $control_number,
343
            'import_record.import_batch_id' => $batch_id,
344
            %extra_conditions
345
        },
346
        {
347
            join => 'import_record',
348
        }
349
    )->get_column('import_record.import_batch_id')->first();
350
}
351
315
=head2 AddAuthToBatch
352
=head2 AddAuthToBatch
316
353
317
  my $import_record_id = AddAuthToBatch($batch_id, $record_sequence,
354
  my $import_record_id = AddAuthToBatch($batch_id, $record_sequence,
Lines 352-428 sub ModAuthInBatch { Link Here
352
389
353
=head2 BatchStageMarcRecords
390
=head2 BatchStageMarcRecords
354
391
355
( $batch_id, $num_records, $num_items, @invalid_records ) =
392
{
356
  BatchStageMarcRecords(
393
    batch_id => $batch_id,
357
    $record_type,                $encoding,
394
    num_records => $num_records,
358
    $marc_records,               $file_name,
395
    num_items => $num_items,
359
    $marc_modification_template, $comments,
396
    invalid_records => \@invalid_records
360
    $branch_code,                $parse_items,
397
} = BatchStageMarcRecords( {
361
    $leave_as_staging,           $progress_interval,
398
    record_type => $record_type,
362
    $progress_callback
399
    encoding => $encoding,
363
  );
400
    marc_records => $marc_records,
401
    file_name => $file_name,
402
    comments => $comments,
403
    [ control_number_handling => 'preserve' | 'overwrite' ],
404
    [ existing_batch_id => $existing_batch_id, ]
405
    [ leave_as_staging => 1 ]
406
    [ marc_modification_template => $marc_modification_template, ]
407
    [ parse_items => 1 ]
408
    [ progress_interval => $progress_interval,
409
    progress_callback => \&progress_callback, ]
410
    [ timestamp_update => 'now' ],
411
    [ to_marc_plugin => $to_marc_plugin, ]
412
} );
413
414
Any optional parameters are assumed to be no / off if omitted. If C<progress_interval> is specified, C<progress_callback> must be as well.
364
415
365
=cut
416
=cut
366
417
367
sub BatchStageMarcRecords {
418
sub BatchStageMarcRecords {
368
    my $record_type = shift;
419
    my $params = shift;
369
    my $encoding = shift;
370
    my $marc_records = shift;
371
    my $file_name = shift;
372
    my $marc_modification_template = shift;
373
    my $comments = shift;
374
    my $branch_code = shift;
375
    my $parse_items = shift;
376
    my $leave_as_staging = shift;
377
378
    # optional callback to monitor status 
420
    # optional callback to monitor status 
379
    # of job
421
    # of job
380
    my $progress_interval = 0;
422
    my $progress_interval = 0;
381
    my $progress_callback = undef;
423
    my $progress_callback = undef;
382
    if ($#_ >= 1) {
424
    if ( $params->{progress_interval} ) {
383
        $progress_interval = shift;
425
        $progress_interval = $params->{progress_interval};
384
        $progress_callback = shift;
426
        $progress_callback = $params->{progress_callback};
385
        $progress_interval = 0 unless $progress_interval =~ /^\d+$/ and $progress_interval > 0;
427
        $progress_interval = 0 unless $progress_interval =~ /^\d+$/ and $progress_interval > 0;
386
        $progress_interval = 0 unless 'CODE' eq ref $progress_callback;
428
        $progress_interval = 0 unless 'CODE' eq ref $progress_callback;
387
    }
429
    }
388
    my $existing_batch_id = shift;
389
    
430
    
390
    my $batch_id;
431
    my $batch_id;
391
432
392
    if ( $existing_batch_id ) {
433
    if ( $params->{existing_batch_id} ) {
393
        $batch_id = $existing_batch_id;
434
        $batch_id = $params->{existing_batch_id};
394
    } else {
435
    } else {
395
        $batch_id = AddImportBatch( {
436
        $batch_id = AddImportBatch( {
396
                overlay_action => 'create_new',
437
                overlay_action => 'create_new',
397
                import_status => 'staging',
438
                import_status => 'staging',
398
                batch_type => 'batch',
439
                batch_type => 'batch',
399
                file_name => $file_name,
440
                file_name => $params->{file_name},
400
                comments => $comments,
441
                comments => $params->{comments},
401
                record_type => $record_type,
442
                record_type => $params->{record_type},
402
            } );
443
            } );
403
    }
444
    }
404
445
405
    if ($parse_items) {
446
    if ($params->{parse_items}) {
406
        SetImportBatchItemAction($batch_id, 'always_add');
447
        SetImportBatchItemAction($batch_id, 'always_add');
407
    } else {
448
    } else {
408
        SetImportBatchItemAction($batch_id, 'ignore');
449
        SetImportBatchItemAction($batch_id, 'ignore');
409
    }
450
    }
410
451
411
412
    my $marc_type = C4::Context->preference('marcflavour');
452
    my $marc_type = C4::Context->preference('marcflavour');
413
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
453
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $params->{record_type} eq 'auth');
414
    my @invalid_records = ();
454
    my @invalid_records = ();
415
    my $num_valid = 0;
455
    my $num_valid = 0;
416
    my $num_items = 0;
456
    my $num_items = 0;
457
    my $num_matched_control_number = 0;
417
    # FIXME - for now, we're dealing only with bibs
458
    # FIXME - for now, we're dealing only with bibs
418
    my $rec_num = 0;
459
    my $rec_num = 0;
419
    foreach my $marc_record (@$marc_records) {
460
    foreach my $marc_record (@{$params->{marc_records}}) {
461
        next unless $marc_record;
420
        $rec_num++;
462
        $rec_num++;
421
        if ($progress_interval and (0 == ($rec_num % $progress_interval))) {
463
        if ($progress_interval and (0 == ($rec_num % $progress_interval))) {
422
            &$progress_callback($rec_num);
464
            &$progress_callback($rec_num);
423
        }
465
        }
424
466
425
        ModifyRecordWithTemplate( $marc_modification_template, $marc_record ) if ( $marc_modification_template );
467
        ModifyRecordWithTemplate( $params->{marc_modification_template}, $marc_record ) if ( $params->{marc_modification_template} );
426
468
427
        my $import_record_id;
469
        my $import_record_id;
428
        if (scalar($marc_record->fields()) == 0) {
470
        if (scalar($marc_record->fields()) == 0) {
Lines 431-455 sub BatchStageMarcRecords { Link Here
431
473
432
            # Normalize the record so it doesn't have separated diacritics
474
            # Normalize the record so it doesn't have separated diacritics
433
            SetUTF8Flag($marc_record);
475
            SetUTF8Flag($marc_record);
434
435
            $num_valid++;
476
            $num_valid++;
436
            if ($record_type eq 'biblio') {
477
437
                $import_record_id = AddBiblioToBatch($batch_id, $rec_num, $marc_record, $encoding, int(rand(99999)), 0);
478
            C4::Biblio::UpdateMarcTimestamp( $marc_record ) if ( $params->{timestamp_update} eq 'now' );
438
                if ($parse_items) {
479
            my $existing_import_record_id;
480
481
            if ( $params->{control_number_handling} ) {
482
                $existing_import_record_id = CheckRecordControlNumberInBatch( $marc_record, $batch_id );
483
484
                if ( $existing_import_record_id ) {
485
                    $num_matched_control_number++;
486
487
                    next if ( $params->{control_number_handling} eq 'preserve' );
488
                }
489
            }
490
491
            if ($params->{record_type} eq 'biblio') {
492
                if ( $existing_import_record_id ) {
493
                    $import_record_id = $existing_import_record_id;
494
                    ModBiblioInBatch( $import_record_id, $marc_record );
495
                } else {
496
                    $import_record_id = AddBiblioToBatch($batch_id, $rec_num, $marc_record, $params->{encoding}, int(rand(99999)), 0);
497
                }
498
499
                if ($params->{parse_items}) {
439
                    my @import_items_ids = AddItemsToImportBiblio($batch_id, $import_record_id, $marc_record, 0);
500
                    my @import_items_ids = AddItemsToImportBiblio($batch_id, $import_record_id, $marc_record, 0);
440
                    $num_items += scalar(@import_items_ids);
501
                    $num_items += scalar(@import_items_ids);
441
                }
502
                }
442
            } elsif ($record_type eq 'auth') {
503
            } elsif ($params->{record_type} eq 'auth') {
443
                $import_record_id = AddAuthToBatch($batch_id, $rec_num, $marc_record, $encoding, int(rand(99999)), 0, $marc_type);
504
                if ( $existing_import_record_id ) {
505
                    $import_record_id = $existing_import_record_id;
506
                    ModAuthInBatch( $import_record_id, $marc_record );
507
                } else {
508
                    $import_record_id = AddAuthToBatch($batch_id, $rec_num, $marc_record, $params->{encoding}, int(rand(99999)), 0, $marc_type);
509
                }
444
            }
510
            }
445
        }
511
        }
446
    }
512
    }
447
    unless ($leave_as_staging) {
513
    unless ($params->{leave_as_staging}) {
448
        SetImportBatchStatus($batch_id, 'staged');
514
        SetImportBatchStatus($batch_id, 'staged');
449
    }
515
    }
450
    # FIXME branch_code, number of bibs, number of items
516
    # FIXME branch_code, number of bibs, number of items
451
    _update_batch_record_counts($batch_id);
517
    _update_batch_record_counts($batch_id);
452
    return ($batch_id, $num_valid, $num_items, @invalid_records);
518
    return {
519
        batch_id => $batch_id,
520
        num_items => $num_items,
521
        num_valid => $num_valid,
522
        num_matched_control_number => $num_matched_control_number,
523
        invalid_records => \@invalid_records
524
    };
453
}
525
}
454
526
455
=head2 AddItemsToImportBiblio
527
=head2 AddItemsToImportBiblio
Lines 468-473 sub AddItemsToImportBiblio { Link Here
468
    my @import_items_ids = ();
540
    my @import_items_ids = ();
469
   
541
   
470
    my $dbh = C4::Context->dbh; 
542
    my $dbh = C4::Context->dbh; 
543
    $dbh->do( "DELETE FROM import_items WHERE import_record_id = ?", undef, $import_record_id );
471
    my ($item_tag,$item_subfield) = &GetMarcFromKohaField("items.itemnumber",'');
544
    my ($item_tag,$item_subfield) = &GetMarcFromKohaField("items.itemnumber",'');
472
    foreach my $item_field ($marc_record->field($item_tag)) {
545
    foreach my $item_field ($marc_record->field($item_tag)) {
473
        my $item_marc = MARC::Record->new();
546
        my $item_marc = MARC::Record->new();
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt (+30 lines)
Lines 40-45 Link Here
40
	<li>[% total %]  records in file</li>
40
	<li>[% total %]  records in file</li>
41
	<li>[% import_errors %] records not staged because of MARC error</li>
41
	<li>[% import_errors %] records not staged because of MARC error</li>
42
	<li>[% staged %] records staged</li>
42
	<li>[% staged %] records staged</li>
43
    [% IF control_number_handling %]
44
	<li>
45
        [% num_matched_control_number %] records with matching control number
46
        [% IF control_number_handling == 'preserve' %]
47
        (preserved)
48
        [% ELSIF control_number_handling == 'overwrite' %]
49
        (overwritten)
50
        [% END %]
51
    </li>
52
    [% END %]
43
    [% IF ( checked_matches ) %]
53
    [% IF ( checked_matches ) %]
44
	<li>[% matched %] records with at least one match in catalog per matching rule 
54
	<li>[% matched %] records with at least one match in catalog per matching rule 
45
        &quot;[% matcher_code %]&quot;</li>
55
        &quot;[% matcher_code %]&quot;</li>
Lines 166-171 Link Here
166
      </li>
176
      </li>
167
    </ol>
177
    </ol>
168
  </fieldset>
178
  </fieldset>
179
  <fieldset class="rows" id="record-update">
180
    <legend>Automatically update records?</legend>
181
    <ol>
182
        [% IF existing_batch_id %]
183
            <li><label for="control_number_handling">How to process 001:</label>
184
            <select name="control_number_handling" id="control_number_handling">
185
               <option value="">Ignore</option>
186
               <option value="overwrite">Overwrite existing records with same 001</option>
187
               <option value="preserve">Preserve existing records with same 001</option>
188
            </select>
189
            </li>
190
        [% END %]
191
        <li><label for="timestamp_update">How to process 005:</label>
192
        <select name="timestamp_update" id="timestamp_update">
193
           <option value="">Do not update 005</option>
194
           <option value="now">Set 005 to current date and time</option>
195
        </select>
196
        </li>
197
    </ol>
198
  </fieldset>
169
  <fieldset class="rows" id="items">
199
  <fieldset class="rows" id="items">
170
    <legend>Check for embedded item record data?</legend>
200
    <legend>Check for embedded item record data?</legend>
171
    <ol>
201
    <ol>
(-)a/misc/stage_file.pl (-13 / +21 lines)
Lines 115-130 sub process_batch { Link Here
115
115
116
    print "... staging MARC records -- please wait\n";
116
    print "... staging MARC records -- please wait\n";
117
    #FIXME: We should really allow the use of marc modification frameworks and to_marc plugins here if possible
117
    #FIXME: We should really allow the use of marc modification frameworks and to_marc plugins here if possible
118
    my ($batch_id, $num_valid_records, $num_items, @import_errors) =
118
    my (@import_errors) =
119
        BatchStageMarcRecords($record_type, $params->{encoding}, $marc_records, $params->{input_file}, undef, $params->{batch_comment}, '', $params->{add_items}, 0,
119
    my $stage_results = BatchStageMarcRecords( {
120
                              100, \&print_progress_and_commit);
120
        record_type => $record_type,
121
        encoding => $encoding,
122
        marc_records => $marc_records,
123
        file_name => $input_file,
124
        comments => $batch_comment,
125
        parse_items => $add_items,
126
        progress_interval => 100,
127
        progress_callback => \&print_progress_and_commit
128
    } );
121
    print "... finished staging MARC records\n";
129
    print "... finished staging MARC records\n";
122
130
123
    my $num_with_matches = 0;
131
    my $num_with_matches = 0;
124
    if ( $params->{match} ) {
132
    if ( $params->{match} ) {
125
        my $matcher = C4::Matcher->fetch( $params->{match} );
133
        my $matcher = C4::Matcher->fetch( $params->{match} );
126
        if (defined $matcher) {
134
        if (defined $matcher) {
127
            SetImportBatchMatcher( $batch_id, $params->{match} );
135
            SetImportBatchMatcher($stage_results->{batch_id}, $params->{match});
128
        } elsif ($record_type eq 'biblio')  {
136
        } elsif ($record_type eq 'biblio')  {
129
            $matcher = C4::Matcher->new($record_type);
137
            $matcher = C4::Matcher->new($record_type);
130
            $matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, '');
138
            $matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, '');
Lines 132-146 sub process_batch { Link Here
132
                                            '245', 'a', -1, 0, '');
140
                                            '245', 'a', -1, 0, '');
133
        }
141
        }
134
        # set default record overlay behavior
142
        # set default record overlay behavior
135
        SetImportBatchOverlayAction( $batch_id, $params->{no_replace} ? 'ignore' : 'replace' );
143
        SetImportBatchOverlayAction($stage_results->{batch_id}, $params->{no_replace} ? 'ignore' : 'replace');
136
        SetImportBatchNoMatchAction( $batch_id, $params->{no_create} ? 'ignore' : 'create_new' );
144
        SetImportBatchNoMatchAction($stage_results->{batch_id}, $params->{no_create} ? 'ignore' : 'create_new');
137
        SetImportBatchItemAction( $batch_id, $params->{item_action} );
145
        SetImportBatchItemAction($stage_results->{batch_id}, $params->{item_action} );
138
        print "... looking for matches with records already in database\n";
146
        print "... looking for matches with records already in database\n";
139
        $num_with_matches = BatchFindDuplicates($batch_id, $matcher, 10, 100, \&print_progress_and_commit);
147
        $num_with_matches = BatchFindDuplicates($stage_results->{batch_id}, $matcher, 10, 100, \&print_progress_and_commit);
140
        print "... finished looking for matches\n";
148
        print "... finished looking for matches\n";
141
    }
149
    }
142
150
143
    my $num_invalid_records = scalar(@import_errors);
151
    my $num_invalid_records = scalar( @{ $stage_results->{invalid_records} } );
144
    print <<_SUMMARY_;
152
    print <<_SUMMARY_;
145
153
146
MARC record staging report
154
MARC record staging report
Lines 148-154 MARC record staging report Link Here
148
Input file:                 $params->{input_file}
156
Input file:                 $params->{input_file}
149
Record type:                $record_type
157
Record type:                $record_type
150
Number of input records:    $num_input_records
158
Number of input records:    $num_input_records
151
Number of valid records:    $num_valid_records
159
Number of valid records:    $stage_results->{num_valid}
152
Number of invalid records:  $num_invalid_records
160
Number of invalid records:  $num_invalid_records
153
_SUMMARY_
161
_SUMMARY_
154
    if( $params->{match} ) {
162
    if( $params->{match} ) {
Lines 157-171 _SUMMARY_ Link Here
157
        print "Incoming records not matched against existing records (--match option not supplied)\n";
165
        print "Incoming records not matched against existing records (--match option not supplied)\n";
158
    }
166
    }
159
    if ($record_type eq 'biblio') {
167
    if ($record_type eq 'biblio') {
160
        if ( $params->{add_items} ) {
168
        if ($params->{add_items} ) {
161
            print "Number of items parsed:  $num_items\n";
169
            print "Number of items parsed:  $stage_results->{num_items}\n";
162
        } else {
170
        } else {
163
            print "No items parsed (--add-items option not supplied)\n";
171
            print "No items parsed (--add-items option not supplied)\n";
164
        }
172
        }
165
    }
173
    }
166
174
167
    print "\n";
175
    print "\n";
168
    print "Batch number assigned:  $batch_id\n";
176
    print "Batch number assigned:  $stage_results->{batch_id}\n";
169
    print "\n";
177
    print "\n";
170
}
178
}
171
179
(-)a/svc/cataloguing/import_batches (-27 / +3 lines)
Lines 21-27 use Modern::Perl; Link Here
21
21
22
use C4::Biblio qw();
22
use C4::Biblio qw();
23
use C4::Context;
23
use C4::Context;
24
use C4::ImportBatch qw( AddBiblioToBatch AddImportBatch GetImportRecordMarcXML ModBiblioInBatch );
24
use C4::ImportBatch qw( AddBiblioToBatch AddImportBatch GetImportRecordMarcXML ModBiblioInBatch CheckRecordControlNumberInBatch );
25
use C4::Service;
25
use C4::Service;
26
use DateTime;
26
use DateTime;
27
use DateTime::Format::Strptime;
27
use DateTime::Format::Strptime;
Lines 132-161 sub get_record { Link Here
132
    C4::Service->return_success( $response );
132
    C4::Service->return_success( $response );
133
}
133
}
134
134
135
sub _control_number_already_used {
136
    my ( $marc_record, $batch_id, $import_record_id ) = @_;
137
138
    return unless ( $marc_record->field('001') );
139
140
    my %extra_conditions;
141
142
    $extra_conditions{'import_record.import_record_id'} = { '!=', $import_record_id } if ( $import_record_id );
143
144
    my $control_number = $marc_record->field('001')->data;
145
146
    my $schema = Koha::Database->new()->schema();
147
    return $schema->resultset('ImportBiblio')->count(
148
        {
149
            control_number => $control_number,
150
            'import_record.import_batch_id' => $batch_id,
151
            %extra_conditions
152
        },
153
        {
154
            join => 'import_record',
155
        }
156
    );
157
}
158
159
sub create_record {
135
sub create_record {
160
    my ( $batch_id ) = @_;
136
    my ( $batch_id ) = @_;
161
137
Lines 165-171 sub create_record { Link Here
165
        C4::Service->return_error( 'failed', $@ );
141
        C4::Service->return_error( 'failed', $@ );
166
    }
142
    }
167
143
168
    if ( !$query->param('allow_control_number_conflict') && _control_number_already_used( $marc_record, $batch_id ) ) {
144
    if ( !$query->param('allow_control_number_conflict') && CheckRecordControlNumberInBatch( $marc_record, $batch_id ) ) {
169
        C4::Service->return_error( 'control_number_match', '' );
145
        C4::Service->return_error( 'control_number_match', '' );
170
    }
146
    }
171
147
Lines 184-190 sub update_record { Link Here
184
        C4::Service->return_error( 'failed', $@ );
160
        C4::Service->return_error( 'failed', $@ );
185
    }
161
    }
186
162
187
    if ( !$query->param('allow_control_number_conflict') &&  _control_number_already_used( $marc_record, $batch_id, $import_record_id ) ) {
163
    if ( !$query->param('allow_control_number_conflict') && CheckRecordControlNumberInBatch( $marc_record, $batch_id, $import_record_id ) ) {
188
        C4::Service->return_error( 'control_number_match', '' );
164
        C4::Service->return_error( 'control_number_match', '' );
189
    }
165
    }
190
166
(-)a/tools/stage-marc-import.pl (-31 / +29 lines)
Lines 59-64 my $encoding = $input->param('encoding') || 'UTF-8'; Link Here
59
my $format                     = $input->param('format') || 'ISO2709';
59
my $format                     = $input->param('format') || 'ISO2709';
60
my $marc_modification_template = $input->param('marc_modification_template_id');
60
my $marc_modification_template = $input->param('marc_modification_template_id');
61
my $existing_batch_id          = $input->param('existing_batch_id');
61
my $existing_batch_id          = $input->param('existing_batch_id');
62
my $control_number_handling    = $input->param('control_number_handling');
63
my $timestamp_update           = $input->param('timestamp_update');
62
64
63
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
64
    {
66
    {
Lines 139-154 if ($completedJobID) { Link Here
139
    $dbh = C4::Context->dbh({new => 1});
141
    $dbh = C4::Context->dbh({new => 1});
140
    $dbh->{AutoCommit} = 0;
142
    $dbh->{AutoCommit} = 0;
141
    # FIXME branch code
143
    # FIXME branch code
142
    my ( $batch_id, $num_valid, $num_items, @import_errors ) =
144
    my $stage_results = BatchStageMarcRecords( {
143
      BatchStageMarcRecords(
145
        record_type => $record_type,
144
        $record_type,    $encoding,
146
        encoding => $encoding,
145
        $marcrecords,    $filename,
147
        marc_records => $marcrecords,
146
        $marc_modification_template,
148
        file_name => $filename,
147
        $comments,       '',
149
        marc_modification_template => $marc_modification_template,
148
        $parse_items,    0,
150
        comments => $comments,
149
        50, staging_progress_callback( $job, $dbh ),
151
        parse_items => $parse_items,
150
        $existing_batch_id
152
        progress_interval => 50,
151
      );
153
        progress_callback => staging_progress_callback( $job, $dbh ),
154
        existing_batch_id => $existing_batch_id,
155
        control_number_handling => $control_number_handling,
156
        timestamp_update => $timestamp_update,
157
    } );
152
158
153
    my $num_with_matches = 0;
159
    my $num_with_matches = 0;
154
    my $checked_matches = 0;
160
    my $checked_matches = 0;
Lines 160-171 if ($completedJobID) { Link Here
160
            $checked_matches = 1;
166
            $checked_matches = 1;
161
            $matcher_code = $matcher->code();
167
            $matcher_code = $matcher->code();
162
            $num_with_matches =
168
            $num_with_matches =
163
              BatchFindDuplicates( $batch_id, $matcher, 10, 50,
169
              BatchFindDuplicates( $stage_results->{batch_id}, $matcher, 10, 50,
164
                matching_progress_callback( $job, $dbh ) );
170
                matching_progress_callback( $job, $dbh ) );
165
            SetImportBatchMatcher($batch_id, $matcher_id);
171
            SetImportBatchMatcher( $stage_results->{batch_id}, $matcher_id );
166
            SetImportBatchOverlayAction($batch_id, $overlay_action);
172
            SetImportBatchOverlayAction( $stage_results->{batch_id}, $overlay_action );
167
            SetImportBatchNoMatchAction($batch_id, $nomatch_action);
173
            SetImportBatchNoMatchAction( $stage_results->{batch_id}, $nomatch_action );
168
            SetImportBatchItemAction($batch_id, $item_action);
174
            SetImportBatchItemAction( $stage_results->{batch_id}, $item_action );
169
            $dbh->commit();
175
            $dbh->commit();
170
        } else {
176
        } else {
171
            $matcher_failed = 1;
177
            $matcher_failed = 1;
Lines 175-204 if ($completedJobID) { Link Here
175
    }
181
    }
176
182
177
    my $results = {
183
    my $results = {
178
        staged          => $num_valid,
184
        staged          => $stage_results->{num_valid},
179
        matched         => $num_with_matches,
185
        matched         => $num_with_matches,
180
        num_items       => $num_items,
186
        num_items       => $stage_results->{num_items},
181
        import_errors   => scalar(@import_errors),
187
        import_errors   => scalar( @{ $stage_results->{invalid_records} } ),
182
        total           => $num_valid + scalar(@import_errors),
188
        total           => $stage_results->{num_valid} + scalar( @{ $stage_results->{invalid_records} } ),
183
        checked_matches => $checked_matches,
189
        checked_matches => $checked_matches,
184
        matcher_failed  => $matcher_failed,
190
        matcher_failed  => $matcher_failed,
185
        matcher_code    => $matcher_code,
191
        matcher_code    => $matcher_code,
186
        import_batch_id => $batch_id
192
        import_batch_id => $stage_results->{batch_id},
193
        control_number_handling => $control_number_handling,
194
        num_matched_control_number => $stage_results->{num_matched_control_number},
187
    };
195
    };
188
    if ($runinbackground) {
196
    if ($runinbackground) {
189
        $job->finish($results);
197
        $job->finish($results);
190
        exit 0;
198
        exit 0;
191
    } else {
199
    } else {
192
	    $template->param(staged => $num_valid,
200
	    $template->param( %$results );
193
 	                     matched => $num_with_matches,
194
                         num_items => $num_items,
195
                         import_errors => scalar(@import_errors),
196
                         total => $num_valid + scalar(@import_errors),
197
                         checked_matches => $checked_matches,
198
                         matcher_failed => $matcher_failed,
199
                         matcher_code => $matcher_code,
200
                         import_batch_id => $batch_id
201
                        );
202
    }
201
    }
203
202
204
} else {
203
} else {
205
- 

Return to bug 19266