[Koha] MARC modification templates problem

Eric Phetteplace ephetteplace at cca.edu
Wed Aug 9 10:39:50 NZST 2023


Hi Caroline,

Yes, they do happen to have different domains, one I want to preserve and
one I want to proxy. Thank you for the suggestion! Using a more qualified
regex seemed like it should work, but Koha still clobbers the second 856$u
subfield. Here's a modified example:

Record
245 _ _ ‡aExample
856 4 0 ‡uhttps://example.com‡yLink to proxy
856 4 0 ‡uhttps://www.cca.edu‡yLink to retain

MARC modification
Copy and replace 1st field(s) 856 u to field 856 u
Regex ✅ s/^https?://example\.com/
https://proxy.cca.edu/url?=https://example.com/
If field 856 u matches m/https://example.com/ Regex ✅

Output record
245    _aExample
856 40 _uhttps://proxy.cca.edu/url?=https://example.com
       _yLink to proxy
856 40 _uhttps://proxy.cca.edu/url?=https://example.com
       _yLink to retain

As the "if" condition cannot stop the second field from being modified, the
regex also cannot. Koha seems to take the first 856, check it against the
if condition, and then copies the modified $u subfield to all other
instances of 856$u no matter what is configured in the modification
template. Again, I tested with both "all" and "1st" 856 fields and the
result was the same. Saying "1st" 856 still modifies both 856s.

So am I stuck writing a bug report? There's no way to modify only one of a
set of the same fields even with if conditions? I would expect other
templates dealing with commonly repeated fields like subject headings to
run into trouble then. Maybe only the "copy and replace" action has
problems so fewer templates are affected?

Best,

ERIC PHETTEPLACE Systems Librarian, Libraries (he/him)

ephetteplace at cca.edu


*CCA is situated on the traditional unceded lands of the **Chochenyo and
Ramaytush Ohlone** peoples.*

Black-owned bookstores in Oakland: Ashay by the Bay
<https://ashaybythebay.com/>, Marcus Books
<https://www.facebook.com/marcus.books/>

:(){ :|: & };:


On Mon, Aug 7, 2023 at 6:40 AM Caroline Cyr La Rose <
caroline.cyr-la-rose at inlibro.com> wrote:

> Hi Eric,
>
> This has been my experience as well. I haven't found a way to modify
> only one field when there are more that one of the same tag in the same
> record.
>
> Are the links you are trying to change all the same domain? Or a couple
> of different domains? If so, you could match the regex on a longer part
> of the URL e.g.
> s/^
> https://some-online-resource.com/https://proxy.cca.edu/url?=https://some-online-resource.com
>
> You can have many options in one modification template, so you can have
> many "copy and replace" for various resources. Or you can do it by
> batch. The latter is usually what I've done in the past: make a report
> to have the URLs matching some-online-resource.com, batch modify those.
> Then change the modification template, change the report to have the
> URLs another-online-resource.com and batch modify those records, etc.
>
> Good luck!
>
> Caroline
>
> On 2023-08-04 11:31, Eric Phetteplace wrote:
> > Hi collective wisdom,
> >
> > I'm running into a MARC modification template problem and I can't tell if
> > I'm missing something or there's a bug/limitation. I know I could
> > accomplish these edits with MARCEdit or a script, but I was hoping to use
> > Koha's tools.
> >
> > I have a record with two 856 fields with links, I want to apply our proxy
> > server prefix to one link but not the other. That seems to be impossible;
> > Koha clobbers the second link with a copy of the first. Here's a minimal
> > example.
> >
> > Record
> > 245 _ _ ‡aExample
> > 856 4 0 ‡uhttps://example.com‡yLink to proxy
> > 856 4 0 ‡uhttps://www.cca.edu‡yLink to retain
> >
> > MARC modification
> > Copy and replace 1st field(s) 856 u to field 856 u Regex ✅ s/^http/
> > https://proxy.cca.edu/url?=http/
> > If field 856 u matches m/https://example.com/  Regex ✅
> >
> > Output record
> > 245    _aExample
> > 856 40 _uhttps://proxy.cca.edu/url?=https://example.com
> >         _yLink to proxy
> > 856 40 _uhttps://proxy.cca.edu/url?=https://example.com
> >         _yLink to retain
> >
> > This happens whether I set the modification template to use the "1st" or
> > "every"  856 field. I don't understand why the second 856 is touched at
> > all, since it does not meet the "if" condition, much less why instead of
> > receiving its own link proxied it gets the first 856 URL proxied.
> >
> > Based on a few tests, it also seems like the "1st" field with respect to
> > modification actions is not always the one that's visually first when I
> > edit a record. I tried a set of three actions which 1) copied the first
> > field to another, unused field, 2) modified it there, and then 3) copied
> it
> > back, but Koha copied the second field instead.
> >
> > Best,
> >
> > ERIC PHETTEPLACE Systems Librarian, Libraries (he/him)
> >
> > ephetteplace at cca.edu
> >
> >
> > *CCA is situated on the traditional unceded lands of the **Chochenyo and
> > Ramaytush Ohlone** peoples.*
> >
> > Black-owned bookstores in Oakland: Ashay by the Bay
> > <https://ashaybythebay.com/>, Marcus Books
> > <https://www.facebook.com/marcus.books/>
> >
> > :(){ :|: & };:
> > _______________________________________________
> >
> > Koha mailing listhttp://koha-community.org
> > Koha at lists.katipo.co.nz
> > Unsubscribe:https://lists.katipo.co.nz/mailman/listinfo/koha
> --
> Logo inLibro <https://inLibro.com>      Caroline Cyr-La-Rose
> Bibliothécaire | Responsable de produit
>
> T 833-INLIBRO (465-4276) <tel:833-465-4276>, poste 221
> C caroline.cyr-la-rose at inlibro.com
>
> www.inLibro.com <https://inLibro.com>
> _______________________________________________
>
> Koha mailing list  http://koha-community.org
> Koha at lists.katipo.co.nz
> Unsubscribe: https://lists.katipo.co.nz/mailman/listinfo/koha
>


More information about the Koha mailing list