Lines 19-24
use Modern::Perl;
Link Here
|
19 |
|
19 |
|
20 |
use base qw(Koha::Object); |
20 |
use base qw(Koha::Object); |
21 |
|
21 |
|
|
|
22 |
use Koha::RestrictionTypes; |
23 |
use C4::Context; |
24 |
|
22 |
=head1 NAME |
25 |
=head1 NAME |
23 |
|
26 |
|
24 |
Koha::RestrictionType - Koha RestrictionType Object class |
27 |
Koha::RestrictionType - Koha RestrictionType Object class |
Lines 27-34
Koha::RestrictionType - Koha RestrictionType Object class
Link Here
|
27 |
|
30 |
|
28 |
=head2 Class Methods |
31 |
=head2 Class Methods |
29 |
|
32 |
|
|
|
33 |
=head3 delete |
34 |
|
35 |
Overloaded delete method that does extra clean up: |
36 |
- Reset all restrictions using the restriction type about to be deleted |
37 |
back to whichever restriction is marked as default |
38 |
|
30 |
=cut |
39 |
=cut |
31 |
|
40 |
|
|
|
41 |
sub delete { |
42 |
my ( $self ) = @_; |
43 |
|
44 |
# Find out what the default is |
45 |
my $default = Koha::RestrictionTypes->find({ dflt => 1 })->code; |
46 |
# Ensure we're not trying to delete a readonly type (this includes |
47 |
# the default type) |
48 |
return 0 if $self->ronly == 1; |
49 |
# We can't use Koha objects here because Koha::Patron::Debarments |
50 |
# is not a Koha object. So we'll do it old skool |
51 |
my $rows = C4::Context->dbh->do( |
52 |
"UPDATE borrower_debarments SET type = ? WHERE type = ?", |
53 |
undef, |
54 |
($default, $self->code) |
55 |
); |
56 |
|
57 |
# Now do the delete if the update was successful |
58 |
if ($rows) { |
59 |
my $deleted = $self->SUPER::delete($self); |
60 |
return $deleted |
61 |
} |
62 |
|
63 |
return 0; |
64 |
} |
65 |
|
32 |
=head2 Internal methods |
66 |
=head2 Internal methods |
33 |
|
67 |
|
34 |
=head3 type |
68 |
=head3 type |