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

(-)a/Koha/Items.pm (-2 / +9 lines)
Lines 61-70 which will be rolled back if an exception is raised. Link Here
61
sub safe_delete {
61
sub safe_delete {
62
    my ($self) = @_;
62
    my ($self) = @_;
63
63
64
    my $items_deleted;
65
64
    try {
66
    try {
65
        $self->_resultset->result_source->schema->txn_do(
67
        $self->_resultset->result_source->schema->txn_do(
66
            sub {
68
            sub {
67
                while ( my $item = $self->next ) {
69
                while ( my $item = $self->next ) {
70
71
                    next unless $item->in_storage;
72
68
                    my $result = $item->safe_delete;
73
                    my $result = $item->safe_delete;
69
                    # FIXME: $item->safe_delete has a weird set of return value options:
74
                    # FIXME: $item->safe_delete has a weird set of return value options:
70
                    # - a string representing the blocking condition
75
                    # - a string representing the blocking condition
Lines 75-89 sub safe_delete { Link Here
75
                            reason => $result
80
                            reason => $result
76
                        );
81
                        );
77
                    }
82
                    }
83
84
                    $items_deleted++;
78
                }
85
                }
79
            }
86
            }
80
        );
87
        );
81
82
        return;
83
    }
88
    }
84
    catch {
89
    catch {
85
        $_->rethrow;
90
        $_->rethrow;
86
    };
91
    };
92
93
    return $items_deleted;
87
}
94
}
88
95
89
96
(-)a/t/db_dependent/Koha/Items.t (-2 / +1 lines)
Lines 990-996 subtest 'safe_delete() tests' => sub { Link Here
990
    C4::Circulation::AddReturn( $item_1->barcode );
990
    C4::Circulation::AddReturn( $item_1->barcode );
991
991
992
    my $result = $items_rs->safe_delete;
992
    my $result = $items_rs->safe_delete;
993
    is( $result, undef, 'Successful call returns undef' );
993
    is( $result, 2, 'Successful call returns the number of deleted items' );
994
    $items_rs = Koha::Items->search({ itemnumber => { -in => [ $item_1_id, $item_2_id ] } });
994
    $items_rs = Koha::Items->search({ itemnumber => { -in => [ $item_1_id, $item_2_id ] } });
995
    is( $items_rs->count, 0, 'Successful safe delete, items are not ' );
995
    is( $items_rs->count, 0, 'Successful safe delete, items are not ' );
996
996
997
- 

Return to bug 26509