Bugzilla – Attachment 193801 Details for
Bug 39658
Allow definition of non-hierarchical linked patron accounts
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39658: Add Koha::Patron::AccountLink(s) objects
Bug-39658-Add-KohaPatronAccountLinks-objects.patch (text/plain), 5.42 KB, created by
Kellie Stephens
on 2026-02-24 21:13:29 UTC
(
hide
)
Description:
Bug 39658: Add Koha::Patron::AccountLink(s) objects
Filename:
MIME Type:
Creator:
Kellie Stephens
Created:
2026-02-24 21:13:29 UTC
Size:
5.42 KB
patch
obsolete
>From cf856b213c8312f034855fcf26afb088ce1a2a7c Mon Sep 17 00:00:00 2001 >From: Jacob O'Mara <Jacob.omara@openfifth.co.uk> >Date: Wed, 21 Jan 2026 15:36:16 +0000 >Subject: [PATCH] Bug 39658: Add Koha::Patron::AccountLink(s) objects > >New objects to manage patron account links. > >Signed-off-by: Trevor Diamond <trevor.diamond@mainlib.org> >Signed-off-by: Kellie Stephens <kellie.stephens@bywatersolutions.com> >--- > Koha/Patron/AccountLink.pm | 135 ++++++++++++++++++++++++++++++++++++ > Koha/Patron/AccountLinks.pm | 60 ++++++++++++++++ > 2 files changed, 195 insertions(+) > create mode 100644 Koha/Patron/AccountLink.pm > create mode 100644 Koha/Patron/AccountLinks.pm > >diff --git a/Koha/Patron/AccountLink.pm b/Koha/Patron/AccountLink.pm >new file mode 100644 >index 0000000000..ebaaebca4f >--- /dev/null >+++ b/Koha/Patron/AccountLink.pm >@@ -0,0 +1,135 @@ >+package Koha::Patron::AccountLink; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <https://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Koha::Database; >+use Koha::Patron::AccountLinks; >+use Koha::Patrons; >+ >+use base qw(Koha::Object); >+ >+=head1 NAME >+ >+Koha::Patron::AccountLink - Represents a link between patron accounts >+ >+=head1 DESCRIPTION >+ >+Patrons in Koha may have multiple accounts at different libraries within a >+consortium. This class models those links and provides access to linked accounts. >+ >+=head1 API >+ >+=head2 Class methods >+ >+=head3 patron >+ >+Returns the Koha::Patron object for this link >+ >+=cut >+ >+sub patron { >+ my ($self) = @_; >+ return Koha::Patrons->find( $self->borrowernumber ); >+} >+ >+=head3 linked_patrons >+ >+Returns Koha::Patrons of all OTHER patrons in this link group (excluding self) >+ >+=cut >+ >+sub linked_patrons { >+ my ($self) = @_; >+ >+ my @borrowernumbers = Koha::Patron::AccountLinks->search( >+ { >+ link_group_id => $self->link_group_id, >+ borrowernumber => { '!=' => $self->borrowernumber } >+ } >+ )->get_column('borrowernumber'); >+ >+ return Koha::Patrons->search( { borrowernumber => \@borrowernumbers } ); >+} >+ >+=head3 all_linked_borrowernumbers >+ >+Returns arrayref of all borrowernumbers in link group (including self) >+ >+=cut >+ >+sub all_linked_borrowernumbers { >+ my ($self) = @_; >+ >+ my @borrowernumbers = >+ Koha::Patron::AccountLinks->search( { link_group_id => $self->link_group_id } )->get_column('borrowernumber'); >+ >+ return \@borrowernumbers; >+} >+ >+=head3 delete >+ >+Override delete to clean up orphaned links. >+ >+When a patron leaves a linked group, if only one patron remains, >+that patron's link is also deleted (they would be an orphan). >+ >+=cut >+ >+sub delete { >+ my ($self) = @_; >+ >+ my $link_group_id = $self->link_group_id; >+ >+ # Delete this link >+ $self->SUPER::delete; >+ >+ # Check for orphans in the group >+ my @remaining = Koha::Patron::AccountLinks->search( { link_group_id => $link_group_id } )->as_list; >+ >+ # If only one patron remains, delete their orphan link too >+ if ( @remaining == 1 ) { >+ $remaining[0]->SUPER::delete; >+ } >+ >+ return $self; >+} >+ >+=head3 to_api_mapping >+ >+=cut >+ >+sub to_api_mapping { >+ return { >+ id => 'account_link_id', >+ link_group_id => 'link_group_id', >+ borrowernumber => 'patron_id', >+ created_on => 'created_on', >+ }; >+} >+ >+=head2 Internal methods >+ >+=head3 _type >+ >+=cut >+ >+sub _type { >+ return 'PatronAccountLink'; >+} >+ >+1; >diff --git a/Koha/Patron/AccountLinks.pm b/Koha/Patron/AccountLinks.pm >new file mode 100644 >index 0000000000..173e47f0b2 >--- /dev/null >+++ b/Koha/Patron/AccountLinks.pm >@@ -0,0 +1,60 @@ >+package Koha::Patron::AccountLinks; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <https://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Koha::Patron::AccountLink; >+ >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::Patron::AccountLinks - Koha Patron Account Link Object set class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=head3 get_next_group_id >+ >+Returns the next available link_group_id for creating new link groups >+ >+=cut >+ >+sub get_next_group_id { >+ my ($class) = @_; >+ my $max = $class->_resultset->get_column('link_group_id')->max || 0; >+ return $max + 1; >+} >+ >+=head3 _type >+ >+=cut >+ >+sub _type { >+ return 'PatronAccountLink'; >+} >+ >+=head3 object_class >+ >+=cut >+ >+sub object_class { >+ return 'Koha::Patron::AccountLink'; >+} >+ >+1; >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39658
:
193344
|
193345
|
193346
|
193347
|
193348
|
193349
|
193350
|
193351
|
193352
|
193353
|
193354
|
193355
|
193356
|
193357
|
193358
|
193359
|
193462
|
193463
|
193464
|
193465
|
193466
|
193467
|
193468
|
193469
|
193470
|
193471
|
193472
|
193473
|
193474
|
193475
|
193476
|
193477
|
193478
|
193479
|
193781
|
193782
|
193783
|
193784
|
193785
|
193786
|
193787
|
193788
|
193789
|
193790
|
193791
|
193792
|
193793
|
193794
|
193795
|
193796
|
193797
|
193798
|
193800
| 193801 |
193802
|
193803
|
193804
|
193805
|
193806
|
193807
|
193808
|
193809
|
193810
|
193811
|
193812
|
193813
|
193814
|
193815
|
193816
|
193817