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

(-)a/Koha/Biblio.pm (+16 lines)
Lines 30-35 use base qw(Koha::Object); Link Here
30
30
31
use Koha::Items;
31
use Koha::Items;
32
use Koha::Biblioitems;
32
use Koha::Biblioitems;
33
use Koha::Biblio::Metadata;
33
use Koha::ArticleRequests;
34
use Koha::ArticleRequests;
34
use Koha::ArticleRequest::Status;
35
use Koha::ArticleRequest::Status;
35
use Koha::IssuingRules;
36
use Koha::IssuingRules;
Lines 61-66 sub store { Link Here
61
    return $self->SUPER::store;
62
    return $self->SUPER::store;
62
}
63
}
63
64
65
=head3 metadata
66
67
my $metadata = $biblio->metadata();
68
69
Returns a Koha::Biblio::Metadata object
70
71
=cut
72
73
sub metadata {
74
    my ( $self ) = @_;
75
76
    my $metadata = $self->_result->metadata;
77
    return Koha::Biblio::Metadata->_new_from_dbic($metadata);
78
}
79
64
=head3 subtitles
80
=head3 subtitles
65
81
66
my @subtitles = $biblio->subtitles();
82
my @subtitles = $biblio->subtitles();
(-)a/Koha/Biblio/Metadata.pm (+53 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Carp;
20
use Carp;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Exceptions::Metadata;
23
24
24
use base qw(Koha::Object);
25
use base qw(Koha::Object);
25
26
Lines 33-38 Koha::Metadata - Koha Metadata Object class Link Here
33
34
34
=cut
35
=cut
35
36
37
=head3 record
38
39
my $record = $metadata->record;
40
41
Returns an object representing the metadata record. The expected record type
42
corresponds to this table:
43
44
    -------------------------------
45
    | format     | object type    |
46
    -------------------------------
47
    | marcxml    | MARC::Record   |
48
    -------------------------------
49
50
=head4 Error handling
51
52
=over
53
54
=item If an unsupported format is found, it throws a I<Koha::Exceptions::Metadata> exception.
55
56
=item If it fails to create the record object, it throws a I<Koha::Exceptions::Metadata::Invalid> exception.
57
58
=back
59
60
=cut
61
62
sub record {
63
64
    my ($self) = @_;
65
66
    my $record;
67
68
    if ( $self->format eq 'marcxml' ) {
69
        $record = eval { MARC::Record::new_from_xml( $self->metadata, 'UTF-8', $self->marcflavour ); };
70
        my $marcxml_error = $@;
71
        chomp $marcxml_error;
72
        unless ($record) {
73
            Koha::Exceptions::Metadata::Invalid->throw(
74
                id     => $self->id,
75
                format => $self->format,
76
                marcflavour => $self->marcflavour,
77
                decoding_error => $marcxml_error,
78
            );
79
        }
80
    }
81
    else {
82
        Koha::Exceptions::Metadata->throw(
83
            'Koha::Biblio::Metadata->record called on unhandled format: ' . $self->format );
84
    }
85
86
    return $record;
87
}
88
36
=head3 type
89
=head3 type
37
90
38
=cut
91
=cut
(-)a/Koha/Exceptions/Metadata.pm (+69 lines)
Line 0 Link Here
1
package Koha::Exceptions::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 Exception::Class (
21
22
    'Koha::Exceptions::Metadata' => {
23
        description => 'Something went wrong!',
24
    },
25
    'Koha::Exceptions::Metadata::Invalid' => {
26
        isa => 'Koha::Exceptions::Metadata',
27
        description => 'Invalid data',
28
        fields => ['id','format','marcflavour', 'decoding_error']
29
    }
30
);
31
32
sub full_message {
33
    my $self = shift;
34
35
    my $msg = $self->message;
36
37
    unless ($msg) {
38
        if ( $self->isa('Koha::Exceptions::Metadata::Invalid') ) {
39
            $msg = sprintf( "Invalid data, cannot decode object (id=%s, format=%s, marcflavour=%s, decoding_error='%s')",
40
                $self->id, $self->format, $self->marcflavour, $self->decoding_error );
41
        }
42
    }
43
44
    return $msg;
45
}
46
47
=head1 NAME
48
49
Koha::Exceptions::Metadata - Base class for metadata exceptions
50
51
=head1 Exceptions
52
53
=head2 Koha::Exceptions::Metadata
54
55
Generic metadata exception
56
57
=head2 Koha::Exceptions::Metadata::Invalid
58
59
The metadata is invalid.
60
61
=head1 Class methods
62
63
=head2 full_message
64
65
Overloaded method for exception stringifying.
66
67
=cut
68
69
1;
(-)a/Koha/Schema/Result/Biblio.pm (-1 / +7 lines)
Lines 351-354 __PACKAGE__->has_many( Link Here
351
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53
351
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53
352
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:bUv00JjY09Hj2Zj4klqyxA
352
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:bUv00JjY09Hj2Zj4klqyxA
353
353
354
__PACKAGE__->has_one(
355
  "metadata",
356
  "Koha::Schema::Result::BiblioMetadata",
357
  { "foreign.biblionumber" => "self.biblionumber" },
358
  { cascade_copy => 0, cascade_delete => 0 },
359
);
360
354
1;
361
1;
355
- 

Return to bug 25009