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

(-)a/Koha/Authority/MergeRequest.pm (-2 / +34 lines)
Lines 22-28 use Modern::Perl; Link Here
22
use parent qw(Koha::Object);
22
use parent qw(Koha::Object);
23
23
24
use Koha::Authorities;
24
use Koha::Authorities;
25
use Koha::Authority::MergeRequests;
26
use Koha::Authority::Types;
25
use Koha::Authority::Types;
27
26
28
=head1 NAME
27
=head1 NAME
Lines 67-73 sub new { Link Here
67
    if( $self->authid && $oldrecord ) {
66
    if( $self->authid && $oldrecord ) {
68
        my $auth = Koha::Authorities->find( $self->authid );
67
        my $auth = Koha::Authorities->find( $self->authid );
69
        my $type = $auth ? Koha::Authority::Types->find($auth->authtypecode) : undef;
68
        my $type = $auth ? Koha::Authority::Types->find($auth->authtypecode) : undef;
70
        $self->reportxml( Koha::Authority::MergeRequests->reporting_tag_xml({ record => $oldrecord, tag => $type->auth_tag_to_report })) if $type;
69
        $self->reportxml( $self->reporting_tag_xml({ record => $oldrecord, tag => $type->auth_tag_to_report })) if $type;
71
    }
70
    }
72
    return $self;
71
    return $self;
73
}
72
}
Lines 88-93 sub oldmarc { Link Here
88
87
89
=head2 CLASS METHODS
88
=head2 CLASS METHODS
90
89
90
=head3 reporting_tag_xml
91
92
    my $xml = Koha::Authority::MergeRequest->reporting_tag_xml({
93
        record => $record, tag => $tag,
94
    });
95
96
=cut
97
98
sub reporting_tag_xml {
99
    my ( $class, $params ) = @_;
100
    return if !$params->{record} || !$params->{tag};
101
102
    my $newrecord = MARC::Record->new;
103
    $newrecord->encoding( 'UTF-8' );
104
    my $reportfield = $params->{record}->field( $params->{tag} );
105
    return if !$reportfield;
106
107
    # For UNIMARC we need a field 100 that includes the encoding
108
    # at position 13 and 14
109
    if( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
110
        $newrecord->append_fields(
111
            MARC::Field->new( '100', '', '', a => ' 'x13 . '50' ),
112
        );
113
    }
114
115
    $newrecord->append_fields( $reportfield );
116
    return $newrecord->as_xml(
117
        C4::Context->preference('marcflavour') eq 'UNIMARC' ?
118
        'UNIMARCAUTH' :
119
        'MARC21'
120
    );
121
}
122
91
=head3 _type
123
=head3 _type
92
124
93
Returns name of corresponding DBIC resultset
125
Returns name of corresponding DBIC resultset
(-)a/Koha/Authority/MergeRequests.pm (-27 lines)
Lines 42-76 Description Link Here
42
42
43
=head1 METHODS
43
=head1 METHODS
44
44
45
=head2 INSTANCE METHODS
46
47
=head2 CLASS METHODS
45
=head2 CLASS METHODS
48
46
49
=head3 reporting_tag_xml
50
51
    my $xml = Koha::Authority::MergeRequests->reporting_tag_xml({
52
        record => $record, tag => $tag,
53
    });
54
55
=cut
56
57
sub reporting_tag_xml {
58
    my ( $class, $params ) = @_;
59
    return if !$params->{record} || !$params->{tag};
60
61
    my $newrecord = MARC::Record->new;
62
    $newrecord->encoding( 'UTF-8' );
63
    my $reportfield = $params->{record}->field( $params->{tag} );
64
    return if !$reportfield;
65
66
    $newrecord->append_fields( $reportfield );
67
    return $newrecord->as_xml(
68
        C4::Context->preference('marcflavour') eq 'UNIMARC' ?
69
        'UNIMARCAUTH' :
70
        'MARC21'
71
    );
72
}
73
74
=head3 cron_cleanup
47
=head3 cron_cleanup
75
48
76
    Koha::Authority::MergeRequests->cron_cleanup({
49
    Koha::Authority::MergeRequests->cron_cleanup({
(-)a/t/db_dependent/Koha/Authorities.t (-13 / +15 lines)
Lines 32-38 use C4::Context; Link Here
32
use Koha::Authority;
32
use Koha::Authority;
33
use Koha::Authorities;
33
use Koha::Authorities;
34
use Koha::Authority::MergeRequest;
34
use Koha::Authority::MergeRequest;
35
use Koha::Authority::MergeRequests;
36
use Koha::Authority::Type;
35
use Koha::Authority::Type;
37
use Koha::Authority::Types;
36
use Koha::Authority::Types;
38
use Koha::Database;
37
use Koha::Database;
Lines 91-125 subtest 'New merge request, method oldmarc' => sub { Link Here
91
    });
90
    });
92
    like( $req->reportxml, qr/b_findme/, 'Reportxml initialized' );
91
    like( $req->reportxml, qr/b_findme/, 'Reportxml initialized' );
93
92
94
    # Check if oldmarc is a MARC::Record and has one field
93
    # Check if oldmarc is a MARC::Record and has one or two fields
95
    is( ref( $req->oldmarc ), 'MARC::Record', 'Check oldmarc method' );
94
    is( ref( $req->oldmarc ), 'MARC::Record', 'Check oldmarc method' );
96
    is( scalar $req->oldmarc->fields, 1, 'Contains one field' );
95
    if( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
96
        is( scalar $req->oldmarc->fields, 2, 'UNIMARC contains two fields' );
97
    } else {
98
        is( scalar $req->oldmarc->fields, 1, 'MARC21 contains one field' );
99
    }
97
};
100
};
98
101
99
subtest 'Testing reporting_tag_xml in MergeRequests' => sub {
102
subtest 'Testing reporting_tag_xml in MergeRequest' => sub {
100
    plan tests => 2;
103
    plan tests => 2;
101
104
102
    my $record = MARC::Record->new;
105
    my $record = MARC::Record->new;
103
    $record->append_fields(
106
    $record->append_fields(
104
        MARC::Field->new( '024', '', '', a => 'aaa' ),
107
        MARC::Field->new( '024', '', '', a => 'aaa' ),
105
        MARC::Field->new( '100', '', '', a => 'Best author' ),
108
        MARC::Field->new( '110', '', '', a => 'Best author' ),
106
        MARC::Field->new( '234', '', '', a => 'Just a field' ),
109
        MARC::Field->new( '234', '', '', a => 'Just a field' ),
107
    );
110
    );
108
    my $xml = Koha::Authority::MergeRequests->reporting_tag_xml({
111
    my $xml = Koha::Authority::MergeRequest->reporting_tag_xml({
109
        record => $record, tag => '110',
112
        record => $record, tag => '100',
110
    });
113
    });
111
    is( $xml, undef, 'Expected no result for wrong tag' );
114
    is( $xml, undef, 'Expected no result for wrong tag' );
112
    $xml = Koha::Authority::MergeRequests->reporting_tag_xml({
115
    $xml = Koha::Authority::MergeRequest->reporting_tag_xml({
113
        record => $record, tag => '100',
116
        record => $record, tag => '110',
114
    });
117
    });
115
    my $newrecord = MARC::Record->new_from_xml(
118
    my $newrecord = MARC::Record->new_from_xml(
116
        $xml, 'UTF-8',
119
        $xml, 'UTF-8',
117
        C4::Context->preference('marcflavour') eq 'UNIMARC' ?
120
        C4::Context->preference('marcflavour') eq 'UNIMARC' ?
118
        'UNIMARCAUTH' :
121
        'UNIMARCAUTH' :
119
        'MARC21',
122
        'MARC21',
120
    ); # MARC format does not actually matter here
123
    );
121
    cmp_deeply( $record->field('100')->subfields,
124
    cmp_deeply( $record->field('110')->subfields,
122
        $newrecord->field('100')->subfields,
125
        $newrecord->field('110')->subfields,
123
        'Compare reporting tag in both records',
126
        'Compare reporting tag in both records',
124
    );
127
    );
125
};
128
};
126
- 

Return to bug 9988