@@ -, +, @@ --- Koha/Patron.pm | 37 ++++++++++++---------- ...add_ListOwnershipUponPatronDeletion_syspref.sql | 1 + .../prog/en/modules/admin/preferences/patrons.pref | 6 ++++ 3 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_11889_-_add_ListOwnershipUponPatronDeletion_syspref.sql --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -54,8 +54,8 @@ $patron->delete Delete patron's holds, lists and finally the patron. -Lists owned by the borrower are deleted, but entries from the borrower to -other lists are kept. +Lists owned by the borrower are deleted or ownership is transfered depending on the +ListOwnershipUponPatronDeletion pref, but entries from the borrower to other lists are kept. =cut @@ -68,21 +68,24 @@ sub delete { # Delete Patron's holds $self->holds->delete; - # Delete all lists and all shares of this borrower - # Consistent with the approach Koha uses on deleting individual lists - # Note that entries in virtualshelfcontents added by this borrower to - # lists of others will be handled by a table constraint: the borrower - # is set to NULL in those entries. - # NOTE: - # We could handle the above deletes via a constraint too. - # But a new BZ report 11889 has been opened to discuss another approach. - # Instead of deleting we could also disown lists (based on a pref). - # In that way we could save shared and public lists. - # The current table constraints support that idea now. - # This pref should then govern the results of other routines/methods such as - # Koha::Virtualshelf->new->delete too. - # FIXME Could be $patron->get_lists - $_->delete for Koha::Virtualshelves->search( { owner => $self->borrowernumber } ); + # If ListOwnershipUponPatronDeletion = transfer, change ownership of all + # public and shared lists to the user who deleted them. + if ( C4::Context->preference('ListOwnershipUponPatronDeletion') eq 'transfer' ) { + my $userenv = C4::Context->userenv(); + my $usernumber = (ref($userenv) eq 'HASH') ? $userenv->{'number'} : 0; + my @publiclists = Koha::Virtualshelves->get_public_shelves; + my @sharedlists = Koha::Virtualshelves->search({ 'me.owner' => $self->borrowernumber, 'me.shelfnumber' => { -ident => 'virtualshelfshares.shelfnumber' } }, { prefetch => 'virtualshelfshares' }); + foreach my $plist ( @publiclists ) { + $plist->set({ owner => $usernumber })->store; + } + foreach my $slist ( @sharedlists ) { + $slist->set({ owner => $usernumber })->store; + } + } + + # Delete any remaining lists that this user is an owner of (always private lists, + # only public and shared lists if ListOwnershipUponPatronDeletion = delete) + $_->delete for Koha::Virtualshelves->search({ owner => $self->borrowernumber }); $deleted = $self->SUPER::delete; --- a/installer/data/mysql/atomicupdate/bug_11889_-_add_ListOwnershipUponPatronDeletion_syspref.sql +++ a/installer/data/mysql/atomicupdate/bug_11889_-_add_ListOwnershipUponPatronDeletion_syspref.sql @@ -0,0 +1, @@ +INSERT INTO systempreferences (`variable`,`value`,`options`,`explanation`,`type`) VALUES ('ListOwnershipUponPatronDeletion', 'delete', 'delete|transfer', 'When deleting a patron who owns public lists, either delete the public lists or transfer ownership to the patron who deleted the owner', 'Choice'); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -77,6 +77,12 @@ Patrons: no: "Don't allow" - "staff to access a patron's checkout history (reading history is still stored, regardless of staff being allowed access or not)." - + - "When deleting a patron who owns public or shared lists," + - pref: ListOwnershipUponPatronDeletion + choices: + delete: "delete all of their public and shared lists." + transfer: "transfer ownership of their public and shared lists to the patron who deleted the owner." + - - The late fine for all checkouts will only go up to - pref: MaxFine class: currency --