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

(-)a/Koha/Patron.pm (-17 / +20 lines)
Lines 54-61 $patron->delete Link Here
54
54
55
Delete patron's holds, lists and finally the patron.
55
Delete patron's holds, lists and finally the patron.
56
56
57
Lists owned by the borrower are deleted, but entries from the borrower to
57
Lists owned by the borrower are deleted or ownership is transfered depending on the
58
other lists are kept.
58
ListOwnershipUponPatronDeletion pref, but entries from the borrower to other lists are kept.
59
59
60
=cut
60
=cut
61
61
Lines 68-88 sub delete { Link Here
68
            # Delete Patron's holds
68
            # Delete Patron's holds
69
            $self->holds->delete;
69
            $self->holds->delete;
70
70
71
            # Delete all lists and all shares of this borrower
71
            # If ListOwnershipUponPatronDeletion = transfer, change ownership of all
72
            # Consistent with the approach Koha uses on deleting individual lists
72
            # public and shared lists to the user who deleted them.
73
            # Note that entries in virtualshelfcontents added by this borrower to
73
            if ( C4::Context->preference('ListOwnershipUponPatronDeletion') eq 'transfer' ) {
74
            # lists of others will be handled by a table constraint: the borrower
74
                my $userenv = C4::Context->userenv();
75
            # is set to NULL in those entries.
75
                my $usernumber = (ref($userenv) eq 'HASH') ? $userenv->{'number'} : 0;
76
            # NOTE:
76
                my @publiclists = Koha::Virtualshelves->get_public_shelves;
77
            # We could handle the above deletes via a constraint too.
77
                my @sharedlists = Koha::Virtualshelves->search({ 'me.owner' => $self->borrowernumber, 'me.shelfnumber' => { -ident => 'virtualshelfshares.shelfnumber' }  }, { prefetch => 'virtualshelfshares' });
78
            # But a new BZ report 11889 has been opened to discuss another approach.
78
                foreach my $plist ( @publiclists ) {
79
            # Instead of deleting we could also disown lists (based on a pref).
79
                    $plist->set({ owner => $usernumber })->store;
80
            # In that way we could save shared and public lists.
80
                }
81
            # The current table constraints support that idea now.
81
                foreach my $slist ( @sharedlists ) {
82
            # This pref should then govern the results of other routines/methods such as
82
                    $slist->set({ owner => $usernumber })->store;
83
            # Koha::Virtualshelf->new->delete too.
83
                }
84
            # FIXME Could be $patron->get_lists
84
            }
85
            $_->delete for Koha::Virtualshelves->search( { owner => $self->borrowernumber } );
85
86
            # Delete any remaining lists that this user is an owner of (always private lists,
87
            # only public and shared lists if ListOwnershipUponPatronDeletion = delete)
88
            $_->delete for Koha::Virtualshelves->search({ owner => $self->borrowernumber });
86
89
87
            $deleted = $self->SUPER::delete;
90
            $deleted = $self->SUPER::delete;
88
91
(-)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 77-82 Patrons: Link Here
77
               no: "Don't allow"
77
               no: "Don't allow"
78
         - "staff to access a patron's checkout history (reading history is still stored, regardless of staff being allowed access or not)."
78
         - "staff to access a patron's checkout history (reading history is still stored, regardless of staff being allowed access or not)."
79
     -
79
     -
80
         - "When deleting a patron who owns public or shared lists,"
81
         - pref: ListOwnershipUponPatronDeletion
82
           choices:
83
            delete: "delete all of their public and shared lists."
84
            transfer: "transfer ownership of their public and shared lists to the patron who deleted the owner."
85
     -
80
         - The late fine for all checkouts will only go up to
86
         - The late fine for all checkouts will only go up to
81
         - pref: MaxFine
87
         - pref: MaxFine
82
           class: currency
88
           class: currency
83
- 

Return to bug 11889