Bug 32735: (follow-up) Make Koha::Objects::Record::Collections->print_collection work with Authorities and Biblios

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Agustin Moyano 2023-05-03 15:31:05 -03:00 committed by Tomas Cohen Arazi
parent 67cafa719b
commit 020f710e31
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
5 changed files with 66 additions and 8 deletions

View File

@ -148,11 +148,24 @@ Return the MARC::Record for this authority
sub record {
my ( $self ) = @_;
my $flavour =
C4::Context->preference('marcflavour') eq 'UNIMARC'
my $flavour = $self->record_schema;
return MARC::Record->new_from_xml( $self->marcxml, 'UTF-8', $flavour );
}
=head3 record_schema
my $schema = $biblio->record_schema();
Returns the record schema (MARC21 or UNIMARCAUTH).
=cut
sub record_schema {
my ( $self ) = @_;
return C4::Context->preference('marcflavour') eq 'UNIMARC'
? 'UNIMARCAUTH'
: 'MARC21';
return MARC::Record->new_from_xml( $self->marcxml, 'UTF-8', $flavour );
}
=head2 Class Methods

View File

@ -105,6 +105,20 @@ sub record {
return $self->metadata->record;
}
=head3 record_schema
my $schema = $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");
}
=head3 orders
my $orders = $biblio->orders();

View File

@ -84,10 +84,13 @@ sub print_collection {
$end = MARC::File::XML::footer();
}
while ( my $element = $self->next ) {
my $metadata = $element->metadata;
MARC::File::XML->default_record_format( $metadata->schema // C4::Context->preference("marcflavour") )
my $schema = C4::Context->preference("marcflavour");
if ($element->can('record_schema')) {
$schema = $element->record_schema;
}
MARC::File::XML->default_record_format( $schema )
if $format eq 'marcxml';
push @parts, $serializers{$format}->( $metadata->record );
push @parts, $serializers{$format}->( $element->record );
}
return
( defined $start ? $start : '' )

View File

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 16;
use Test::More tests => 17;
use Test::MockModule;
use Test::Warn;
use List::MoreUtils qw( uniq );
@ -877,6 +877,20 @@ subtest 'record test' => sub {
$biblio->metadata->record->as_formatted );
};
subtest 'record_schema test' => sub {
plan tests => 1;
my $marc_record = MARC::Record->new;
$marc_record->append_fields( create_isbn_field( '0590353403', 'MARC21' ) );
my ($biblionumber) = C4::Biblio::AddBiblio( $marc_record, '' );
my $biblio = Koha::Biblios->find($biblionumber);
is( $biblio->record_schema,
$biblio->metadata->schema );
};
# Cleanup

View File

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 9;
use Test::More tests => 10;
use MARC::Field;
use MARC::File::XML;
use MARC::Record;
@ -321,4 +321,18 @@ subtest 'record tests' => sub {
};
subtest 'record_schema tests' => sub {
plan tests => 2;
my $authority = $builder->build_object({class => 'Koha::Authorities'});
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
is($authority->record_schema, 'MARC21');
t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' );
is($authority->record_schema, 'UNIMARCAUTH');
};
$schema->storage->txn_rollback;