Bug 40594

Summary: Allow batch record modification to create multiple items on existing bibs
Product: Koha Reporter: Pedro Amorim <pedro.amorim>
Component: CatalogingAssignee: Bugs List <koha-bugs>
Status: Needs Signoff --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: bernard.scaife, chris.rowlands6, esther.melander, hebah, m.de.rooy, martin.renvoize, pedro.amorim
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 26869    
Bug Blocks:    
Attachments: MMT sample multiple mapped items
Bug 40594: Consider multiple items mapped in MMT

Description Pedro Amorim 2025-08-05 11:40:54 UTC
Created attachment 185115 [details]
MMT sample multiple mapped items

Bug 26869 only considered one item to be added per library modification execution, if more than one item is mapped, it fails with an FK constraint.

I don't know the reason behind it, but the original test plan stated:

test with more than one occurrence of 952$a -> confirm 'FK constraint' error is shown, no modification made

I don't think there's any reason why this restriction should exist. The attached Marc Modification Template sample should work perfectly fine and add new - multiple - items to biblio records, as mapped.
Comment 1 Pedro Amorim 2025-08-05 11:45:32 UTC
Created attachment 185116 [details] [review]
Bug 40594: Consider multiple items mapped in MMT

Test plan, clean k-t-d:

Before test, pick a record and confirm it has no items, for this test we're using biblio 79:
<staff_url>/cgi-bin/koha/catalogue/detail.pl?biblionumber=79

1) Add a new MARC modification template, visit:
<staff_url>/cgi-bin/koha/tools/marc_modification_templates.pl
2) Click 'New template', enter a name and click 'Submit'
3) Add multiple items mapping, use the attached Marc Modification template sample as reference
4) Do a batch record modification, visit:
<staff_url>/cgi-bin/koha/tools/batch_record_modification.pl
5) Select the tab 'Enter a list of record numbers' and enter '79'
6) On the template, select the template previously created. Click 'continue'
7) Click 'Modify selected records'. Click 'View detail of the enqueued job'. Notice success message is shown with no errors
8) Check the biblio, visit:
<staff_url>/cgi-bin/koha/catalogue/detail.pl?biblionumber=79
9) Notice it now has however how many new items you added to the mapping

Additional testing notes from bug 26869:
test with 952 but with other subfields, without subfield 'a' -> confirm 'FK constraint' error is shown, no modification made
test with 952$a too long e.g. 'aaaaaaaa' -> confirm 'too long' error is shown
test with no 952 mapping -> confirm things work as intended
test with 952 mapping plus other tags -> confirm things work as intended

prove koha/t/db_dependent/Koha/BackgroundJobs/BatchUpdateBiblio.t
prove koha/t/db_dependent/Koha/BackgroundJob/BatchUpdateBiblio.t
Comment 2 Bernard 2025-08-08 11:01:11 UTC
Test plan in #1 followed
 
All records were successfully modified. 

Further tests:

a) test with 952 but with other subfields, without subfield 'a' -> confirm 'FK constraint' error is shown, no modification made

Removed 952$a from one of 3 items. It successfully loaded the other 2 but no error is shown relating to "FK constraint". FAIL

b) test with 952$a too long e.g. 'aaaaaaaa' -> confirm 'too long' error is shown

Made one 952$a 'aaaaaaaaaaaaaa' It successfully loaded the other 2 but no error is shown relating to "too long". FAIL

c) test with no 952 mapping -> confirm things work as intended

Made template with only 264a field to be added. Works fine. PASS

d) test with 952 mapping plus other tags -> confirm things work as intended

Template with 952 and 856 - works fine PASS