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

(-)a/Koha/Patron.pm (-8 / +14 lines)
Lines 389-404 sub delete { Link Here
389
            }
389
            }
390
390
391
            # Handle lists (virtualshelves)
391
            # Handle lists (virtualshelves)
392
            my $userenv = C4::Context->userenv;
392
            my $new_owner = _new_owner();
393
            my $usernumber = ref($userenv) eq 'HASH' ? $userenv->{'number'} : 0;
394
            my $lists = $self->virtualshelves;
393
            my $lists = $self->virtualshelves;
395
            while( my $list = $lists->next ) {
394
            while( my $list = $lists->next ) {
396
                # if staff member had a share, remove it
395
                if( $new_owner && ( $list->is_public || $list->is_shared )) {
397
                $list->remove_share( $usernumber ) if $usernumber && $list->is_private;
396
                    # if new_owner had a share, remove it
398
                if( C4::Context->preference('ListOwnershipUponPatronDeletion') eq 'transfer' &&
397
                    $list->remove_share( $new_owner ) if $list->is_private;
399
                    $usernumber && ( $list->is_public || $list->is_shared ))
398
                    $list->set({ owner => $new_owner })->store; # transfer ownership of public/shared list
400
                {
401
                    $list->set({ owner => $usernumber })->store; # transfer ownership of public/shared list
402
                } else { # delete
399
                } else { # delete
403
                    $list->delete;
400
                    $list->delete;
404
                }
401
                }
Lines 416-421 sub delete { Link Here
416
    return $self;
413
    return $self;
417
}
414
}
418
415
416
sub _new_owner {
417
    if( C4::Context->preference('ListOwnershipUponPatronDeletion') eq 'transfer' ) {
418
        # designated owner overrides userenv
419
        my $designated_owner = C4::Context->preference('ListOwnerDesignated');
420
        return $designated_owner if Koha::Patrons->find($designated_owner);
421
        my $userenv = C4::Context->userenv;
422
        return $userenv->{'number'} if $userenv;
423
    }
424
}
419
425
420
=head3 category
426
=head3 category
421
427
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +16 lines)
Lines 460-468 subtest "move_to_deleted" => sub { Link Here
460
};
460
};
461
461
462
subtest "delete" => sub {
462
subtest "delete" => sub {
463
    plan tests => 13;
463
    plan tests => 16;
464
    t::lib::Mocks::mock_preference( 'BorrowersLog', 1 );
464
    t::lib::Mocks::mock_preference( 'BorrowersLog', 1 );
465
    t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'transfer' );
465
    t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'transfer' );
466
    t::lib::Mocks::mock_preference( 'ListOwnerDesignated', undef );
466
    Koha::Virtualshelves->delete;
467
    Koha::Virtualshelves->delete;
467
468
468
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
469
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
Lines 511-516 subtest "delete" => sub { Link Here
511
    my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'DELETE', object => $patron->borrowernumber } )->count;
512
    my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'DELETE', object => $patron->borrowernumber } )->count;
512
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' );
513
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' );
513
514
515
    # Test deletion with designated fallback owner
516
    my $designated_owner = $builder->build_object({ class => 'Koha::Patrons' });
517
    t::lib::Mocks::mock_preference( 'ListOwnerDesignated', $designated_owner->id );
518
    $patron = $builder->build_object({ class => 'Koha::Patrons' });
519
    $private_list = Koha::Virtualshelf->new({ shelfname => "PR1", owner => $patron->id })->store;
520
    $public_list = Koha::Virtualshelf->new({ shelfname => "PU1", public => 1, owner => $patron->id })->store;
521
    $list_to_share = Koha::Virtualshelf->new({ shelfname => "SH1", owner => $patron->id })->store;
522
    $list_to_share->share("valid key")->accept( "valid key", $patron_for_sharing->id );
523
    $patron->delete;
524
    is( Koha::Virtualshelves->find( $private_list->id ), undef, 'Private list gone' );
525
    is( $public_list->discard_changes->get_column('owner'), $designated_owner->id, 'Public list transferred' );
526
    is( $list_to_share->discard_changes->get_column('owner'), $designated_owner->id, 'Shared list transferred' );
527
528
    # Finally test deleting lists
514
    t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'delete' );
529
    t::lib::Mocks::mock_preference( 'ListOwnershipUponPatronDeletion', 'delete' );
515
    Koha::Virtualshelves->delete;
530
    Koha::Virtualshelves->delete;
516
    my $patron2 = $builder->build_object({ class => 'Koha::Patrons' });
531
    my $patron2 = $builder->build_object({ class => 'Koha::Patrons' });
517
- 

Return to bug 30933