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

(-)a/Koha/Authority.pm (-6 / +29 lines)
Lines 19-31 package Koha::Authority; Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Carp;
23
24
use Koha::Database;
25
use C4::Context;
26
use MARC::Record;
27
28
use base qw(Koha::Object);
22
use base qw(Koha::Object);
23
use Koha::Authority::MergeRequest;
24
use Koha::Authority::Types;
29
25
30
=head1 NAME
26
=head1 NAME
31
27
Lines 33-38 Koha::Authority - Koha Authority Object class Link Here
33
29
34
=head1 API
30
=head1 API
35
31
32
=head2 Instance Methods
33
34
=cut
35
36
=head3 add_merge_request
37
38
    $self->add_merge_request({ [ authid_to => $to ], record_from => $marc });
39
40
=cut
41
42
sub add_merge_request {
43
    my ( $self, $params ) = @_;
44
    if( $self->in_storage ) {
45
        my $type = Koha::Authority::Types->find( $self->authtypecode );
46
        my $tag = $type ? $type->auth_tag_to_report : undef;
47
        my $xml = Koha::Authority::MergeRequests->reporting_tag_xml({
48
            record => $params->{record_from},
49
            tag    => $tag,
50
        });
51
        my $req = Koha::Authority::MergeRequest->new({
52
            authid_from => $self->authid,
53
            authid_to   => $params->{authid_to} // $self->authid,
54
            reportxml   => $xml,
55
        })->store;
56
    }
57
}
58
36
=head2 Class Methods
59
=head2 Class Methods
37
60
38
=cut
61
=cut
(-)a/Koha/Authority/MergeRequest.pm (+60 lines)
Line 0 Link Here
1
package Koha::Authority::MergeRequest;
2
3
# Copyright Rijksmuseum 2017
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use parent qw(Koha::Object);
23
24
=head1 NAME
25
26
Koha::Authority::MergeRequest - Koha::Object class for single need_merge_authorities record
27
28
=head1 SYNOPSIS
29
30
use Koha::Authority::MergeRequest;
31
32
=head1 DESCRIPTION
33
34
Description
35
36
=head1 METHODS
37
38
=head2 INSTANCE METHODS
39
40
=head2 CLASS METHODS
41
42
=head3 _type
43
44
Returns name of corresponding DBIC resultset
45
46
=cut
47
48
sub _type {
49
    return 'NeedMergeAuthority';
50
}
51
52
=head1 AUTHOR
53
54
Marcel de Rooy (Rijksmuseum)
55
56
Koha Development Team
57
58
=cut
59
60
1;
(-)a/Koha/Authority/MergeRequests.pm (+100 lines)
Line 0 Link Here
1
package Koha::Authority::MergeRequests;
2
3
# Copyright Rijksmuseum 2017
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
use MARC::File::XML;
22
use MARC::Record;
23
24
use C4::Context;
25
use Koha::Authority::MergeRequest;
26
27
use parent qw(Koha::Objects);
28
29
=head1 NAME
30
31
Koha::Authority::MergeRequests - Koha::Objects class for need_merge_authorities
32
33
=head1 SYNOPSIS
34
35
use Koha::Authority::MergeRequests;
36
37
=head1 DESCRIPTION
38
39
Description
40
41
=head1 METHODS
42
43
=head2 INSTANCE METHODS
44
45
=head2 CLASS METHODS
46
47
=head3 reporting_tag_xml
48
49
    my $xml = Koha::Authority::MergeRequests->reporting_tag_xml({
50
        record => $record, tag => $tag,
51
    });
52
53
=cut
54
55
sub reporting_tag_xml {
56
    my ( $class, $params ) = @_;
57
    return if !$params->{record} || !$params->{tag};
58
59
    my $newrecord = MARC::Record->new;
60
    $newrecord->encoding( 'UTF-8' );
61
    my $reportfield = $params->{record}->field( $params->{tag} );
62
    return if !$reportfield;
63
64
    $newrecord->append_fields( $reportfield );
65
    return $newrecord->as_xml(
66
        C4::Context->preference('marcflavour') eq 'UNIMARC' ?
67
        'UNIMARCAUTH' :
68
        'MARC21'
69
    );
70
}
71
72
=head3 _type
73
74
Returns name of corresponding DBIC resultset
75
76
=cut
77
78
sub _type {
79
    return 'NeedMergeAuthority';
80
}
81
82
=head3 object_class
83
84
Returns name of corresponding Koha object class
85
86
=cut
87
88
sub object_class {
89
    return 'Koha::Authority::MergeRequest';
90
}
91
92
=head1 AUTHOR
93
94
Marcel de Rooy (Rijksmuseum)
95
96
Koha Development Team
97
98
=cut
99
100
1;
(-)a/t/db_dependent/Koha/Authorities.t (-3 / +49 lines)
Lines 19-28 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 3;
22
use Test::More tests => 5;
23
use MARC::Field;
24
use MARC::File::XML;
25
use MARC::Record;
26
use Test::Deep;
23
27
24
use Koha::Authority;
28
use Koha::Authority;
25
use Koha::Authorities;
29
use Koha::Authorities;
30
use Koha::Authority::MergeRequests;
26
use Koha::Authority::Type;
31
use Koha::Authority::Type;
27
use Koha::Authority::Types;
32
use Koha::Authority::Types;
28
use Koha::Database;
33
use Koha::Database;
Lines 51-55 is( Koha::Authorities->search->count, $nb_of_authorities + 2, 'The 2 au Link Here
51
$new_authority_1->delete;
56
$new_authority_1->delete;
52
is( Koha::Authorities->search->count, $nb_of_authorities + 1, 'Delete should have deleted the authority' );
57
is( Koha::Authorities->search->count, $nb_of_authorities + 1, 'Delete should have deleted the authority' );
53
58
59
subtest 'Add merge request' => sub {
60
    plan tests => 2;
61
62
    my $count = Koha::Authority::MergeRequests->count;
63
    $new_authority_2->add_merge_request;
64
    is( Koha::Authority::MergeRequests->count,
65
        $count+1,
66
        'Merge request added' );
67
    my $new_authority_3 = Koha::Authority->new;
68
    $new_authority_3->add_merge_request;
69
    is( Koha::Authority::MergeRequests->count,
70
        $count+1,
71
        'No additional merge request added (not in storage)' );
72
};
73
74
subtest 'Testing reporting_tag_xml in MergeRequests' => sub {
75
    plan tests => 2;
76
77
    my $record = MARC::Record->new;
78
    $record->append_fields(
79
        MARC::Field->new( '024', '', '', a => 'aaa' ),
80
        MARC::Field->new( '100', '', '', a => 'Best author' ),
81
        MARC::Field->new( '234', '', '', a => 'Just a field' ),
82
    );
83
    my $xml = Koha::Authority::MergeRequests->reporting_tag_xml({
84
        record => $record, tag => '110',
85
    });
86
    is( $xml, undef, 'Expected no result for wrong tag' );
87
    $xml = Koha::Authority::MergeRequests->reporting_tag_xml({
88
        record => $record, tag => '100',
89
    });
90
    my $newrecord = MARC::Record->new_from_xml(
91
        $xml, 'UTF-8',
92
        C4::Context->preference('marcflavour') eq 'UNIMARC' ?
93
        'UNIMARCAUTH' :
94
        'MARC21',
95
    ); # MARC format does not actually matter here
96
    cmp_deeply( $record->field('100')->subfields,
97
        $newrecord->field('100')->subfields,
98
        'Compare reporting tag in both records',
99
    );
100
};
101
54
$schema->storage->txn_rollback;
102
$schema->storage->txn_rollback;
55
1;
56
- 

Return to bug 9988