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

(-)a/C4/Biblio.pm (-3 / +9 lines)
Lines 3352-3360 sub _koha_delete_biblio_metadata { Link Here
3352
3352
3353
=head1 UNEXPORTED FUNCTIONS
3353
=head1 UNEXPORTED FUNCTIONS
3354
3354
3355
=head2 Update005Time
3355
=head2 UpdateMarcTimestamp
3356
3356
3357
  &Update005Time( $record );
3357
  &UpdateMarcTimestamp( $record );
3358
3358
3359
Updates the 005 timestamp of the given record to the current time.
3359
Updates the 005 timestamp of the given record to the current time.
3360
3360
Lines 3369-3375 sub UpdateMarcTimestamp { Link Here
3369
        my @a = (localtime) [5,4,3,2,1,0]; $a[0]+=1900; $a[1]++;
3369
        my @a = (localtime) [5,4,3,2,1,0]; $a[0]+=1900; $a[1]++;
3370
        # YY MM DD HH MM SS (update year and month)
3370
        # YY MM DD HH MM SS (update year and month)
3371
        my $f005 = $record->field('005');
3371
        my $f005 = $record->field('005');
3372
        $f005->update( sprintf( "%4d%02d%02d%02d%02d%04.1f",@a ) ) if $f005;
3372
3373
        unless ($f005) {
3374
            $f005 = MARC::Field->new('005');
3375
            $record->insert_fields_ordered( $f005 );
3376
        }
3377
3378
        $f005->update( sprintf( "%4d%02d%02d%02d%02d%04.1f",@a ) );
3373
    }
3379
    }
3374
}
3380
}
3375
3381
(-)a/C4/ImportBatch.pm (-39 / +127 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
420
378
    # optional callback to monitor status 
421
    # optional callback to monitor status 
379
    # of job
422
    # of job
380
    my $progress_interval = 0;
423
    my $progress_interval = 0;
381
    my $progress_callback = undef;
424
    my $progress_callback = undef;
382
    if ($#_ >= 1) {
425
    if ( $params->{progress_interval} ) {
383
        $progress_interval = shift;
426
        $progress_interval = $params->{progress_interval};
384
        $progress_callback = shift;
427
        $progress_callback = $params->{progress_callback};
385
        $progress_interval = 0 unless $progress_interval =~ /^\d+$/ and $progress_interval > 0;
428
        $progress_interval = 0 unless $progress_interval =~ /^\d+$/ and $progress_interval > 0;
386
        $progress_interval = 0 unless 'CODE' eq ref $progress_callback;
429
        $progress_interval = 0 unless 'CODE' eq ref $progress_callback;
387
    }
430
    }
388
    my $existing_batch_id = shift;
389
    
431
    
390
    my $batch_id;
432
    my $batch_id;
391
433
392
    if ( $existing_batch_id ) {
434
    if ( $params->{existing_batch_id} ) {
393
        $batch_id = $existing_batch_id;
435
        $batch_id = $params->{existing_batch_id};
394
    } else {
436
    } else {
395
        $batch_id = AddImportBatch( {
437
        $batch_id = AddImportBatch( {
396
                overlay_action => 'create_new',
438
                overlay_action => 'create_new',
397
                import_status => 'staging',
439
                import_status => 'staging',
398
                batch_type => 'batch',
440
                batch_type => 'batch',
399
                file_name => $file_name,
441
                file_name => $params->{file_name},
400
                comments => $comments,
442
                comments => $params->{comments},
401
                record_type => $record_type,
443
                record_type => $params->{record_type},
402
            } );
444
            } );
403
    }
445
    }
404
446
405
    if ($parse_items) {
447
    if ($params->{parse_items}) {
406
        SetImportBatchItemAction($batch_id, 'always_add');
448
        SetImportBatchItemAction($batch_id, 'always_add');
407
    } else {
449
    } else {
408
        SetImportBatchItemAction($batch_id, 'ignore');
450
        SetImportBatchItemAction($batch_id, 'ignore');
409
    }
451
    }
410
452
453
    $params->{marc_records} = Koha::Plugins::Handler->run(
454
        {
455
            class  => $params->{to_marc_plugin},
456
            method => 'to_marc',
457
            params => { data => $params->{marc_records} }
458
        }
459
    ) if $params->{to_marc_plugin} && @$marc_records;
411
460
412
    my $marc_type = C4::Context->preference('marcflavour');
461
    my $marc_type = C4::Context->preference('marcflavour');
413
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
462
    $marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $params->{record_type} eq 'auth');
414
    my @invalid_records = ();
463
    my @invalid_records = ();
415
    my $num_valid = 0;
464
    my $num_valid = 0;
416
    my $num_items = 0;
465
    my $num_items = 0;
466
    my $num_matched_control_number = 0;
417
    # FIXME - for now, we're dealing only with bibs
467
    # FIXME - for now, we're dealing only with bibs
418
    my $rec_num = 0;
468
    my $rec_num = 0;
419
    foreach my $marc_record (@$marc_records) {
469
    foreach my $marc_blob (@$marc_records) {
470
        $marc_blob =~ s/^\s+//g;
471
        $marc_blob =~ s/\s+$//g;
472
        next unless $marc_blob;
420
        $rec_num++;
473
        $rec_num++;
421
        if ($progress_interval and (0 == ($rec_num % $progress_interval))) {
474
        if ($progress_interval and (0 == ($rec_num % $progress_interval))) {
422
            &$progress_callback($rec_num);
475
            &$progress_callback($rec_num);
423
        }
476
        }
477
        my ($marc_record, $charset_guessed, $char_errors) =
478
            MarcToUTF8Record($marc_blob, $marc_type, $params->{encoding});
479
480
        $params->{encoding} = $charset_guessed unless $params->{encoding};
424
481
425
        ModifyRecordWithTemplate( $marc_modification_template, $marc_record ) if ( $marc_modification_template );
482
        ModifyRecordWithTemplate( $params->{marc_modification_template}, $marc_record ) if ( $params->{marc_modification_template} );
426
483
427
        my $import_record_id;
484
        my $import_record_id;
428
        if (scalar($marc_record->fields()) == 0) {
485
        if (scalar($marc_record->fields()) == 0) {
Lines 431-455 sub BatchStageMarcRecords { Link Here
431
488
432
            # Normalize the record so it doesn't have separated diacritics
489
            # Normalize the record so it doesn't have separated diacritics
433
            SetUTF8Flag($marc_record);
490
            SetUTF8Flag($marc_record);
434
435
            $num_valid++;
491
            $num_valid++;
436
            if ($record_type eq 'biblio') {
492
437
                $import_record_id = AddBiblioToBatch($batch_id, $rec_num, $marc_record, $encoding, int(rand(99999)), 0);
493
            C4::Biblio::UpdateMarcTimestamp( $marc_record ) if ( $params->{timestamp_update} eq 'now' );
438
                if ($parse_items) {
494
            my $existing_import_record_id;
495
496
            if ( $params->{control_number_handling} ) {
497
                $existing_import_record_id = CheckRecordControlNumberInBatch( $marc_record, $batch_id );
498
499
                if ( $existing_import_record_id ) {
500
                    $num_matched_control_number++;
501
502
                    next if ( $params->{control_number_handling} eq 'preserve' );
503
                }
504
            }
505
506
            if ($params->{record_type} eq 'biblio') {
507
                if ( $existing_import_record_id ) {
508
                    $import_record_id = $existing_import_record_id;
509
                    ModBiblioInBatch( $import_record_id, $marc_record );
510
                } else {
511
                    $import_record_id = AddBiblioToBatch($batch_id, $rec_num, $marc_record, $params->{encoding}, int(rand(99999)), 0);
512
                }
513
514
                if ($params->{parse_items}) {
439
                    my @import_items_ids = AddItemsToImportBiblio($batch_id, $import_record_id, $marc_record, 0);
515
                    my @import_items_ids = AddItemsToImportBiblio($batch_id, $import_record_id, $marc_record, 0);
440
                    $num_items += scalar(@import_items_ids);
516
                    $num_items += scalar(@import_items_ids);
441
                }
517
                }
442
            } elsif ($record_type eq 'auth') {
518
            } elsif ($params->{record_type} eq 'auth') {
443
                $import_record_id = AddAuthToBatch($batch_id, $rec_num, $marc_record, $encoding, int(rand(99999)), 0, $marc_type);
519
                if ( $existing_import_record_id ) {
520
                    $import_record_id = $existing_import_record_id;
521
                    ModAuthInBatch( $import_record_id, $marc_record );
522
                } else {
523
                    $import_record_id = AddAuthToBatch($batch_id, $rec_num, $marc_record, $params->{encoding}, int(rand(99999)), 0, $marc_type);
524
                }
444
            }
525
            }
445
        }
526
        }
446
    }
527
    }
447
    unless ($leave_as_staging) {
528
    unless ($params->{leave_as_staging}) {
448
        SetImportBatchStatus($batch_id, 'staged');
529
        SetImportBatchStatus($batch_id, 'staged');
449
    }
530
    }
450
    # FIXME branch_code, number of bibs, number of items
531
    # FIXME branch_code, number of bibs, number of items
451
    _update_batch_record_counts($batch_id);
532
    _update_batch_record_counts($batch_id);
452
    return ($batch_id, $num_valid, $num_items, @invalid_records);
533
    return {
534
        batch_id => $batch_id,
535
        num_items => $num_items,
536
        num_valid => $num_valid,
537
        num_matched_control_number => $num_matched_control_number,
538
        invalid_records => \@invalid_records
539
    };
453
}
540
}
454
541
455
=head2 AddItemsToImportBiblio
542
=head2 AddItemsToImportBiblio
Lines 468-473 sub AddItemsToImportBiblio { Link Here
468
    my @import_items_ids = ();
555
    my @import_items_ids = ();
469
   
556
   
470
    my $dbh = C4::Context->dbh; 
557
    my $dbh = C4::Context->dbh; 
558
    $dbh->do( "DELETE FROM import_items WHERE import_record_id = ?", undef, $import_record_id );
471
    my ($item_tag,$item_subfield) = &GetMarcFromKohaField("items.itemnumber",'');
559
    my ($item_tag,$item_subfield) = &GetMarcFromKohaField("items.itemnumber",'');
472
    foreach my $item_field ($marc_record->field($item_tag)) {
560
    foreach my $item_field ($marc_record->field($item_tag)) {
473
        my $item_marc = MARC::Record->new();
561
        my $item_marc = MARC::Record->new();
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt (+30 lines)
Lines 117-122 function cbUpload( status, fileid ) { Link Here
117
	<li>[% total %]  records in file</li>
117
	<li>[% total %]  records in file</li>
118
	<li>[% import_errors %] records not staged because of MARC error</li>
118
	<li>[% import_errors %] records not staged because of MARC error</li>
119
	<li>[% staged %] records staged</li>
119
	<li>[% staged %] records staged</li>
120
    [% IF control_number_handling %]
121
	<li>
122
        [% num_matched_control_number %] records with matching control number
123
        [% IF control_number_handling == 'preserve' %]
124
        (preserved)
125
        [% ELSIF control_number_handling == 'overwrite' %]
126
        (overwritten)
127
        [% END %]
128
    </li>
129
    [% END %]
120
    [% IF ( checked_matches ) %]
130
    [% IF ( checked_matches ) %]
121
	<li>[% matched %] records with at least one match in catalog per matching rule 
131
	<li>[% matched %] records with at least one match in catalog per matching rule 
122
        &quot;[% matcher_code %]&quot;</li>
132
        &quot;[% matcher_code %]&quot;</li>
Lines 243-248 function cbUpload( status, fileid ) { Link Here
243
      </li>
253
      </li>
244
    </ol>
254
    </ol>
245
  </fieldset>
255
  </fieldset>
256
  <fieldset class="rows" id="record-update">
257
    <legend>Automatically update records?</legend>
258
    <ol>
259
        [% IF existing_batch_id %]
260
            <li><label for="control_number_handling">How to process 001:</label>
261
            <select name="control_number_handling" id="control_number_handling">
262
               <option value="">Ignore</option>
263
               <option value="overwrite">Overwrite existing records with same 001</option>
264
               <option value="preserve">Preserve existing records with same 001</option>
265
            </select>
266
            </li>
267
        [% END %]
268
        <li><label for="timestamp_update">How to process 005:</label>
269
        <select name="timestamp_update" id="timestamp_update">
270
           <option value="">Do not update 005</option>
271
           <option value="now">Set 005 to current date and time</option>
272
        </select>
273
        </li>
274
    </ol>
275
  </fieldset>
246
  <fieldset class="rows" id="items">
276
  <fieldset class="rows" id="items">
247
    <legend>Check for embedded item record data?</legend>
277
    <legend>Check for embedded item record data?</legend>
248
    <ol>
278
    <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 / +30 lines)
Lines 60-65 my $encoding = $input->param('encoding') || 'UTF-8'; Link Here
60
my $format                     = $input->param('format') || 'ISO2709';
60
my $format                     = $input->param('format') || 'ISO2709';
61
my $marc_modification_template = $input->param('marc_modification_template_id');
61
my $marc_modification_template = $input->param('marc_modification_template_id');
62
my $existing_batch_id          = $input->param('existing_batch_id');
62
my $existing_batch_id          = $input->param('existing_batch_id');
63
my $control_number_handling    = $input->param('control_number_handling');
64
my $timestamp_update           = $input->param('timestamp_update');
63
65
64
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
66
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65
    {
67
    {
Lines 140-155 if ($completedJobID) { Link Here
140
    $dbh = C4::Context->dbh({new => 1});
142
    $dbh = C4::Context->dbh({new => 1});
141
    $dbh->{AutoCommit} = 0;
143
    $dbh->{AutoCommit} = 0;
142
    # FIXME branch code
144
    # FIXME branch code
143
    my ( $batch_id, $num_valid, $num_items, @import_errors ) =
145
    my $stage_results = BatchStageMarcRecords( {
144
      BatchStageMarcRecords(
146
        record_type => $record_type,
145
        $record_type,    $encoding,
147
        encoding => $encoding,
146
        $marcrecords,    $filename,
148
        marc_records => $marcrecord,
147
        $marc_modification_template,
149
        file_name => $filename,
148
        $comments,       '',
150
        to_marc_plugin => $to_marc_plugin,
149
        $parse_items,    0,
151
        marc_modification_template => $marc_modification_template,
150
        50, staging_progress_callback( $job, $dbh ),
152
        comments => $comments,
151
        $existing_batch_id
153
        parse_items => $parse_items,
152
      );
154
        progress_interval => 50,
155
        progress_callback => staging_progress_callback( $job, $dbh ),
156
        existing_batch_id => $existing_batch_id,
157
        control_number_handling => $control_number_handling,
158
        timestamp_update => $timestamp_update,
159
    } );
153
160
154
    my $num_with_matches = 0;
161
    my $num_with_matches = 0;
155
    my $checked_matches = 0;
162
    my $checked_matches = 0;
Lines 161-172 if ($completedJobID) { Link Here
161
            $checked_matches = 1;
168
            $checked_matches = 1;
162
            $matcher_code = $matcher->code();
169
            $matcher_code = $matcher->code();
163
            $num_with_matches =
170
            $num_with_matches =
164
              BatchFindDuplicates( $batch_id, $matcher, 10, 50,
171
              BatchFindDuplicates( $stage_results->{batch_id}, $matcher, 10, 50,
165
                matching_progress_callback( $job, $dbh ) );
172
                matching_progress_callback( $job, $dbh ) );
166
            SetImportBatchMatcher($batch_id, $matcher_id);
173
            SetImportBatchMatcher( $stage_results->{batch_id}, $matcher_id );
167
            SetImportBatchOverlayAction($batch_id, $overlay_action);
174
            SetImportBatchOverlayAction( $stage_results->{batch_id}, $overlay_action );
168
            SetImportBatchNoMatchAction($batch_id, $nomatch_action);
175
            SetImportBatchNoMatchAction( $stage_results->{batch_id}, $nomatch_action );
169
            SetImportBatchItemAction($batch_id, $item_action);
176
            SetImportBatchItemAction( $stage_results->{batch_id}, $item_action );
170
            $dbh->commit();
177
            $dbh->commit();
171
        } else {
178
        } else {
172
            $matcher_failed = 1;
179
            $matcher_failed = 1;
Lines 176-205 if ($completedJobID) { Link Here
176
    }
183
    }
177
184
178
    my $results = {
185
    my $results = {
179
        staged          => $num_valid,
186
        staged          => $stage_results->{num_valid},
180
        matched         => $num_with_matches,
187
        matched         => $num_with_matches,
181
        num_items       => $num_items,
188
        num_items       => $stage_results->{num_items},
182
        import_errors   => scalar(@import_errors),
189
        import_errors   => scalar( @{ $stage_results->{invalid_records} } ),
183
        total           => $num_valid + scalar(@import_errors),
190
        total           => $stage_results->{num_valid} + scalar( @{ $stage_results->{invalid_records} } ),
184
        checked_matches => $checked_matches,
191
        checked_matches => $checked_matches,
185
        matcher_failed  => $matcher_failed,
192
        matcher_failed  => $matcher_failed,
186
        matcher_code    => $matcher_code,
193
        matcher_code    => $matcher_code,
187
        import_batch_id => $batch_id
194
        import_batch_id => $stage_results->{batch_id},
195
        control_number_handling => $control_number_handling,
196
        num_matched_control_number => $stage_results->{num_matched_control_number},
188
    };
197
    };
189
    if ($runinbackground) {
198
    if ($runinbackground) {
190
        $job->finish($results);
199
        $job->finish($results);
191
        exit 0;
200
        exit 0;
192
    } else {
201
    } else {
193
	    $template->param(staged => $num_valid,
202
	    $template->param( %$results );
194
 	                     matched => $num_with_matches,
195
                         num_items => $num_items,
196
                         import_errors => scalar(@import_errors),
197
                         total => $num_valid + scalar(@import_errors),
198
                         checked_matches => $checked_matches,
199
                         matcher_failed => $matcher_failed,
200
                         matcher_code => $matcher_code,
201
                         import_batch_id => $batch_id
202
                        );
203
    }
203
    }
204
204
205
} else {
205
} else {
206
- 

Return to bug 19266