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

(-)a/Koha/Util/Misc.pm (-1 / +144 lines)
Line 0 Link Here
0
- 
1
package Koha::Util::Misc;
2
3
# Copyright 2024 Koha Development Team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use Digest::MD5     qw( md5_hex );
22
use Sereal::Encoder qw( encode_sereal );
23
use Koha::Biblios;
24
use Koha::MetadataRecord;
25
use C4::Biblio qw( GetFrameworkCode GetMarcStructure GetMarcFromKohaField );
26
27
=head1 NAME
28
29
Koha::Util::Misc - utility class with miscellaneous routines
30
31
=head1 FUNCTIONS
32
33
=head2 digest
34
35
my $digest = Koha::Util::Misc::digest( $data_structure )
36
37
Calculates a md5_hex digest of the given argument (any Perl data structure).
38
39
=head3 Returns:
40
41
=over 4
42
43
=item C<$digest>
44
45
calculated digest
46
47
=back
48
49
=cut
50
51
sub digest {
52
    my $data = shift;
53
    return md5_hex(
54
        encode_sereal(
55
            ( ref $data eq '' ) ? \$data : $data,
56
            { sort_keys => 1 }
57
        )
58
    );
59
}
60
61
=head2 prepare_mid_air_collision_merge
62
63
my ( $records, $framework_database ) = prepare_mid_air_collision_merge( $data )
64
65
Prepares data for merging two versions of a bibliographic record in case of
66
concurrent modification made.
67
68
=head3 Parameters:
69
70
=over 4
71
72
=item C<$data>
73
74
in $data you pass biblionumber of the modified bibliographic record and
75
its modified version in MARC::Record object
76
77
=back
78
79
=head3 Returns:
80
81
=over 4
82
83
=item C<$records>
84
85
a data structure suitable for 'records' parameter for cataloguing/merge.tt
86
template
87
88
89
=item C<$framework_database>
90
91
a template code of the database version of the record needed for
92
cataloguing/merge.tt template ('framework' parameter)
93
94
=back
95
96
=cut
97
98
sub prepare_mid_air_collision_merge {
99
    my $data            = shift;
100
    my $biblionumber    = $data->{biblionumber};
101
    my $modified_record = $data->{modified_record};
102
103
    my $framework_database = GetFrameworkCode($biblionumber);
104
105
    # Getting MARC Structure
106
    my $tagslib = GetMarcStructure( 1, $framework_database );
107
108
    my $marcflavour = lc( C4::Context->preference('marcflavour') );
109
110
    # Creating a loop for display
111
    my @records;
112
113
    for my $i ( 0 .. 1 ) {
114
        my $biblio;
115
        my $marcrecord;
116
        my $template_record;
117
        if ( $i == 0 ) {    #database version
118
            $biblio                       = Koha::Biblios->find($biblionumber);
119
            $marcrecord                   = $biblio->record;
120
            $template_record->{reference} = 1;
121
            $template_record->{recordid}  = $biblionumber;
122
        } else {            #modified version
123
            $marcrecord = $modified_record;
124
            $template_record->{recordid} = -1;                 # NOTE for the modified version
125
        }
126
127
        my $recordObj = Koha::MetadataRecord->new( { 'record' => $marcrecord, schema => $marcflavour } );
128
        $template_record->{record}  = $marcrecord;
129
        $template_record->{display} = $recordObj->createMergeHash($tagslib);
130
        push @records, $template_record;
131
    }
132
    return ( \@records, $framework_database );
133
}
134
135
1;
136
__END__
137
138
=head1 AUTHOR
139
140
Koha Development Team <https://koha-community.org/>
141
142
Janusz Kaczmarek <januszop@gmail.com>
143
144
=cut

Return to bug 31109