View | Details | Raw Unified | Return to bug 11889
Collapse All | Expand All

(-)a/Koha/Patron.pm (-17 / +20 lines)
Lines 352-359 $patron->delete Link Here
352
352
353
Delete patron's holds, lists and finally the patron.
353
Delete patron's holds, lists and finally the patron.
354
354
355
Lists owned by the borrower are deleted, but entries from the borrower to
355
Lists owned by the borrower are deleted or ownership is transfered depending on the
356
other lists are kept.
356
ListOwnershipUponPatronDeletion pref, but entries from the borrower to other lists are kept.
357
357
358
=cut
358
=cut
359
359
Lines 368-388 sub delete { Link Here
368
                $hold->cancel;
368
                $hold->cancel;
369
            }
369
            }
370
370
371
            # Delete all lists and all shares of this borrower
371
            # If ListOwnershipUponPatronDeletion = transfer, change ownership of all
372
            # Consistent with the approach Koha uses on deleting individual lists
372
            # public and shared lists to the user who deleted them.
373
            # Note that entries in virtualshelfcontents added by this borrower to
373
            if ( C4::Context->preference('ListOwnershipUponPatronDeletion') eq 'transfer' ) {
374
            # lists of others will be handled by a table constraint: the borrower
374
                my $userenv = C4::Context->userenv();
375
            # is set to NULL in those entries.
375
                my $usernumber = (ref($userenv) eq 'HASH') ? $userenv->{'number'} : 0;
376
            # NOTE:
376
                my @publiclists = Koha::Virtualshelves->get_public_shelves;
377
            # We could handle the above deletes via a constraint too.
377
                my @sharedlists = Koha::Virtualshelves->search({ 'me.owner' => $self->borrowernumber, 'me.shelfnumber' => { -ident => 'virtualshelfshares.shelfnumber' }  }, { prefetch => 'virtualshelfshares' });
378
            # But a new BZ report 11889 has been opened to discuss another approach.
378
                foreach my $plist ( @publiclists ) {
379
            # Instead of deleting we could also disown lists (based on a pref).
379
                    $plist->set({ owner => $usernumber })->store;
380
            # In that way we could save shared and public lists.
380
                }
381
            # The current table constraints support that idea now.
381
                foreach my $slist ( @sharedlists ) {
382
            # This pref should then govern the results of other routines/methods such as
382
                    $slist->set({ owner => $usernumber })->store;
383
            # Koha::Virtualshelf->new->delete too.
383
                }
384
            # FIXME Could be $patron->get_lists
384
            }
385
            $_->delete for Koha::Virtualshelves->search( { owner => $self->borrowernumber } );
385
386
            # Delete any remaining lists that this user is an owner of (always private lists,
387
            # only public and shared lists if ListOwnershipUponPatronDeletion = delete)
388
            $_->delete for Koha::Virtualshelves->search({ owner => $self->borrowernumber });
386
389
387
            # We cannot have a FK on borrower_modifications.borrowernumber, the table is also used
390
            # We cannot have a FK on borrower_modifications.borrowernumber, the table is also used
388
            # for patron selfreg
391
            # for patron selfreg
(-)a/installer/data/mysql/atomicupdate/bug_11889_-_add_ListOwnershipUponPatronDeletion_syspref.sql (+1 lines)
Line 0 Link Here
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 (-1 / +6 lines)
Lines 21-26 Patrons: Link Here
21
               yes: "Allow"
21
               yes: "Allow"
22
               no: "Don't allow"
22
               no: "Don't allow"
23
         - "staff to access a patron's checkout and hold history (reading history is still stored, regardless of staff being allowed access or not)."
23
         - "staff to access a patron's checkout and hold history (reading history is still stored, regardless of staff being allowed access or not)."
24
     -
25
         - "When deleting a patron who owns public or shared lists,"
26
         - pref: ListOwnershipUponPatronDeletion
27
           choices:
28
            delete: "delete all of their public and shared lists."
29
            transfer: "transfer ownership of their public and shared lists to the patron who deleted the owner."
24
     -
30
     -
25
         - The late fine for all checkouts will only go up to
31
         - The late fine for all checkouts will only go up to
26
         - pref: MaxFine
32
         - pref: MaxFine
27
- 

Return to bug 11889