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

(-)a/Koha/ItemTypes.pm (-17 lines)
Lines 39-61 Koha::ItemTypes - Koha ItemType Object set class Link Here
39
39
40
=cut
40
=cut
41
41
42
sub check_items_and_biblioitems {
43
    my ($itemtype_code) = @_;
44
45
    my $dbh = C4::Context->dbh;
46
47
    # Check both items and biblioitems
48
    my ($total) = $dbh->selectrow_array( '
49
        SELECT COUNT(*) AS total FROM (
50
        SELECT itemtype AS t FROM biblioitems
51
            UNION ALL
52
           SELECT itype AS t FROM items
53
        ) AS tmp
54
        WHERE tmp.t=?
55
        ', {}, $itemtype_code );
56
    return $total;
57
}
58
59
sub _type {
42
sub _type {
60
    return 'Itemtype';
43
    return 'Itemtype';
61
}
44
}
(-)a/admin/itemtypes.pl (-5 / +13 lines)
Lines 137-148 if ( $op eq 'add_form' ) { Link Here
137
137
138
    $searchfield = '';
138
    $searchfield = '';
139
    $op          = 'list';
139
    $op          = 'list';
140
} elsif ( $op eq 'delete_confirm' ) {
141
140
142
    my $total = Koha::ItemTypes->check_items_and_biblioitems($itemtype_code);
141
 } elsif ( $op eq 'delete_confirm' ) {
143
142
144
    if ($total) {
143
    my $context = C4::Context->new;
145
        push @messages, { type => 'error', code => 'cannot_be_deleted', total => $total };
144
    my $schema = Koha::Database->new()->schema();
145
    my $itemtotal = $schema->resultset('Item')->search({ 'itype' => $itemtype_code} );
146
    my $bibliototal = $schema->resultset('Biblioitem')->search({ 'itemtype' => $itemtype_code} );
147
148
    $itemtotal->count;
149
    $bibliototal->count;
150
    my $overalltotal = $itemtotal + $bibliototal;
151
152
    if ($overalltotal) {
153
        push @messages, { type => 'error', code => 'cannot_be_deleted', total => $overalltotal };
146
        $op = 'list';
154
        $op = 'list';
147
    } else {
155
    } else {
148
        my $itemtype = Koha::ItemTypes->find($itemtype_code);
156
        my $itemtype = Koha::ItemTypes->find($itemtype_code);
Lines 150-155 if ( $op eq 'add_form' ) { Link Here
150
    }
158
    }
151
159
152
} elsif ( $op eq 'delete_confirmed' ) {
160
} elsif ( $op eq 'delete_confirmed' ) {
161
153
    my $itemtype = Koha::ItemTypes->find($itemtype_code);
162
    my $itemtype = Koha::ItemTypes->find($itemtype_code);
154
    my $deleted = eval { $itemtype->delete };
163
    my $deleted = eval { $itemtype->delete };
155
    if ( $@ or not $deleted ) {
164
    if ( $@ or not $deleted ) {
156
- 

Return to bug 17944