Bug 32336: (QA follow-up) Use $metadata->schema
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 23 Mar 2023 23:16:37 +0000 (20:16 -0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 31 Mar 2023 09:56:48 +0000 (11:56 +0200)
When we worked on Koha::Biblio::Metadata, we agreed
biblio_metadata.schema would be the sourceof truth when it comes to the
record schema.

This patch acknowledges that, while retaining the fallback to the
syspref.

To test:
1. Apply this patch
2. Run:
   $ prove t/db_dependent/api/v1/biblios.t
=> SUCCESS: Tests pass, behavior is unchanged.
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/REST/V1/Biblios.pm

index 530df09..baf9d94 100644 (file)
@@ -67,14 +67,15 @@ sub get {
             );
         }
         else {
-            my $record = $biblio->metadata->record;
-            my $marcflavour = C4::Context->preference("marcflavour");
+            my $metadata = $biblio->metadata;
+            my $record   = $metadata->record;
+            my $schema   = $metadata->schema // C4::Context->preference("marcflavour");
 
             $c->respond_to(
                 marcxml => {
                     status => 200,
                     format => 'marcxml',
-                    text   => $record->as_xml_record($marcflavour),
+                    text   => $record->as_xml_record($schema),
                 },
                 mij => {
                     status => 200,
@@ -169,7 +170,8 @@ sub get_public {
 
     return try {
 
-        my $record = $biblio->metadata->record;
+        my $metadata = $biblio->metadata;
+        my $record   = $metadata->record;
 
         my $opachiddenitems_rules = C4::Context->yaml_preference('OpacHiddenItems');
         my $patron = $c->stash('koha.user');
@@ -189,7 +191,7 @@ sub get_public {
             }
         }
 
-        my $marcflavour = C4::Context->preference("marcflavour");
+        my $schema = $metadata->schema // C4::Context->preference("marcflavour");
 
         my $record_processor = Koha::RecordProcessor->new({
             filters => 'ViewPolicy',
@@ -205,7 +207,7 @@ sub get_public {
             marcxml => {
                 status => 200,
                 format => 'marcxml',
-                text   => $record->as_xml_record($marcflavour),
+                text   => $record->as_xml_record($schema),
             },
             mij => {
                 status => 200,