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

(-)a/Koha/Patron.pm (-3 / +4 lines)
Lines 543-548 sub siblings { Link Here
543
sub merge_with {
543
sub merge_with {
544
    my ( $self, $patron_ids ) = @_;
544
    my ( $self, $patron_ids ) = @_;
545
545
546
    my $anonymous_patron = C4::Context->preference("AnonymousPatron");
547
    return if $anonymous_patron && $self->id eq $anonymous_patron;
548
546
    my @patron_ids = @{ $patron_ids };
549
    my @patron_ids = @{ $patron_ids };
547
550
548
    # Ensure the keeper isn't in the list of patrons to merge
551
    # Ensure the keeper isn't in the list of patrons to merge
Lines 555-563 sub merge_with { Link Here
555
    $self->_result->result_source->schema->txn_do( sub {
558
    $self->_result->result_source->schema->txn_do( sub {
556
        foreach my $patron_id (@patron_ids) {
559
        foreach my $patron_id (@patron_ids) {
557
560
558
            if ( my $anonymous_patron = C4::Context->preference("AnonymousPatron") ) {
561
            next if $patron_id eq $anonymous_patron;
559
                next if $patron_id eq $anonymous_patron;
560
            }
561
562
562
            my $patron = Koha::Patrons->find( $patron_id );
563
            my $patron = Koha::Patrons->find( $patron_id );
563
564
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +6 lines)
Lines 1683-1689 subtest 'BorrowersLog tests' => sub { Link Here
1683
$schema->storage->txn_rollback;
1683
$schema->storage->txn_rollback;
1684
1684
1685
subtest 'Test Koha::Patrons::merge' => sub {
1685
subtest 'Test Koha::Patrons::merge' => sub {
1686
    plan tests => 111;
1686
    plan tests => 113;
1687
1687
1688
    my $schema = Koha::Database->new()->schema();
1688
    my $schema = Koha::Database->new()->schema();
1689
1689
Lines 1729-1734 subtest 'Test Koha::Patrons::merge' => sub { Link Here
1729
    is( Koha::Patrons->find($loser_2), undef, 'Loser 2 has been deleted' );
1729
    is( Koha::Patrons->find($loser_2), undef, 'Loser 2 has been deleted' );
1730
    is( ref Koha::Patrons->find($anonymous_patron), 'Koha::Patron', 'Anonymous Patron was not deleted' );
1730
    is( ref Koha::Patrons->find($anonymous_patron), 'Koha::Patron', 'Anonymous Patron was not deleted' );
1731
1731
1732
    $anonymous_patron = Koha::Patrons->find($anonymous_patron);
1733
    $results = $anonymous_patron->merge_with( [ $keeper->id ] );
1734
    is( $results, undef, "Anonymous patron cannot have other patrons merged into it" );
1735
    is( Koha::Patrons->search( { borrowernumber => $keeper->id } )->count, 1, "Patron from attempted merge with AnonymousPatron still exists" );
1736
1732
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
1737
    t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
1733
    $schema->storage->txn_rollback;
1738
    $schema->storage->txn_rollback;
1734
};
1739
};
1735
- 

Return to bug 14708