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

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

Return to bug 19266