Bug 33270: Attempt to recover from invalid metadata exception
authorNick Clemens <nick@bywatersolutions.com>
Thu, 22 Jun 2023 11:22:18 +0000 (11:22 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 19 Jul 2023 08:27:43 +0000 (09:27 +0100)
commit2e23ed06b7d6abbb3b27f0b0728bba10532d6c63
treefde5a414faeecccf44237f25368b8a2bb495f321
parent9544bd25a2b3c4811abb941b67a5684952a78da6
Bug 33270: Attempt to recover from invalid metadata exception

This patch uses the new record_strip_nonxml routine to attempt to display
the record when it contains invalid characters

Rather than silently strippg these, we warn in the logs, then add an 'about'
container to the response. It is displayed nicely in the web view or sent as "INVALID_METADATA" in
the xml response

The 'error' codes for OAI seem to be at the request level, and the offered codes don't have a match
for a bad record. Adding the about when we can recover seems the most generous response

To test:
Test plan, assumes using KTD default data - otherwise you need to find and import a record with encoding issues:
 1 - Enable OAI-PMH system preference
 2 - Browse to:
    http://localhost:8080/cgi-bin/koha/oai.pl?verb=ListRecords&resumptionToken=marcxml/350////0/0/352
 3 - 500 error:
    Invalid data, cannot decode metadata object (biblio_metadata.id=368, biblionumber=369, format=marcxml, schema=MARC21, decoding_error=':8: parser error : PCDATA invalid Char value 31...
 4 - Apply patch, restart all
 5 - Reload the page
 6 - It loads!
 7 - Click 'Metadata' for record 369 - it succeeds!
 8 - Check the logs - confirm you see a warning of the record problem
 9 - Confirm 369 has an about section
10 - Check the individul 'GetRecord' response as well
    http://localhost:8080/cgi-bin/koha/oai.pl?verb=GetRecord&metadataPrefix=oai_dc&identifier=KOHA-OAI-TEST:369

Signed-off-by: Sam Lau <samalau@gmail.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit c71468537b4fa589e91e7fd5823ddd4f54379e21)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Koha/OAI/Server/GetRecord.pm
Koha/OAI/Server/ListBase.pm
Koha/OAI/Server/Repository.pm
koha-tmpl/opac-tmpl/xslt/OAI.xslt