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

(-)a/Koha/Patron.pm (-3 / +2 lines)
Lines 357-363 other lists are kept. Link Here
357
sub delete {
357
sub delete {
358
    my ($self) = @_;
358
    my ($self) = @_;
359
359
360
    my $deleted;
361
    $self->_result->result_source->schema->txn_do(
360
    $self->_result->result_source->schema->txn_do(
362
        sub {
361
        sub {
363
            # Cancel Patron's holds
362
            # Cancel Patron's holds
Lines 382-393 sub delete { Link Here
382
            # FIXME Could be $patron->get_lists
381
            # FIXME Could be $patron->get_lists
383
            $_->delete for Koha::Virtualshelves->search( { owner => $self->borrowernumber } );
382
            $_->delete for Koha::Virtualshelves->search( { owner => $self->borrowernumber } );
384
383
385
            $deleted = $self->SUPER::delete;
384
            $self->SUPER::delete;
386
385
387
            logaction( "MEMBERS", "DELETE", $self->borrowernumber, "" ) if C4::Context->preference("BorrowersLog");
386
            logaction( "MEMBERS", "DELETE", $self->borrowernumber, "" ) if C4::Context->preference("BorrowersLog");
388
        }
387
        }
389
    );
388
    );
390
    return $deleted;
389
    return $self;
391
}
390
}
392
391
393
392
(-)a/Koha/REST/V1/Patrons.pm (-1 / +1 lines)
Lines 276-282 sub delete { Link Here
276
        $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
276
        $patron = Koha::Patrons->find( $c->validation->param('patron_id') );
277
277
278
        # check if loans, reservations, debarrment, etc. before deletion!
278
        # check if loans, reservations, debarrment, etc. before deletion!
279
        my $res = $patron->delete;
279
        $patron->delete;
280
        return $c->render( status => 200, openapi => {} );
280
        return $c->render( status => 200, openapi => {} );
281
    }
281
    }
282
    catch {
282
    catch {
(-)a/t/db_dependent/Koha/Patrons.t (-16 / +8 lines)
Lines 36-41 use Koha::ActionLogs; Link Here
36
use Koha::Holds;
36
use Koha::Holds;
37
use Koha::Old::Holds;
37
use Koha::Old::Holds;
38
use Koha::Patrons;
38
use Koha::Patrons;
39
use Koha::Old::Patrons;
39
use Koha::Patron::Categories;
40
use Koha::Patron::Categories;
40
use Koha::Patron::Relationship;
41
use Koha::Patron::Relationship;
41
use Koha::Database;
42
use Koha::Database;
Lines 479-485 subtest "delete" => sub { Link Here
479
    );
480
    );
480
481
481
    my $deleted = $retrieved_patron->delete;
482
    my $deleted = $retrieved_patron->delete;
482
    is( $deleted, 1, 'Koha::Patron->delete should return 1 if the patron has been correctly deleted' );
483
    is( ref($deleted), 'Koha::Patron', 'Koha::Patron->delete should return the deleted patron object if the patron has been correctly deleted' );
483
484
484
    is( Koha::Patrons->find( $patron->{borrowernumber} ), undef, 'Koha::Patron->delete should have deleted the patron' );
485
    is( Koha::Patrons->find( $patron->{borrowernumber} ), undef, 'Koha::Patron->delete should have deleted the patron' );
485
486
Lines 494-520 subtest "delete" => sub { Link Here
494
};
495
};
495
496
496
subtest 'Koha::Patrons->delete' => sub {
497
subtest 'Koha::Patrons->delete' => sub {
497
    plan tests => 4;
498
    plan tests => 3;
498
499
    my $mod_patron = Test::MockModule->new( 'Koha::Patron' );
500
    my $moved_to_deleted = 0;
501
    $mod_patron->mock( 'move_to_deleted', sub { $moved_to_deleted++; } );
502
499
503
    my $patron1 = $builder->build_object({ class => 'Koha::Patrons' });
500
    my $patron1 = $builder->build_object({ class => 'Koha::Patrons' });
504
    my $patron2 = $builder->build_object({ class => 'Koha::Patrons' });
501
    my $patron2 = $builder->build_object({ class => 'Koha::Patrons' });
505
    my $id1 = $patron1->borrowernumber;
502
    my $id1 = $patron1->borrowernumber;
506
    my $set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }});
503
    my $set = Koha::Patrons->search({ borrowernumber => { -in => [$patron1->borrowernumber, $patron2->borrowernumber]}});
507
    is( $set->count, 2, 'Two patrons found as expected' );
504
    is( $set->count, 2, 'Two patrons found as expected' );
508
    is( $set->delete({ move => 1 }), 2, 'Two patrons deleted' );
505
    is( $set->delete({ move => 1 }), 2, 'Two patrons deleted' );
509
    is( $moved_to_deleted, 2, 'Patrons moved to deletedborrowers' );
506
    my $deleted_patrons = Koha::Old::Patrons->search({ borrowernumber => { -in => [$patron1->borrowernumber, $patron2->borrowernumber]}});
510
507
    is( $deleted_patrons->count, 2, 'Patrons moved to deletedborrowers' );
511
    # Add again, test if we can raise an exception
508
512
    $mod_patron->mock( 'delete', sub { return -1; } );
509
    # See other tests in t/db_dependent/Koha/Objects.t
513
    $patron1 = $builder->build_object({ class => 'Koha::Patrons' });
514
    $id1 = $patron1->borrowernumber;
515
    $set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }});
516
    throws_ok { $set->delete } 'Koha::Exceptions::Patron::FailedDelete',
517
        'Exception raised for deleting patron';
518
};
510
};
519
511
520
subtest 'add_enrolment_fee_if_needed' => sub {
512
subtest 'add_enrolment_fee_if_needed' => sub {
(-)a/t/db_dependent/Virtualshelves.t (-3 / +2 lines)
Lines 84-90 subtest 'CRUD' => sub { Link Here
84
    is( $number_of_shelves, 2, 'Another patron should be able to create a shelf with an existing shelfname');
84
    is( $number_of_shelves, 2, 'Another patron should be able to create a shelf with an existing shelfname');
85
85
86
    my $is_deleted = Koha::Virtualshelves->find( $shelf->shelfnumber )->delete;
86
    my $is_deleted = Koha::Virtualshelves->find( $shelf->shelfnumber )->delete;
87
    is( $is_deleted, 1, 'The shelf has been deleted correctly' );
87
    ok( $is_deleted, 'The shelf has been deleted correctly' );
88
    $number_of_shelves = Koha::Virtualshelves->search->count;
88
    $number_of_shelves = Koha::Virtualshelves->search->count;
89
    is( $number_of_shelves, 1, 'To be sure the shelf has been deleted' );
89
    is( $number_of_shelves, 1, 'To be sure the shelf has been deleted' );
90
90
Lines 162-168 subtest 'Sharing' => sub { Link Here
162
    is( Koha::Virtualshelfshares->search->count, 2, 'Check that number of shares went down again' );
162
    is( Koha::Virtualshelfshares->search->count, 2, 'Check that number of shares went down again' );
163
163
164
    # Remove the first accept
164
    # Remove the first accept
165
    is( $shelf_to_share->remove_share( $share_with_me->{borrowernumber} ), 1, '1 share should have been removed if the shelf was shared with this patron' );
165
    ok( $shelf_to_share->remove_share( $share_with_me->{borrowernumber} ), '1 share should have been removed if the shelf was shared with this patron' );
166
    $number_of_shelves_shared = Koha::Virtualshelfshares->search->count;
166
    $number_of_shelves_shared = Koha::Virtualshelfshares->search->count;
167
    is( $number_of_shelves_shared, 1, 'To be sure the share has been removed' );
167
    is( $number_of_shelves_shared, 1, 'To be sure the share has been removed' );
168
168
169
- 

Return to bug 21684