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

(-)a/Koha/SimpleMARC.pm (-6 / +7 lines)
Lines 582-587 sub _copy_move_field { Link Here
582
        @from_fields = map { $_ <= @from_fields ? $from_fields[ $_ - 1 ] : () } @$field_numbers;
582
        @from_fields = map { $_ <= @from_fields ? $from_fields[ $_ - 1 ] : () } @$field_numbers;
583
    }
583
    }
584
584
585
    if ( $action eq 'replace' ) {
586
        my @to_fields = $record->field( $toFieldName );
587
        for my $to_field ( @to_fields ) {
588
            $record->delete_field( $to_field );
589
        }
590
    }
591
585
    for my $from_field ( @from_fields ) {
592
    for my $from_field ( @from_fields ) {
586
        my $new_field = $from_field->clone;
593
        my $new_field = $from_field->clone;
587
        $new_field->{_tag} = $toFieldName; # Should be replaced by set_tag, introduced by MARC::Field 2.0.4
594
        $new_field->{_tag} = $toFieldName; # Should be replaced by set_tag, introduced by MARC::Field 2.0.4
Lines 595-606 sub _copy_move_field { Link Here
595
        if ( $action eq 'move' ) {
602
        if ( $action eq 'move' ) {
596
            $record->delete_field( $from_field )
603
            $record->delete_field( $from_field )
597
        }
604
        }
598
        elsif ( $action eq 'replace' ) {
599
            my @to_fields = $record->field( $toFieldName );
600
            if ( @to_fields ) {
601
                $record->delete_field( $to_fields[0] );
602
            }
603
        }
604
        $record->insert_grouped_field( $new_field );
605
        $record->insert_grouped_field( $new_field );
605
    }
606
    }
606
}
607
}
(-)a/t/SimpleMARC.t (-17 / +16 lines)
Lines 384-390 subtest 'copy_field' => sub { Link Here
384
          read_field( { record => $record, field => '651', subfield => 'a' } );
384
          read_field( { record => $record, field => '651', subfield => 'a' } );
385
        is_deeply(
385
        is_deeply(
386
            \@fields_651a,
386
            \@fields_651a,
387
            [ 'Computer programming.', 'Computer algorithms.' ],
387
            [ 'Computer algorithms.' , 'Computer programming.' ],
388
            'Copy multivalued field'
388
            'Copy multivalued field'
389
        );
389
        );
390
        delete_field( { record => $record, field => '651' } );
390
        delete_field( { record => $record, field => '651' } );
Lines 445-451 subtest 'copy_field' => sub { Link Here
445
          read_field( { record => $record, field => '651', subfield => 'a' } );
445
          read_field( { record => $record, field => '651', subfield => 'a' } );
446
        is_deeply(
446
        is_deeply(
447
            \@fields_651a,
447
            \@fields_651a,
448
            [ 'The art of programming.', 'The art of algorithms.' ],
448
            [ 'The art of algorithms.', 'The art of programming.' ],
449
            'Copy field using regex'
449
            'Copy field using regex'
450
        );
450
        );
451
        delete_field( { record => $record, field => '651' } );
451
        delete_field( { record => $record, field => '651' } );
Lines 464-470 subtest 'copy_field' => sub { Link Here
464
          read_field( { record => $record, field => '651', subfield => 'a' } );
464
          read_field( { record => $record, field => '651', subfield => 'a' } );
465
        is_deeply(
465
        is_deeply(
466
            \@fields_651a,
466
            \@fields_651a,
467
            [ 'The mistake of programming.', 'The mistake of algorithms.' ],
467
            [ 'The mistake of algorithms.', 'The mistake of programming.' ],
468
            'Copy fields using regex on existing fields'
468
            'Copy fields using regex on existing fields'
469
        );
469
        );
470
        delete_field( { record => $record, field => '651' } );
470
        delete_field( { record => $record, field => '651' } );
Lines 483-489 subtest 'copy_field' => sub { Link Here
483
          read_field( { record => $record, field => '651', subfield => 'a' } );
483
          read_field( { record => $record, field => '651', subfield => 'a' } );
484
        is_deeply(
484
        is_deeply(
485
            \@fields_651a,
485
            \@fields_651a,
486
            [ 'The art of programming.', 'The art of algorithms.', ],
486
            [ 'The art of algorithms.', 'The art of programming.', ],
487
            'Copy all fields using regex'
487
            'Copy all fields using regex'
488
        );
488
        );
489
        delete_field( { record => $record, field => '651' } );
489
        delete_field( { record => $record, field => '651' } );
Lines 531-537 subtest 'copy_field' => sub { Link Here
531
          read_field( { record => $record, field => '652', subfield => 'a' } );
531
          read_field( { record => $record, field => '652', subfield => 'a' } );
532
        is_deeply(
532
        is_deeply(
533
            \@fields_652a,
533
            \@fields_652a,
534
            [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
534
            [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ],
535
            'Copy field using regex'
535
            'Copy field using regex'
536
        );
536
        );
537
537
Lines 549-555 subtest 'copy_field' => sub { Link Here
549
          read_field( { record => $record, field => '653', subfield => 'a' } );
549
          read_field( { record => $record, field => '653', subfield => 'a' } );
550
        is_deeply(
550
        is_deeply(
551
            \@fields_653a,
551
            \@fields_653a,
552
            [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
552
            [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ],
553
            'Copy field using regex'
553
            'Copy field using regex'
554
        );
554
        );
555
555
Lines 567-573 subtest 'copy_field' => sub { Link Here
567
          read_field( { record => $record, field => '654', subfield => 'a' } );
567
          read_field( { record => $record, field => '654', subfield => 'a' } );
568
        is_deeply(
568
        is_deeply(
569
            \@fields_654a,
569
            \@fields_654a,
570
            [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
570
            [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ],
571
            'Copy field using regex'
571
            'Copy field using regex'
572
        );
572
        );
573
573
Lines 585-591 subtest 'copy_field' => sub { Link Here
585
          read_field( { record => $record, field => '655', subfield => 'a' } );
585
          read_field( { record => $record, field => '655', subfield => 'a' } );
586
        is_deeply(
586
        is_deeply(
587
            \@fields_655a,
587
            \@fields_655a,
588
            [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
588
            [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ],
589
            'Copy field using regex'
589
            'Copy field using regex'
590
        );
590
        );
591
591
Lines 958-964 subtest 'copy_and_replace_field' => sub { Link Here
958
          read_field( { record => $record, field => '651', subfield => 'a' } );
958
          read_field( { record => $record, field => '651', subfield => 'a' } );
959
        is_deeply(
959
        is_deeply(
960
            \@fields_651a,
960
            \@fields_651a,
961
            [ 'Computer programming.', 'Computer algorithms.' ],
961
            [ 'Computer algorithms.', 'Computer programming.' ],
962
            'Copy and replace multivalued field (same as copy)'
962
            'Copy and replace multivalued field (same as copy)'
963
        );
963
        );
964
        delete_field( { record => $record, field => '651' } );
964
        delete_field( { record => $record, field => '651' } );
Lines 1018-1024 subtest 'copy_and_replace_field' => sub { Link Here
1018
          read_field( { record => $record, field => '651', subfield => 'a' } );
1018
          read_field( { record => $record, field => '651', subfield => 'a' } );
1019
        is_deeply(
1019
        is_deeply(
1020
            \@fields_651a,
1020
            \@fields_651a,
1021
            [ 'The art of programming.', 'The art of algorithms.' ],
1021
            [ 'The art of algorithms.', 'The art of programming.' ],
1022
            'Copy and replace field using regex (same as copy)'
1022
            'Copy and replace field using regex (same as copy)'
1023
        );
1023
        );
1024
        delete_field( { record => $record, field => '651' } );
1024
        delete_field( { record => $record, field => '651' } );
Lines 1037-1043 subtest 'copy_and_replace_field' => sub { Link Here
1037
          read_field( { record => $record, field => '651', subfield => 'a' } );
1037
          read_field( { record => $record, field => '651', subfield => 'a' } );
1038
        is_deeply(
1038
        is_deeply(
1039
            \@fields_651a,
1039
            \@fields_651a,
1040
            [ 'The mistake of programming.', 'The mistake of algorithms.' ],
1040
            [ 'The mistake of algorithms.', 'The mistake of programming.' ],
1041
            'Copy and replace fields using regex on existing fields (same as copy)'
1041
            'Copy and replace fields using regex on existing fields (same as copy)'
1042
        );
1042
        );
1043
        delete_field( { record => $record, field => '651' } );
1043
        delete_field( { record => $record, field => '651' } );
Lines 1056-1062 subtest 'copy_and_replace_field' => sub { Link Here
1056
          read_field( { record => $record, field => '651', subfield => 'a' } );
1056
          read_field( { record => $record, field => '651', subfield => 'a' } );
1057
        is_deeply(
1057
        is_deeply(
1058
            \@fields_651a,
1058
            \@fields_651a,
1059
            [ 'The art of programming.', 'The art of algorithms.', ],
1059
            [ 'The art of algorithms.', 'The art of programming.', ],
1060
            'Copy and replace all fields using regex (same as copy)'
1060
            'Copy and replace all fields using regex (same as copy)'
1061
        );
1061
        );
1062
        delete_field( { record => $record, field => '651' } );
1062
        delete_field( { record => $record, field => '651' } );
Lines 1104-1110 subtest 'copy_and_replace_field' => sub { Link Here
1104
          read_field( { record => $record, field => '652', subfield => 'a' } );
1104
          read_field( { record => $record, field => '652', subfield => 'a' } );
1105
        is_deeply(
1105
        is_deeply(
1106
            \@fields_652a,
1106
            \@fields_652a,
1107
            [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
1107
            [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ],
1108
            'Copy and replace field using regex (same as copy)'
1108
            'Copy and replace field using regex (same as copy)'
1109
        );
1109
        );
1110
1110
Lines 1122-1128 subtest 'copy_and_replace_field' => sub { Link Here
1122
          read_field( { record => $record, field => '653', subfield => 'a' } );
1122
          read_field( { record => $record, field => '653', subfield => 'a' } );
1123
        is_deeply(
1123
        is_deeply(
1124
            \@fields_653a,
1124
            \@fields_653a,
1125
            [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
1125
            [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ],
1126
            'Copy and replace field using regex (same as copy)'
1126
            'Copy and replace field using regex (same as copy)'
1127
        );
1127
        );
1128
1128
Lines 1140-1146 subtest 'copy_and_replace_field' => sub { Link Here
1140
          read_field( { record => $record, field => '654', subfield => 'a' } );
1140
          read_field( { record => $record, field => '654', subfield => 'a' } );
1141
        is_deeply(
1141
        is_deeply(
1142
            \@fields_654a,
1142
            \@fields_654a,
1143
            [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
1143
            [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ],
1144
            'Copy and replace field using regex (same as copy)'
1144
            'Copy and replace field using regex (same as copy)'
1145
        );
1145
        );
1146
1146
Lines 1158-1164 subtest 'copy_and_replace_field' => sub { Link Here
1158
          read_field( { record => $record, field => '655', subfield => 'a' } );
1158
          read_field( { record => $record, field => '655', subfield => 'a' } );
1159
        is_deeply(
1159
        is_deeply(
1160
            \@fields_655a,
1160
            \@fields_655a,
1161
            [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
1161
            [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ],
1162
            'Copy and replace field using regex (same as copy)'
1162
            'Copy and replace field using regex (same as copy)'
1163
        );
1163
        );
1164
1164
1165
- 

Return to bug 24480