From 8ede54c33e493bccb02dfa09edaddc45f2d56941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=A4is=C3=A4?= Date: Mon, 11 Aug 2025 12:05:30 +0300 Subject: [PATCH] Bug 40339: add guarantees to target patron when merging patrons This patch adds the guarantees from the source patron to the target patron when merging patrons. Test plan: 1. Create two patrons with different guarantees. 2. Merge the source patron into the target patron. 3. See that the target patron does not have the source patron's guarantees. 4. Apply this patch. 5. Repeat the merge. 6. See that the target patron now has the source patron's guarantees. Sponsored-by: Koha-Suomi Oy --- members/merge-patrons.pl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/members/merge-patrons.pl b/members/merge-patrons.pl index cb10f2fcbb..cbeb7daf3f 100755 --- a/members/merge-patrons.pl +++ b/members/merge-patrons.pl @@ -51,6 +51,23 @@ if ( $op eq 'show' ) { if ($keeper) { try { + # Find all guarantor relationships for the patrons to be merged + my $patrons_to_merge_rs = Koha::Patrons->search({ borrowernumber => { -in => \@ids } }); + + while (my $patron = $patrons_to_merge_rs->next) { + # Ensure $patron is a valid Koha::Patron object + if ($patron && $patron->isa('Koha::Patron')) { + my $relationships = Koha::Patron::Relationships->search({ guarantor_id => $patron->id }); + + while (my $relationship = $relationships->next) { + $relationship->guarantor_id($keeper_id); + $relationship->store; + } + } else { + # If the patron is not valid, we should handle it gracefully + die "Invalid patron"; + } + } $results = $keeper->merge_with( \@ids ); $template->param( keeper => $keeper, -- 2.34.1