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

(-)a/Koha/SimpleMARC.pm (-6 / +7 lines)
Lines 575-580 sub _copy_move_field { Link Here
575
        @from_fields = map { $_ <= @from_fields ? $from_fields[ $_ - 1 ] : () } @$field_numbers;
575
        @from_fields = map { $_ <= @from_fields ? $from_fields[ $_ - 1 ] : () } @$field_numbers;
576
    }
576
    }
577
577
578
    if ( $action eq 'replace' ) {
579
        my @to_fields = $record->field( $toFieldName );
580
        for my $to_field ( @to_fields ) {
581
            $record->delete_field( $to_field );
582
        }
583
    }
584
578
    for my $from_field ( @from_fields ) {
585
    for my $from_field ( @from_fields ) {
579
        my $new_field = $from_field->clone;
586
        my $new_field = $from_field->clone;
580
        $new_field->{_tag} = $toFieldName; # Should be replaced by set_tag, introduced by MARC::Field 2.0.4
587
        $new_field->{_tag} = $toFieldName; # Should be replaced by set_tag, introduced by MARC::Field 2.0.4
Lines 588-599 sub _copy_move_field { Link Here
588
        if ( $action eq 'move' ) {
595
        if ( $action eq 'move' ) {
589
            $record->delete_field( $from_field )
596
            $record->delete_field( $from_field )
590
        }
597
        }
591
        elsif ( $action eq 'replace' ) {
592
            my @to_fields = $record->field( $toFieldName );
593
            if ( @to_fields ) {
594
                $record->delete_field( $to_fields[0] );
595
            }
596
        }
597
        $record->insert_grouped_field( $new_field );
598
        $record->insert_grouped_field( $new_field );
598
    }
599
    }
599
}
600
}
(-)a/t/SimpleMARC.t (-16 / +16 lines)
Lines 386-392 subtest 'copy_field' => sub { Link Here
386
          read_field( { record => $record, field => '651', subfield => 'a' } );
386
          read_field( { record => $record, field => '651', subfield => 'a' } );
387
        is_deeply(
387
        is_deeply(
388
            \@fields_651a,
388
            \@fields_651a,
389
            [ 'Computer programming.', 'Computer algorithms.' ],
389
            [ 'Computer algorithms.' , 'Computer programming.' ],
390
            'Copy multivalued field'
390
            'Copy multivalued field'
391
        );
391
        );
392
        delete_field( { record => $record, field => '651' } );
392
        delete_field( { record => $record, field => '651' } );
Lines 447-453 subtest 'copy_field' => sub { Link Here
447
          read_field( { record => $record, field => '651', subfield => 'a' } );
447
          read_field( { record => $record, field => '651', subfield => 'a' } );
448
        is_deeply(
448
        is_deeply(
449
            \@fields_651a,
449
            \@fields_651a,
450
            [ 'The art of programming.', 'The art of algorithms.' ],
450
            [ 'The art of algorithms.', 'The art of programming.' ],
451
            'Copy field using regex'
451
            'Copy field using regex'
452
        );
452
        );
453
        delete_field( { record => $record, field => '651' } );
453
        delete_field( { record => $record, field => '651' } );
Lines 466-472 subtest 'copy_field' => sub { Link Here
466
          read_field( { record => $record, field => '651', subfield => 'a' } );
466
          read_field( { record => $record, field => '651', subfield => 'a' } );
467
        is_deeply(
467
        is_deeply(
468
            \@fields_651a,
468
            \@fields_651a,
469
            [ 'The mistake of programming.', 'The mistake of algorithms.' ],
469
            [ 'The mistake of algorithms.', 'The mistake of programming.' ],
470
            'Copy fields using regex on existing fields'
470
            'Copy fields using regex on existing fields'
471
        );
471
        );
472
        delete_field( { record => $record, field => '651' } );
472
        delete_field( { record => $record, field => '651' } );
Lines 485-491 subtest 'copy_field' => sub { Link Here
485
          read_field( { record => $record, field => '651', subfield => 'a' } );
485
          read_field( { record => $record, field => '651', subfield => 'a' } );
486
        is_deeply(
486
        is_deeply(
487
            \@fields_651a,
487
            \@fields_651a,
488
            [ 'The art of programming.', 'The art of algorithms.', ],
488
            [ 'The art of algorithms.', 'The art of programming.', ],
489
            'Copy all fields using regex'
489
            'Copy all fields using regex'
490
        );
490
        );
491
        delete_field( { record => $record, field => '651' } );
491
        delete_field( { record => $record, field => '651' } );
Lines 533-539 subtest 'copy_field' => sub { Link Here
533
          read_field( { record => $record, field => '652', subfield => 'a' } );
533
          read_field( { record => $record, field => '652', subfield => 'a' } );
534
        is_deeply(
534
        is_deeply(
535
            \@fields_652a,
535
            \@fields_652a,
536
            [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
536
            [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ],
537
            'Copy field using regex'
537
            'Copy field using regex'
538
        );
538
        );
539
539
Lines 551-557 subtest 'copy_field' => sub { Link Here
551
          read_field( { record => $record, field => '653', subfield => 'a' } );
551
          read_field( { record => $record, field => '653', subfield => 'a' } );
552
        is_deeply(
552
        is_deeply(
553
            \@fields_653a,
553
            \@fields_653a,
554
            [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
554
            [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ],
555
            'Copy field using regex'
555
            'Copy field using regex'
556
        );
556
        );
557
557
Lines 569-575 subtest 'copy_field' => sub { Link Here
569
          read_field( { record => $record, field => '654', subfield => 'a' } );
569
          read_field( { record => $record, field => '654', subfield => 'a' } );
570
        is_deeply(
570
        is_deeply(
571
            \@fields_654a,
571
            \@fields_654a,
572
            [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
572
            [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ],
573
            'Copy field using regex'
573
            'Copy field using regex'
574
        );
574
        );
575
575
Lines 587-593 subtest 'copy_field' => sub { Link Here
587
          read_field( { record => $record, field => '655', subfield => 'a' } );
587
          read_field( { record => $record, field => '655', subfield => 'a' } );
588
        is_deeply(
588
        is_deeply(
589
            \@fields_655a,
589
            \@fields_655a,
590
            [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
590
            [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ],
591
            'Copy field using regex'
591
            'Copy field using regex'
592
        );
592
        );
593
593
Lines 981-987 subtest 'copy_and_replace_field' => sub { Link Here
981
          read_field( { record => $record, field => '651', subfield => 'a' } );
981
          read_field( { record => $record, field => '651', subfield => 'a' } );
982
        is_deeply(
982
        is_deeply(
983
            \@fields_651a,
983
            \@fields_651a,
984
            [ 'Computer programming.', 'Computer algorithms.' ],
984
            [ 'Computer algorithms.', 'Computer programming.' ],
985
            'Copy and replace multivalued field (same as copy)'
985
            'Copy and replace multivalued field (same as copy)'
986
        );
986
        );
987
        delete_field( { record => $record, field => '651' } );
987
        delete_field( { record => $record, field => '651' } );
Lines 1041-1047 subtest 'copy_and_replace_field' => sub { Link Here
1041
          read_field( { record => $record, field => '651', subfield => 'a' } );
1041
          read_field( { record => $record, field => '651', subfield => 'a' } );
1042
        is_deeply(
1042
        is_deeply(
1043
            \@fields_651a,
1043
            \@fields_651a,
1044
            [ 'The art of programming.', 'The art of algorithms.' ],
1044
            [ 'The art of algorithms.', 'The art of programming.' ],
1045
            'Copy and replace field using regex (same as copy)'
1045
            'Copy and replace field using regex (same as copy)'
1046
        );
1046
        );
1047
        delete_field( { record => $record, field => '651' } );
1047
        delete_field( { record => $record, field => '651' } );
Lines 1060-1066 subtest 'copy_and_replace_field' => sub { Link Here
1060
          read_field( { record => $record, field => '651', subfield => 'a' } );
1060
          read_field( { record => $record, field => '651', subfield => 'a' } );
1061
        is_deeply(
1061
        is_deeply(
1062
            \@fields_651a,
1062
            \@fields_651a,
1063
            [ 'The mistake of programming.', 'The mistake of algorithms.' ],
1063
            [ 'The mistake of algorithms.', 'The mistake of programming.' ],
1064
            'Copy and replace fields using regex on existing fields (same as copy)'
1064
            'Copy and replace fields using regex on existing fields (same as copy)'
1065
        );
1065
        );
1066
        delete_field( { record => $record, field => '651' } );
1066
        delete_field( { record => $record, field => '651' } );
Lines 1079-1085 subtest 'copy_and_replace_field' => sub { Link Here
1079
          read_field( { record => $record, field => '651', subfield => 'a' } );
1079
          read_field( { record => $record, field => '651', subfield => 'a' } );
1080
        is_deeply(
1080
        is_deeply(
1081
            \@fields_651a,
1081
            \@fields_651a,
1082
            [ 'The art of programming.', 'The art of algorithms.', ],
1082
            [ 'The art of algorithms.', 'The art of programming.', ],
1083
            'Copy and replace all fields using regex (same as copy)'
1083
            'Copy and replace all fields using regex (same as copy)'
1084
        );
1084
        );
1085
        delete_field( { record => $record, field => '651' } );
1085
        delete_field( { record => $record, field => '651' } );
Lines 1127-1133 subtest 'copy_and_replace_field' => sub { Link Here
1127
          read_field( { record => $record, field => '652', subfield => 'a' } );
1127
          read_field( { record => $record, field => '652', subfield => 'a' } );
1128
        is_deeply(
1128
        is_deeply(
1129
            \@fields_652a,
1129
            \@fields_652a,
1130
            [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
1130
            [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ],
1131
            'Copy and replace field using regex (same as copy)'
1131
            'Copy and replace field using regex (same as copy)'
1132
        );
1132
        );
1133
1133
Lines 1145-1151 subtest 'copy_and_replace_field' => sub { Link Here
1145
          read_field( { record => $record, field => '653', subfield => 'a' } );
1145
          read_field( { record => $record, field => '653', subfield => 'a' } );
1146
        is_deeply(
1146
        is_deeply(
1147
            \@fields_653a,
1147
            \@fields_653a,
1148
            [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
1148
            [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ],
1149
            'Copy and replace field using regex (same as copy)'
1149
            'Copy and replace field using regex (same as copy)'
1150
        );
1150
        );
1151
1151
Lines 1163-1169 subtest 'copy_and_replace_field' => sub { Link Here
1163
          read_field( { record => $record, field => '654', subfield => 'a' } );
1163
          read_field( { record => $record, field => '654', subfield => 'a' } );
1164
        is_deeply(
1164
        is_deeply(
1165
            \@fields_654a,
1165
            \@fields_654a,
1166
            [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
1166
            [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ],
1167
            'Copy and replace field using regex (same as copy)'
1167
            'Copy and replace field using regex (same as copy)'
1168
        );
1168
        );
1169
1169
Lines 1181-1187 subtest 'copy_and_replace_field' => sub { Link Here
1181
          read_field( { record => $record, field => '655', subfield => 'a' } );
1181
          read_field( { record => $record, field => '655', subfield => 'a' } );
1182
        is_deeply(
1182
        is_deeply(
1183
            \@fields_655a,
1183
            \@fields_655a,
1184
            [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
1184
            [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ],
1185
            'Copy and replace field using regex (same as copy)'
1185
            'Copy and replace field using regex (same as copy)'
1186
        );
1186
        );
1187
1187
(-)a/t/db_dependent/MarcModificationTemplates.t (-33 / +32 lines)
Lines 507-512 sub expected_record_1 { Link Here
507
    my $record = MARC::Record->new;
507
    my $record = MARC::Record->new;
508
    $record->leader('03174nam a2200445 a 4500');
508
    $record->leader('03174nam a2200445 a 4500');
509
    my @fields = (
509
    my @fields = (
510
        MARC::Field->new(
511
           '007', 'vxcdq',
512
        ),
510
        MARC::Field->new(
513
        MARC::Field->new(
511
            100, '1', ' ',
514
            100, '1', ' ',
512
            a => 'Knuth, Donald Ervin',
515
            a => 'Knuth, Donald Ervin',
Lines 517-552 sub expected_record_1 { Link Here
517
            a => 'The art of computer programming',
520
            a => 'The art of computer programming',
518
            c => 'Donald E. Knuth.',
521
            c => 'Donald E. Knuth.',
519
        ),
522
        ),
520
        MARC::Field->new(
521
            650, ' ', '0',
522
            9 => '462',
523
        ),
524
        MARC::Field->new(
525
            952, ' ', ' ',
526
            p => '3010023917_updated',
527
            y => 'BK',
528
            c => 'GEN',
529
            e => '2001-06-25',
530
        ),
531
        MARC::Field->new(
523
        MARC::Field->new(
532
            246, '', ' ',
524
            246, '', ' ',
533
            a => 'The art of computer programming',
525
            a => 'The art of computer programming',
534
        ),
526
        ),
527
        MARC::Field->new(
528
            650, ' ', '0',
529
            9 => '462',
530
        ),
535
        MARC::Field->new(
531
        MARC::Field->new(
536
            651, ' ', '0',
532
            651, ' ', '0',
537
            a => 'Computer algorithms.',
533
            a => 'Computer algorithms.',
538
            9 => '499',
534
            9 => '499',
539
        ),
535
        ),
540
        MARC::Field->new(
536
        MARC::Field->new(
541
            999, ' ', ' ',
537
            952, ' ', ' ',
542
            a => 'existent - updated.',
538
            p => '3010023917_updated',
539
            y => 'BK',
540
            c => 'GEN',
541
            e => '2001-06-25',
543
        ),
542
        ),
544
        MARC::Field->new(
543
        MARC::Field->new(
545
            999, ' ', ' ',
544
            999, ' ', ' ',
546
            a => 'additional existent.',
545
            a => 'additional existent.',
547
        ),
546
        ),
548
        MARC::Field->new(
547
        MARC::Field->new(
549
           '007', 'vxcdq',
548
            999, ' ', ' ',
549
            a => 'existent - updated.',
550
        ),
550
        ),
551
    );
551
    );
552
    $record->append_fields(@fields);
552
    $record->append_fields(@fields);
Lines 577-594 sub expected_record_2 { Link Here
577
            a => 'Computer programming.',
577
            a => 'Computer programming.',
578
            9 => '499',
578
            9 => '499',
579
        ),
579
        ),
580
        MARC::Field->new(
581
            651, ' ', '0',
582
            a => 'Computer programming.',
583
            9 => '462',
584
        ),
580
        MARC::Field->new(
585
        MARC::Field->new(
581
            952, ' ', ' ',
586
            952, ' ', ' ',
582
            p => '3010023917',
587
            p => '3010023917',
583
            y => 'BK',
588
            y => 'BK',
584
            c => 'GEN',
589
            c => 'GEN',
585
            d => '2001-06-25',
590
            d => '2001-06-25',
586
        ),
591
        )
587
        MARC::Field->new(
588
            651, ' ', '0',
589
            a => 'Computer programming.',
590
            9 => '462',
591
        ),
592
    );
592
    );
593
    $record->append_fields(@fields);
593
    $record->append_fields(@fields);
594
    return $record;
594
    return $record;
Lines 720-725 sub expected_record_0 { Link Here
720
            a => 'The art of computer programming',
720
            a => 'The art of computer programming',
721
            c => 'Donald E. Knuth.',
721
            c => 'Donald E. Knuth.',
722
        ),
722
        ),
723
        MARC::Field->new(
724
            600, ' ', ' ',
725
            0 => 'TestUpdated',
726
        ),
727
        MARC::Field->new(
728
            600, ' ', ' ',
729
            0 => 'TestUpdated',
730
        ),
723
        MARC::Field->new(
731
        MARC::Field->new(
724
            650, ' ', '0',
732
            650, ' ', '0',
725
            0 => '42',
733
            0 => '42',
Lines 731-748 sub expected_record_0 { Link Here
731
            0 => 'Zeroth',
739
            0 => 'Zeroth',
732
            a => 'Appolo',
740
            a => 'Appolo',
733
        ),
741
        ),
734
        MARC::Field->new(
735
            600, ' ', ' ',
736
            0 => 'TestUpdated',
737
        ),
738
        MARC::Field->new(
739
            600, ' ', ' ',
740
            0 => 'TestUpdated',
741
        ),
742
        MARC::Field->new(
743
            700, ' ', ' ',
744
            0 => '12345',
745
        ),
746
        MARC::Field->new(
742
        MARC::Field->new(
747
            690, ' ', ' ',
743
            690, ' ', ' ',
748
            0 => 'Zeroth',
744
            0 => 'Zeroth',
Lines 753-758 sub expected_record_0 { Link Here
753
            0 => 'Zeroth',
749
            0 => 'Zeroth',
754
            a => 'Appolo',
750
            a => 'Appolo',
755
        ),
751
        ),
752
        MARC::Field->new(
753
            700, ' ', ' ',
754
            0 => '12345',
755
        ),
756
    );
756
    );
757
    $record->append_fields(@fields);
757
    $record->append_fields(@fields);
758
    return $record;
758
    return $record;
759
- 

Return to bug 24480