I was trying to import records and items with bulkmarcimport.pl. The records were added, but no items were saved to the DB. Turning off OAI-PMH:AutoUpdateSets and OAI-PMH:AutoUpdateSetsEmbedItemData fixed the problem. I think this is what happens: 1. bulkmarcimport.pl calls C4::Biblio::AddBiblio on line 461: eval { ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, '', { defer_marc_save => 1 } ) }; https://git.koha-community.org/Koha-community/Koha/src/branch/master/misc/migration_tools/bulkmarcimport.pl#L461 2. C4::Biblio::AddBiblio has this code: # update OAI-PMH sets if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) { C4::OAI::Sets::UpdateOAISetsBiblio($biblionumber, $record); } https://git.koha-community.org/Koha-community/Koha/src/branch/master/C4/Biblio.pm#L296 3. C4::OAI::Sets::UpdateOAISetsBiblio does this: if (C4::Context->preference('OAI-PMH:AutoUpdateSetsEmbedItemData')) { C4::Biblio::EmbedItemsInMarcBiblio({ marc_record => $record, biblionumber => $biblionumber }); } https://git.koha-community.org/Koha-community/Koha/src/branch/master/C4/OAI/Sets.pm#L612 4. C4::Biblio::EmbedItemsInMarcBiblio does: my ($params) = @_; $marc = $params->{marc_record}; ... _strip_item_fields($marc, $frameworkcode); # ... and embed the current items my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblionumber = ?"); https://git.koha-community.org/Koha-community/Koha/src/branch/master/C4/Biblio.pm#L2501 The end result is that item data is stripped from the record that is about to be imported, and no item data is added from the DB, since they are not there yet. Not sure how to fix this.
This stood out to me as I have some plugin code in C4::Biblio::AddBiblio which fails due to bulkmarcimport.pl using defer_marc_save. I imagine this wouldn't be an issue if we just got rid of the frustrating defer_marc_save via Bug 25539.
Oh actually on another review... it's totally unrelated. Don't mind me. I'm just really biased against defer_marc_save [U+1F605]
We should clone MARC::Record in UpdateOAISetsBiblio ?
Created attachment 137502 [details] [review] Bug 30308 - Fix bulkmarcimport.pl broken by OAI-PMH:AutoUpdateSets(EmbedItemData)
(In reply to Fridolin Somers from comment #3) > We should clone MARC::Record in UpdateOAISetsBiblio ? Yes! It solves the issue.
Shouldn't this be Needs Signoff, Frederic?
Could we get a test plan for this? Thanks!
Created attachment 137630 [details] [review] Bug 30308 - Fix bulkmarcimport.pl broken by OAI-PMH:AutoUpdateSets(EmbedItemData) Test plan: (A) Reproduce the bug: A1 In Administration > System preferences > Web services: - Enable OAI-PMH - Enable OAI-PMH:AutoUpdateSets - Enable OAI-PMH:AutoUpdateSetsEmbedItemData A2 In Tools > Export data > Export bibliographic records, export 1 (one) biblio record. Be sure that this biblio record has at least one item. Don't tick "Don't export items". A3 Delete the exported biblio record, and its items. A4 In command line, on the server load the exported file: ./bulkmarcimport.pl -b -v -file /path/to/koha.mrc A5 Retrieve the biblio record in Koha. Note the absence of the item(s). This is the bug. (B) Apply the patch B1 Delete the record (without item) loaded at A4. B2 In command line, on the server load the exported file: ./bulkmarcimport.pl -b -v -file /path/to/koha.mrc B2 Retrieve the biblio record in Koha. Note the presence of the item(s).
Created attachment 137721 [details] [review] Bug 30308 - Fix bulkmarcimport.pl broken by OAI-PMH:AutoUpdateSets(EmbedItemData) Test plan: (A) Reproduce the bug: A1 In Administration > System preferences > Web services: - Enable OAI-PMH - Enable OAI-PMH:AutoUpdateSets - Enable OAI-PMH:AutoUpdateSetsEmbedItemData A2 In Tools > Export data > Export bibliographic records, export 1 (one) biblio record. Be sure that this biblio record has at least one item. Don't tick "Don't export items". A3 Delete the exported biblio record, and its items. A4 In command line, on the server load the exported file: ./bulkmarcimport.pl -b -v -file /path/to/koha.mrc A5 Retrieve the biblio record in Koha. Note the absence of the item(s). This is the bug. (B) Apply the patch B1 Delete the record (without item) loaded at A4. B2 In command line, on the server load the exported file: ./bulkmarcimport.pl -b -v -file /path/to/koha.mrc B2 Retrieve the biblio record in Koha. Note the presence of the item(s). Signed-off-by: David Nind <david@davidnind.com>
Thanks Frédéric for the test plan!
Frederic, please don't forget to assign yourself!
Created attachment 138301 [details] [review] Bug 30308: Fix bulkmarcimport.pl broken by OAI-PMH:AutoUpdateSets(EmbedItemData) Test plan: (A) Reproduce the bug: A1 In Administration > System preferences > Web services: - Enable OAI-PMH - Enable OAI-PMH:AutoUpdateSets - Enable OAI-PMH:AutoUpdateSetsEmbedItemData A2 In Tools > Export data > Export bibliographic records, export 1 (one) biblio record. Be sure that this biblio record has at least one item. Don't tick "Don't export items". A3 Delete the exported biblio record, and its items. A4 In command line, on the server load the exported file: ./bulkmarcimport.pl -b -v -file /path/to/koha.mrc A5 Retrieve the biblio record in Koha. Note the absence of the item(s). This is the bug. (B) Apply the patch B1 Delete the record (without item) loaded at A4. B2 In command line, on the server load the exported file: ./bulkmarcimport.pl -b -v -file /path/to/koha.mrc B2 Retrieve the biblio record in Koha. Note the presence of the item(s). Signed-off-by: David Nind <david@davidnind.com>
Pushed to master for 22.11. Nice work everyone, thanks!
Don't forget to sign, Kyle :) Thx for QA!
Please backport to old branches
Backported to 22.05.x for 22.05.05
Thanks! Pushed to 21.11 for 21.11.12
Backported: Pushed to 21.05.x branch for 21.05.19 nothing to document