From 2001da13b961b30ef7fa57095613e31f542b3020 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 8 Jun 2023 13:57:35 +0000 Subject: [PATCH] Bug 33960: Add objects and update schema Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize --- Koha/Old/Biblio.pm | 46 +++++++++ Koha/Old/Biblio/Metadata.pm | 140 ++++++++++++++++++++++++++++ Koha/Old/Biblio/Metadatas.pm | 52 +++++++++++ Koha/Old/Biblios.pm | 2 +- Koha/Schema/Result/Deletedbiblio.pm | 15 +++ 5 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 Koha/Old/Biblio/Metadata.pm create mode 100644 Koha/Old/Biblio/Metadatas.pm diff --git a/Koha/Old/Biblio.pm b/Koha/Old/Biblio.pm index 7b9d90f5de3..5c0e416619c 100644 --- a/Koha/Old/Biblio.pm +++ b/Koha/Old/Biblio.pm @@ -19,6 +19,8 @@ use Modern::Perl; use base qw(Koha::Object); +use Koha::Old::Biblio::Metadatas; + =head1 NAME Koha::Old::Biblio - Koha Old::Biblio Object class @@ -29,6 +31,50 @@ Koha::Old::Biblio - Koha Old::Biblio Object class =cut +=head3 metadata + +my $metadata = $deleted_biblio->metadata(); + +Returns a Koha::Biblio::Metadata object + +=cut + +sub metadata { + my ( $self ) = @_; + + my $metadata = $self->_result->metadata; + return Koha::Old::Biblio::Metadata->_new_from_dbic($metadata); +} + +=head3 record + +my $record = $deleted_biblio->record(); + +Returns a Marc::Record object + +=cut + +sub record { + my ( $self ) = @_; + + return $self->metadata->record; +} + +=head3 record_schema + +my $schema = $deleted_biblio->record_schema(); + +Returns the record schema (MARC21, USMARC or UNIMARC). + +=cut + +sub record_schema { + my ( $self ) = @_; + + return $self->metadata->schema // C4::Context->preference("marcflavour"); +} + + =head2 Internal methods =head3 _type diff --git a/Koha/Old/Biblio/Metadata.pm b/Koha/Old/Biblio/Metadata.pm new file mode 100644 index 00000000000..281e963750b --- /dev/null +++ b/Koha/Old/Biblio/Metadata.pm @@ -0,0 +1,140 @@ +package Koha::Old::Biblio::Metadata; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use MARC::File::XML; +use Scalar::Util qw( blessed ); + +use C4::Biblio qw( GetMarcFromKohaField ); +use C4::Items qw( GetMarcItem ); +use Koha::Database; +use Koha::Exceptions::Metadata; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Old::Biblio::Metadata - Koha Deleted Biblio Metadata Object class + +=head1 API + +=head2 Class methods + +=cut + +=head3 record + +my $record = $metadata->record; + +Returns an object representing the metadata record. The expected record type +corresponds to this table: + + ------------------------------- + | format | object type | + ------------------------------- + | marcxml | MARC::Record | + ------------------------------- + + $record = $deleted_biblio->metadata->record({ + { + embed_items => 0|1 + itemnumbers => $itemnumbers, + opac => $opac + } + ); + + Koha::Old::Biblio::Metadata::record( + { + record => $record, + embed_items => 1, + biblionumber => $biblionumber, + itemnumbers => $itemnumbers, + opac => $opac + } + ); + +Given a MARC::Record object containing a bib record, +modify it to include the items attached to it as 9XX +per the bib's MARC framework. +if $itemnumbers is defined, only specified itemnumbers are embedded. + +If $opac is true, then opac-relevant suppressions are included. + +If opac filtering will be done, patron should be passed to properly +override if necessary. + + +=head4 Error handling + +=over + +=item If an unsupported format is found, it throws a I exception. + +=item If it fails to create the record object, it throws a I exception. + +=back + +=cut + +sub record { + + my ( $self, $params ) = @_; + + my $record = $params->{record}; + my $format = blessed($self) ? $self->format : $params->{format}; + $format ||= 'marcxml'; + + if ( !$record && !blessed($self) ) { + Koha::Exceptions::Metadata->throw( + 'Koha::Old::Biblio::Metadata->record must be called on an instantiated object or like a class method with a record passed in parameter' + ); + } + + if ( $format eq 'marcxml' ) { + $record ||= eval { MARC::Record::new_from_xml( $self->metadata, 'UTF-8', $self->schema ); }; + my $marcxml_error = $@; + chomp $marcxml_error; + unless ($record) { + warn $marcxml_error; + Koha::Exceptions::Metadata::Invalid->throw( + id => $self->id, + biblionumber => $self->biblionumber, + format => $self->format, + schema => $self->schema, + decoding_error => $marcxml_error, + ); + } + } else { + Koha::Exceptions::Metadata->throw( + 'Koha::Old::Biblio::Metadata->record called on unhandled format: ' . $format ); + } + + return $record; +} + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'DeletedbiblioMetadata'; +} + +1; diff --git a/Koha/Old/Biblio/Metadatas.pm b/Koha/Old/Biblio/Metadatas.pm new file mode 100644 index 00000000000..8f43c5b4265 --- /dev/null +++ b/Koha/Old/Biblio/Metadatas.pm @@ -0,0 +1,52 @@ +package Koha::Old::Biblio::Metadatas; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Koha::Database; + +use Koha::Old::Biblio::Metadata; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Old::Biblio::Metadatas - Koha Deleted Metadata Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 _type + +=cut + +sub _type { + return 'DeletedbiblioMetadata'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Old::Biblio::Metadata'; +} + +1; diff --git a/Koha/Old/Biblios.pm b/Koha/Old/Biblios.pm index 205a48e962c..990d067a180 100644 --- a/Koha/Old/Biblios.pm +++ b/Koha/Old/Biblios.pm @@ -17,7 +17,7 @@ package Koha::Old::Biblios; use Modern::Perl; -use base qw(Koha::Objects); +use base qw(Koha::Objects Koha::Objects::Record::Collections); use Koha::Old::Biblio; diff --git a/Koha/Schema/Result/Deletedbiblio.pm b/Koha/Schema/Result/Deletedbiblio.pm index e3f48a3acd2..33b8c92ead7 100644 --- a/Koha/Schema/Result/Deletedbiblio.pm +++ b/Koha/Schema/Result/Deletedbiblio.pm @@ -214,9 +214,24 @@ __PACKAGE__->has_many( # Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:KwlqhkWWX6CYWb3l2fCcSg +__PACKAGE__->has_many( + "biblioitem", + "Koha::Schema::Result::Deletedbiblioitem", + { "foreign.biblionumber" => "self.biblionumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +__PACKAGE__->has_one( + "metadata", + "Koha::Schema::Result::DeletedbiblioMetadata", + { "foreign.biblionumber" => "self.biblionumber" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub koha_objects_class { 'Koha::Old::Biblios'; } + sub koha_object_class { 'Koha::Old::Biblio'; } -- 2.44.0