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

(-)a/Koha/Patron.pm (-8 / +14 lines)
Lines 388-403 sub delete { Link Here
388
            }
388
            }
389
389
390
            # Handle lists (virtualshelves)
390
            # Handle lists (virtualshelves)
391
            my $userenv = C4::Context->userenv;
391
            my $new_owner = _new_owner();
392
            my $usernumber = ref($userenv) eq 'HASH' ? $userenv->{'number'} : 0;
393
            my $lists = $self->virtualshelves;
392
            my $lists = $self->virtualshelves;
394
            while( my $list = $lists->next ) {
393
            while( my $list = $lists->next ) {
395
                # if staff member had a share, remove it
394
                if( $new_owner && ( $list->is_public || $list->is_shared )) {
396
                $list->remove_share( $usernumber ) if $usernumber && $list->is_private;
395
                    # if new_owner had a share, remove it
397
                if( C4::Context->preference('ListOwnershipUponPatronDeletion') eq 'transfer' &&
396
                    $list->remove_share( $new_owner ) if $list->is_private;
398
                    $usernumber && ( $list->is_public || $list->is_shared ))
397
                    $list->set({ owner => $new_owner })->store; # transfer ownership of public/shared list
399
                {
400
                    $list->set({ owner => $usernumber })->store; # transfer ownership of public/shared list
401
                } else { # delete
398
                } else { # delete
402
                    $list->delete;
399
                    $list->delete;
403
                }
400
                }
Lines 415-420 sub delete { Link Here
415
    return $self;
412
    return $self;
416
}
413
}
417
414
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
}
418
424
419
=head3 category
425
=head3 category
420
426
(-)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