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

(-)a/Koha/Patron.pm (-21 / +1 lines)
Lines 388-404 sub delete { Link Here
388
            }
388
            }
389
389
390
            # Handle lists (virtualshelves)
390
            # Handle lists (virtualshelves)
391
            my $new_owner = _new_owner();
391
            $self->virtualshelves->disown_or_delete;
392
            my $lists = $self->virtualshelves;
393
            while( my $list = $lists->next ) {
394
                if( $new_owner && ( $list->is_public || $list->is_shared )) {
395
                    # if new_owner had a share, remove it
396
                    $list->remove_share( $new_owner ) if $list->is_private;
397
                    $list->set({ owner => $new_owner })->store; # transfer ownership of public/shared list
398
                } else { # delete
399
                    $list->delete;
400
                }
401
            }
402
392
403
            # We cannot have a FK on borrower_modifications.borrowernumber, the table is also used
393
            # We cannot have a FK on borrower_modifications.borrowernumber, the table is also used
404
            # for patron selfreg
394
            # for patron selfreg
Lines 412-427 sub delete { Link Here
412
    return $self;
402
    return $self;
413
}
403
}
414
404
415
sub _new_owner {
416
    if( C4::Context->preference('ListOwnershipUponPatronDeletion') eq 'transfer' ) {
417
        # designated owner overrides userenv
418
        my $designated_owner = C4::Context->preference('ListOwnerDesignated');
419
        return $designated_owner if Koha::Patrons->find($designated_owner);
420
        my $userenv = C4::Context->userenv;
421
        return $userenv->{'number'} if $userenv;
422
    }
423
}
424
425
=head3 category
405
=head3 category
426
406
427
my $patron_category = $patron->category
407
my $patron_category = $patron->category
(-)a/Koha/Virtualshelf.pm (+19 lines)
Lines 23-28 use C4::Auth qw( haspermission ); Link Here
23
use Koha::Patrons;
23
use Koha::Patrons;
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::DateUtils qw( dt_from_string );
25
use Koha::DateUtils qw( dt_from_string );
26
use Koha::Exceptions;
26
use Koha::Exceptions::Virtualshelf;
27
use Koha::Exceptions::Virtualshelf;
27
use Koha::Virtualshelfshare;
28
use Koha::Virtualshelfshare;
28
use Koha::Virtualshelfshares;
29
use Koha::Virtualshelfshares;
Lines 331-336 sub cannot_be_transferred { Link Here
331
    return 0; # serving as green light
332
    return 0; # serving as green light
332
}
333
}
333
334
335
=head3 transfer_ownership
336
337
    $list->transfer_ownership( $patron_id );
338
339
This method transfers the list ownership to the passed I<$patron_id>.
340
341
=cut
342
343
sub transfer_ownership {
344
    my ( $self, $patron_id ) = @_;
345
346
    Koha::Exceptions::MissingParameter->throw( "Mandatory parameter 'patron' missing" )
347
      unless $patron_id;
348
349
    $self->remove_share( $patron_id ) if $self->is_private;
350
    return $self->set({ owner => $patron_id })->store;
351
}
352
334
=head2 Internal methods
353
=head2 Internal methods
335
354
336
=head3 _type
355
=head3 _type
(-)a/Koha/Virtualshelves.pm (-2 / +41 lines)
Lines 20-25 use Modern::Perl; Link Here
20
20
21
use Koha::Database;
21
use Koha::Database;
22
22
23
use Koha::Patrons;
23
use Koha::Virtualshelf;
24
use Koha::Virtualshelf;
24
25
25
26
Lines 31-40 Koha::Virtualshelf - Koha Virtualshelf Object class Link Here
31
32
32
=head1 API
33
=head1 API
33
34
34
=head2 Class Methods
35
=head2 Class methods
36
37
=head3 disown_or_delete
38
39
    $lists->disown_or_delete;
40
41
This method will transfer public/shared lists to the appropriate patron or
42
just delete them if not possible.
35
43
36
=cut
44
=cut
37
45
46
sub disown_or_delete {
47
    my ($self) = @_;
48
49
    $self->_resultset->result_source->schema->txn_do(
50
        sub {
51
            if ( C4::Context->preference('ListOwnershipUponPatronDeletion') eq 'transfer' ) {
52
                my $new_owner;
53
54
                $new_owner = C4::Context->preference('ListOwnerDesignated')
55
                  if C4::Context->preference('ListOwnerDesignated')
56
                  and Koha::Patrons->find( C4::Context->preference('ListOwnerDesignated') );
57
58
                unless ($new_owner) {
59
                    $new_owner = C4::Context->userenv->{number};
60
                }
61
62
                while ( my $list = $self->next ) {
63
                    if ( $list->is_public or $list->is_shared ) {
64
                        $list->transfer_ownership($new_owner);
65
                    } else {
66
                        $list->delete;
67
                    }
68
                }
69
            } else {    # 'delete'
70
                $_->delete for $self->as_list;
71
            }
72
        }
73
    );
74
75
    return $self;
76
}
77
38
=head3 get_private_shelves
78
=head3 get_private_shelves
39
79
40
=cut
80
=cut
41
- 

Return to bug 30933