https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43777

--- Comment #5 from Martin Renvoize (ashimema) 
<[email protected]> ---
Created attachment 207773
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=207773&action=edit
Bug 43777: Repair recoverable MARCXML faults in Koha::Biblio::Metadata->record

Bug 35104 repairs non-XML characters and empty datafields when saving
MARCXML. Metadata that was already corrupt before that, or that bypassed
store(), still made ->record throw, so each caller had to catch
Koha::Exceptions::Metadata::Invalid and re-implement its own fallback.

->record now saves the repair by calling store(), which repairs the
metadata, writes it back, records each fault as an error row and reports
it through object_messages. The repaired MARC::Record is returned, and
later reads find clean metadata, so the repair runs once per record
while the errors stay available (and dismissable). If the write fails
the repaired record is still returned. Unrecoverable metadata still
throws Invalid. Note that the write bumps biblio_metadata.timestamp.

record_strip_nonxml is now redundant (and only covered one of the two
faults), so it is removed and its callers use ->record.

Koha::Biblio->metadata previously built a new wrapper on every call, so
messages reported by ->record were lost before they could be read. It now
returns the same wrapper for as long as it wraps the same row.

Test plan:
Setup
1. Turn on the CataloguingLog system preference (Administration >
   System preferences > Logs), and set OAI-PMH to "Enable".
2. Pick three catalogue records with titles you can recognise, B with no
   items. Note their biblionumbers (A, B and C).
3. Damage them the way old data can be damaged, using the database
   (ktd --name "$KTD_INSTANCE" --dbshell):
     -- a stray control character in the title of A, B and C
     UPDATE biblio_metadata
        SET metadata = REPLACE(metadata, '<subfield code="a">',
                               CONCAT('<subfield code="a">', CHAR(31)))
      WHERE biblionumber IN (A, B, C) AND format = 'marcxml';
     -- an empty field on C as well
     UPDATE biblio_metadata
        SET metadata = REPLACE(metadata, '</record>',
                '<datafield tag="500" ind1=" " ind2=" "></datafield></record>')
      WHERE biblionumber = C AND format = 'marcxml';
   Check that SELECT * FROM biblio_metadata_errors is empty for A, B and C.

Editing a damaged record (used to go through record_strip_nonxml)
4. Open record A in the cataloguing editor (Edit > Edit record).
   => The record opens, the title is shown without the stray character,
      and a notice says the record was repaired.
5. Save the record without changing anything.
   => It saves with no error.
6. Tools > Log viewer, module Cataloguing: there is a MODIFY entry for A
   with the MARC before and after, and no error.
7. In the database, the stored metadata for A no longer contains the
   control character, and biblio_metadata_errors has a row for A
   (error_type nonxml_stripped, tag 245, subfield a).

Deleting a damaged record
8. Delete record B (it has no items). In the Log viewer there is a DELETE
   entry for B that includes its MARC.

Adding a record
9. Add a new, valid record. The Log viewer has an ADD entry with its MARC.

OAI-PMH
10. Request record C:
    /cgi-bin/koha/oai.pl?verb=GetRecord&metadataPrefix=marcxml
    &identifier=<OAI identifier of C>
    => The record is returned, without the control character or the empty
       500 field, and the request does not fail.

Reading again
11. Open record C in the cataloguing editor, then again.
    => It opens both times. The database has error rows for C, and the
       stored metadata is already repaired, so nothing is repaired again.
       Known limit of this patch: the "repaired" notice in the editor is
       only shown on the read that did the repair; later bugs show it from
       the saved error rows.

Regression check
12. Nothing in steps 4-11 produces an "Invalid metadata" error for these
    records, and the Log viewer has an entry for every step above.

Automated
13. prove t/db_dependent/Koha/Biblio/Metadata.t
14. prove t/db_dependent/Koha/Biblio.t t/db_dependent/Biblio.t \
         t/db_dependent/OAI/ t/db_dependent/Exporter/Record.t

Sponsored-by: OpenFifth
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to