Bug 37252

Summary: Saving an authority record as MADS (XML) fails
Product: Koha Reporter: Phil Ringnalda <phil>
Component: MARC Authority data supportAssignee: Phil Ringnalda <phil>
Status: Needs documenting --- QA Contact: Pedro Amorim <pedro.amorim>
Severity: normal    
Priority: P5 - low CC: david, dcook, fridolin.somers, lucas, pedro.amorim
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
This fixes the saving of authority records in MADS format in the staff interface (Authorities > search results > authority details > Save > MADS (XML)). Before this fix, the downloaded records had a zero file size and were empty.
Version(s) released in:
24.11.00,24.05.06
Circulation function:
Bug Depends on: 37235, 23290    
Bug Blocks:    
Attachments: Bug 37252: Use our local copy of MARC21slimUtils.xsl in MARC21slim2MADS.xsl
Bug 37252: Use our local copy of MARC21slimUtils.xsl in MARC21slim2MADS.xsl
Bug 37252: Use our local copy of MARC21slimUtils.xsl in MARC21slim2MADS.xsl

Description Phil Ringnalda 2024-07-03 21:18:01 UTC
Until it has been pushed, you need the patch for bug 37235 to see this, since otherwise you're stopped by a CSRF-related error first.

Steps to reproduce:
1. View details for an authority record, e.g. /cgi-bin/koha/authorities/detail.pl?authid=620
2. tail -f /var/log/koha/kohadev/plack-intranet-error.log
3. In the authority details page, Save - MADS (XML)

Expected result is a downloaded file of more than zero bytes, Actual result is a zero byte file and the following logged errors:

[WARN] XSLT::Base: Unknown IO errorI/O warning : failed to load external entity "http://www.loc.gov/marcxml/xslt/MARC21slimUtils.xsl"
compilation error: file /kohadevbox/koha/koha-tmpl/intranet-tmpl/prog/en/xslt/MARC21slim2MADS.xsl element include
xsl:include : unable to load http://www.loc.gov/marcxml/xslt/MARC21slimUtils.xsl
 at /kohadevbox/koha/Koha/XSLT/Base.pm line 346.
[WARN] Use of uninitialized value $marc in print at /kohadevbox/koha/authorities/export.pl line 47.

If you eventually notice that the URL, which seems to work fine in a browser, is actually sending a 301 to http://www.loc.gov/standards/marcxml/xslt/MARC21slimUtils.xsl and you update the include to that, it still fails.

As bug 29556 pointed out, the MADS XSLT is alone in including MARC21slimUtils.xsl from LoC, all our others include our local copy. If we want to have a canary in the coal mine that tells us when that fails, we should make it something which will actually produce a visible failure, not this spectacularly obscure authority format download.
Comment 1 Phil Ringnalda 2024-07-03 21:28:10 UTC
Created attachment 168479 [details] [review]
Bug 37252: Use our local copy of MARC21slimUtils.xsl in MARC21slim2MADS.xsl

Our local copy of the Library of Congress stylesheet MARC21slim2MADS.xsl is
our only one which includes MARC21slimUtils.xsl directly from the Library of
Congress rather than including our local copy. That makes it a fragile canary
for whatever reason that it currently isn't loading, but because it's not
exactly the most popular menu choice in all of Koha, it's far from being one
that anyone will notice.

We should instead include our local copy, make the bug 29556 change to
MARC21slim2MADS.xsl, and if someone wants to notice when including xsl from
LoC fails, they should write a test for it rather than depend on someone
noticing that saving authority records as MADS fails.

Test plan:
1. Without the patch, Authorities - search for Smith - click the linked
   name of any result to show authorities/detail.pl
2. Save - MADS (XML)
3. Check your downloaded file, see that it is zero bytes
4. Apply patch, restart_all
5. Repeat step 2, but this time find that your downloaded file is more
   than zero bytes.
Comment 2 David Nind 2024-07-04 00:58:27 UTC
Created attachment 168485 [details] [review]
Bug 37252: Use our local copy of MARC21slimUtils.xsl in MARC21slim2MADS.xsl

Our local copy of the Library of Congress stylesheet MARC21slim2MADS.xsl is
our only one which includes MARC21slimUtils.xsl directly from the Library of
Congress rather than including our local copy. That makes it a fragile canary
for whatever reason that it currently isn't loading, but because it's not
exactly the most popular menu choice in all of Koha, it's far from being one
that anyone will notice.

We should instead include our local copy, make the bug 29556 change to
MARC21slim2MADS.xsl, and if someone wants to notice when including xsl from
LoC fails, they should write a test for it rather than depend on someone
noticing that saving authority records as MADS fails.

Test plan:
1. Without the patch, Authorities - search for Smith - click the linked
   name of any result to show authorities/detail.pl
2. Save - MADS (XML)
3. Check your downloaded file, see that it is zero bytes
4. Apply patch, restart_all
5. Repeat step 2, but this time find that your downloaded file is more
   than zero bytes.

Signed-off-by: David Nind <david@davidnind.com>
Comment 3 David Nind 2024-07-04 01:01:09 UTC
Testing notes (using KTD):

1. Before working through the test plan, apply bug 37235. Otherwise, you will get a 500 error for steps 2 and 3 of the test plan.
2. When applying the patch, say n (for no) to not apply the dependent patch.
Comment 4 Pedro Amorim 2024-07-05 15:06:22 UTC
Created attachment 168555 [details] [review]
Bug 37252: Use our local copy of MARC21slimUtils.xsl in MARC21slim2MADS.xsl

Our local copy of the Library of Congress stylesheet MARC21slim2MADS.xsl is
our only one which includes MARC21slimUtils.xsl directly from the Library of
Congress rather than including our local copy. That makes it a fragile canary
for whatever reason that it currently isn't loading, but because it's not
exactly the most popular menu choice in all of Koha, it's far from being one
that anyone will notice.

We should instead include our local copy, make the bug 29556 change to
MARC21slim2MADS.xsl, and if someone wants to notice when including xsl from
LoC fails, they should write a test for it rather than depend on someone
noticing that saving authority records as MADS fails.

Test plan:
1. Without the patch, Authorities - search for Smith - click the linked
   name of any result to show authorities/detail.pl
2. Save - MADS (XML)
3. Check your downloaded file, see that it is zero bytes
4. Apply patch, restart_all
5. Repeat step 2, but this time find that your downloaded file is more
   than zero bytes.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Comment 5 David Cook 2024-07-07 23:59:10 UTC
I think the reason why the include of an external stylesheet would've failed would be due to the security added by bug 23290.
Comment 6 Katrin Fischer 2024-07-08 15:50:47 UTC
Pushed for 24.11!

Well done everyone, thank you!
Comment 7 Lucas Gass (lukeg) 2024-11-18 17:53:58 UTC
Backported to 24.05.x for upcoming 24.05.06
Comment 8 Fridolin Somers 2024-12-06 07:54:14 UTC
Depends on Bug 37235 not in 23.11.x