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

(-)a/Koha/Old/Biblio.pm (+46 lines)
Lines 19-24 use Modern::Perl; Link Here
19
19
20
use base qw(Koha::Object);
20
use base qw(Koha::Object);
21
21
22
use Koha::Old::Biblio::Metadatas;
23
22
=head1 NAME
24
=head1 NAME
23
25
24
Koha::Old::Biblio - Koha Old::Biblio Object class
26
Koha::Old::Biblio - Koha Old::Biblio Object class
Lines 29-34 Koha::Old::Biblio - Koha Old::Biblio Object class Link Here
29
31
30
=cut
32
=cut
31
33
34
=head3 metadata
35
36
my $metadata = $deleted_biblio->metadata();
37
38
Returns a Koha::Biblio::Metadata object
39
40
=cut
41
42
sub metadata {
43
    my ( $self ) = @_;
44
45
    my $metadata = $self->_result->metadata;
46
    return Koha::Old::Biblio::Metadata->_new_from_dbic($metadata);
47
}
48
49
=head3 record
50
51
my $record = $deleted_biblio->record();
52
53
Returns a Marc::Record object
54
55
=cut
56
57
sub record {
58
    my ( $self ) = @_;
59
60
    return $self->metadata->record;
61
}
62
63
=head3 record_schema
64
65
my $schema = $deleted_biblio->record_schema();
66
67
Returns the record schema (MARC21, USMARC or UNIMARC).
68
69
=cut
70
71
sub record_schema {
72
    my ( $self ) = @_;
73
74
    return $self->metadata->schema // C4::Context->preference("marcflavour");
75
}
76
77
32
=head2 Internal methods
78
=head2 Internal methods
33
79
34
=head3 _type
80
=head3 _type
(-)a/Koha/Old/Biblio/Metadata.pm (+141 lines)
Line 0 Link Here
1
package Koha::Old::Biblio::Metadata;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use MARC::File::XML;
21
use Scalar::Util qw( blessed );
22
23
use C4::Biblio qw( GetMarcFromKohaField );
24
use C4::Items qw( GetMarcItem );
25
use Koha::Database;
26
use Koha::Exceptions::Metadata;
27
28
use base qw(Koha::Object);
29
30
=head1 NAME
31
32
Koha::Old::Biblio::Metadata - Koha Deleted Biblio Metadata Object class
33
34
=head1 API
35
36
=head2 Class methods
37
38
=cut
39
40
=head3 record
41
42
my $record = $metadata->record;
43
44
Returns an object representing the metadata record. The expected record type
45
corresponds to this table:
46
47
    -------------------------------
48
    | format     | object type    |
49
    -------------------------------
50
    | marcxml    | MARC::Record   |
51
    -------------------------------
52
53
    $record = $deleted_biblio->metadata->record({
54
        {
55
            embed_items => 0|1
56
            itemnumbers => $itemnumbers,
57
            opac        => $opac
58
        }
59
    );
60
61
    Koha::Old::Biblio::Metadata::record(
62
        {
63
            record       => $record,
64
            embed_items  => 1,
65
            biblionumber => $biblionumber,
66
            itemnumbers  => $itemnumbers,
67
            opac         => $opac
68
        }
69
    );
70
71
Given a MARC::Record object containing a bib record,
72
modify it to include the items attached to it as 9XX
73
per the bib's MARC framework.
74
if $itemnumbers is defined, only specified itemnumbers are embedded.
75
76
If $opac is true, then opac-relevant suppressions are included.
77
78
If opac filtering will be done, patron should be passed to properly
79
override if necessary.
80
81
82
=head4 Error handling
83
84
=over
85
86
=item If an unsupported format is found, it throws a I<Koha::Exceptions::Metadata> exception.
87
88
=item If it fails to create the record object, it throws a I<Koha::Exceptions::Metadata::Invalid> exception.
89
90
=back
91
92
=cut
93
94
sub record {
95
96
    my ($self, $params) = @_;
97
98
    my $record = $params->{record};
99
    my $format = blessed($self) ? $self->format : $params->{format};
100
    $format ||= 'marcxml';
101
102
    if ( !$record && !blessed($self) ) {
103
        Koha::Exceptions::Metadata->throw(
104
            'Koha::Old::Biblio::Metadata->record must be called on an instantiated object or like a class method with a record passed in parameter'
105
        );
106
    }
107
108
    if ( $format eq 'marcxml' ) {
109
        $record ||= eval { MARC::Record::new_from_xml( $self->metadata, 'UTF-8', $self->schema ); };
110
        my $marcxml_error = $@;
111
        chomp $marcxml_error;
112
        unless ($record) {
113
            warn $marcxml_error;
114
            Koha::Exceptions::Metadata::Invalid->throw(
115
                id             => $self->id,
116
                biblionumber   => $self->biblionumber,
117
                format         => $self->format,
118
                schema         => $self->schema,
119
                decoding_error => $marcxml_error,
120
            );
121
        }
122
    }
123
    else {
124
        Koha::Exceptions::Metadata->throw(
125
            'Koha::Old::Biblio::Metadata->record called on unhandled format: ' . $format );
126
    }
127
128
    return $record;
129
}
130
131
=head2 Internal methods
132
133
=head3 _type
134
135
=cut
136
137
sub _type {
138
    return 'DeletedbiblioMetadata';
139
}
140
141
1;
(-)a/Koha/Old/Biblio/Metadatas.pm (+49 lines)
Line 0 Link Here
1
package Koha::Old::Biblio::Metadatas;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
21
use Koha::Database;
22
23
use Koha::Old::Biblio::Metadata;
24
25
use base qw(Koha::Objects);
26
27
=head1 NAME
28
29
Koha::Old::Biblio::Metadatas - Koha Deleted Metadata Object set class
30
31
=head1 API
32
33
=head2 Class Methods
34
35
=cut
36
37
=head3 type
38
39
=cut
40
41
sub _type {
42
    return 'DeletedbiblioMetadata';
43
}
44
45
sub object_class {
46
    return 'Koha::Old::Biblio::Metadata';
47
}
48
49
1;
(-)a/Koha/Old/Biblios.pm (-1 / +1 lines)
Lines 17-23 package Koha::Old::Biblios; Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use base qw(Koha::Objects);
20
use base qw(Koha::Objects Koha::Objects::Record::Collections);
21
21
22
use Koha::Old::Biblio;
22
use Koha::Old::Biblio;
23
23
(-)a/Koha/Schema/Result/Deletedbiblio.pm (-1 / +14 lines)
Lines 214-219 __PACKAGE__->has_many( Link Here
214
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
214
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
215
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:KwlqhkWWX6CYWb3l2fCcSg
215
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:KwlqhkWWX6CYWb3l2fCcSg
216
216
217
__PACKAGE__->has_many(
218
  "biblioitem",
219
  "Koha::Schema::Result::Deletedbiblioitem",
220
  { "foreign.biblionumber" => "self.biblionumber" },
221
  { cascade_copy => 0, cascade_delete => 0 },
222
);
223
224
__PACKAGE__->has_one(
225
  "metadata",
226
  "Koha::Schema::Result::DeletedbiblioMetadata",
227
  { "foreign.biblionumber" => "self.biblionumber" },
228
  { cascade_copy => 0, cascade_delete => 0 },
229
);
230
217
sub koha_objects_class {
231
sub koha_objects_class {
218
    'Koha::Old::Biblios';
232
    'Koha::Old::Biblios';
219
}
233
}
220
- 

Return to bug 33960