Koha/catalogue
Julian Maurice 76e980bb1a Bug 29333: Fix encoding of imported UNIMARC authorities
MARC::Record and MARC::File::* modules sometimes use the position 09 of
the leader to detect encoding. A blank character means 'MARC-8' while an
'a' means 'UTF-8'.

In a UNIMARC authority this position is used to store the authority type
(see https://www.transition-bibliographique.fr/wp-content/uploads/2021/02/AIntroLabel-2004.pdf [FR]).
In this case, 'a' means 'Personal Name'.

The result is that the import will succeed for a Personal Name
authority, but it will fail for all other authority types.

Steps to reproduce:
0. Be sure to have a Koha UNIMARC instance.
1. Download the MARCXML for "Honoré de Balzac"
   curl -o balzac.marcxml https://www.idref.fr/02670305X.xml
2. Verify that it's encoded in UTF-8
   file balzac.marcxml
   (should output "balzac.marcxml: XML 1.0 document, UTF-8 Unicode
   text")
3. Go to Tools » Stage MARC for import and import balzac.marcxml with
   the following settings:
   Record type: Authority
   Character encoding: UTF-8
   Format: MARCXML
   Do not touch the other settings
4. Once imported, go to the staged MARC management tool and find your
   batch. Click on the authority title "Balzac Honoré de 1799-1850" to
   show the MARC inside a modal window. There should be no encoding
   issue.
5. Write down the imported record id (the number in column '#') and go
   to the MARC authority editor. Replace all URL parameters by
   'breedingid=THE_ID_YOU_WROTE_DOWN'
   The URL should look like this:
   /cgi-bin/koha/authorities/authorities.pl?breedingid=198
   You should see no encoding issues. Do not save the record.
6. Import the batch into the catalog. Verify that the authority record
   has no encoding issue.
7. Now download the MARCXML for "Athènes (Grèce)"
   curl -o athènes.marcxml https://www.idref.fr/027290530.xml
8. Repeat steps 2 to 6 using athènes.marcxml file. At steps 4 and 5 you
   should see encoding issues and that the position 9 of the leader was
   rewritten from 'c' to 'a'. Strangely, importing this batch fix the
   encoding issue, but we still lose the information in position 09 of
   the leader

This patch makes use of the MARCXML representation of the record instead
of the ISO2709 representation, because, unlike
MARC::Record::new_from_usmarc, MARC::Record::new_from_xml allows us to
pass directly the encoding and the format, which prevents data to be
double encoded when position 09 of the leader is different that 'a'

Test plan:
- Follow the "steps to reproduce" above and verify that you have no
  encoding issues.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 01d78e1ec7)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2022-08-23 15:30:11 +00:00
..
detail.pl Bug 30976: Display biblio's cover images first 2022-08-12 15:43:47 +00:00
export.pl Bug 17600: Standardize our EXPORT_OK 2021-07-16 08:58:47 +02:00
getitem-ajax.pl Bug 17600: Standardize our EXPORT_OK 2021-07-16 08:58:47 +02:00
image.pl Bug 28606: Remove $DEBUG and $ENV{DEBUG} 2021-06-24 11:53:44 +02:00
imageviewer.pl Bug 17600: Standardize our EXPORT_OK 2021-07-16 08:58:47 +02:00
ISBDdetail.pl Bug 28959: (follow-up) Adjust all places in which 'category' was used 2021-10-28 17:47:38 +02:00
issuehistory.pl Bug 29844: Fix ->search occurrences 2022-02-09 15:36:23 -10:00
item-export.pl Bug 29859: Use iterator instead of as_list 2022-02-09 15:36:23 -10:00
itemsearch.pl Bug 17748: Show due date and availability in item search results 2022-03-24 14:22:10 -10:00
labeledMARCdetail.pl Bug 28959: (follow-up) Adjust all places in which 'category' was used 2021-10-28 17:47:38 +02:00
MARCdetail.pl Bug 28959: (follow-up) Adjust all places in which 'category' was used 2021-10-28 17:47:38 +02:00
moredetail.pl Bug 28959: (follow-up) Adjust all places in which 'category' was used 2021-10-28 17:47:38 +02:00
search-history.pl Bug 17600: Standardize our EXPORT_OK 2021-07-16 08:58:47 +02:00
search.pl Bug 22605: Add ability to edit a search on staff interface 2022-03-24 14:22:09 -10:00
showmarc.pl Bug 29333: Fix encoding of imported UNIMARC authorities 2022-08-23 15:30:11 +00:00
stockrotation.pl Bug 17600: Standardize our EXPORT_OK 2021-07-16 08:58:47 +02:00
updateitem.pl Bug 17600: Standardize our EXPORT_OK 2021-07-16 08:58:47 +02:00