From 65a9fed4f458484850070dc063fca466c5429b07 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Mon, 30 Oct 2023 15:26:22 -0100 Subject: [PATCH] Bug 35115 [Alternative]: Skip Resource store logic if resource was imported from list This patch fixes the data loss issue when importing titles from a list of biblios. It does NOT fix the data loss issue when saving a title that is linked to a biblio, that will still caused data loss on the biblio. I believe store in Resource.pm is trying to do a couple things: 1) Updating Biblio when a title is saved, or 2) Adding a biblio when a title is created The problem is that it's updating the biblio when the title is created from an import list, as if new changes were made to the title and need to be reflected to the biblio. This is not the case, a title created from an imported list of biblios should have no business updating their respective biblio's MARC at that time. ---- The biblio MARC being updated when the title is saved through the edit form should perhaps be a different bug. Should all possible fields be updated on the biblio when saving the title? --- Koha/BackgroundJob/CreateEHoldingsFromBiblios.pm | 3 ++- Koha/ERM/EHoldings/Resource.pm | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Koha/BackgroundJob/CreateEHoldingsFromBiblios.pm b/Koha/BackgroundJob/CreateEHoldingsFromBiblios.pm index 9638c7fcd3..3090fe2764 100644 --- a/Koha/BackgroundJob/CreateEHoldingsFromBiblios.pm +++ b/Koha/BackgroundJob/CreateEHoldingsFromBiblios.pm @@ -245,7 +245,8 @@ sub process { : _get_marc21_mapping($biblio); $eholding_title = Koha::ERM::EHoldings::Title->new($eholding_title)->store; - Koha::ERM::EHoldings::Resource->new({ title_id => $eholding_title->title_id, package_id => $package_id })->store; + Koha::ERM::EHoldings::Resource->new( { title_id => $eholding_title->title_id, package_id => $package_id } ) + ->store( { imported_from_list => 1 } ); $report->{total_success}++; } catch { push @messages, { diff --git a/Koha/ERM/EHoldings/Resource.pm b/Koha/ERM/EHoldings/Resource.pm index 2457b2d644..56eefe725b 100644 --- a/Koha/ERM/EHoldings/Resource.pm +++ b/Koha/ERM/EHoldings/Resource.pm @@ -44,7 +44,12 @@ Koha::ERM::EHoldings::Resource - Koha EHolding resource Object class =cut sub store { - my ($self) = @_; + my ($self, $params) = @_; + + if ( $params->{imported_from_list} ){ + $self = $self->SUPER::store; + return $self; + } # FIXME This is terrible and ugly, we need to: # * Provide a mapping for each attribute of title -- 2.30.2