|
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 |
} else { |
| 123 |
Koha::Exceptions::Metadata->throw( |
| 124 |
'Koha::Old::Biblio::Metadata->record called on unhandled format: ' . $format ); |
| 125 |
} |
| 126 |
|
| 127 |
return $record; |
| 128 |
} |
| 129 |
|
| 130 |
=head2 Internal methods |
| 131 |
|
| 132 |
=head3 _type |
| 133 |
|
| 134 |
=cut |
| 135 |
|
| 136 |
sub _type { |
| 137 |
return 'DeletedbiblioMetadata'; |
| 138 |
} |
| 139 |
|
| 140 |
1; |