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

(-)a/Koha/ItemTypes.pm (-17 lines)
Lines 62-84 sub search_with_localization { Link Here
62
62
63
=cut
63
=cut
64
64
65
sub check_items_and_biblioitems {
66
    my ($itemtype_code) = @_;
67
68
    my $dbh = C4::Context->dbh;
69
70
    # Check both items and biblioitems
71
    my ($total) = $dbh->selectrow_array( '
72
        SELECT COUNT(*) AS total FROM (
73
        SELECT itemtype AS t FROM biblioitems
74
            UNION ALL
75
           SELECT itype AS t FROM items
76
        ) AS tmp
77
        WHERE tmp.t=?
78
        ', {}, $itemtype_code );
79
    return $total;
80
}
81
82
sub _type {
65
sub _type {
83
    return 'Itemtype';
66
    return 'Itemtype';
84
}
67
}
(-)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