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

(-)a/Koha/RestrictionType.pm (+34 lines)
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
(-)a/Koha/RestrictionTypes.pm (-6 / +3 lines)
Lines 36-42 Koha::RestrictionTypes - Koha Restriction Types Object set class Link Here
36
36
37
=cut
37
=cut
38
38
39
=head3 type
39
=head3 keyed_on_code
40
40
41
Return all restriction types as a hashref keyed on the code
41
Return all restriction types as a hashref keyed on the code
42
42
Lines 54-60 sub keyed_on_code { Link Here
54
    return $out;
54
    return $out;
55
}
55
}
56
56
57
=head3 type
57
=head3 _type
58
58
59
=cut
59
=cut
60
60
Lines 62-70 sub _type { Link Here
62
    return 'DebarmentType';
62
    return 'DebarmentType';
63
}
63
}
64
64
65
=head3 type
65
=head3 object_class
66
67
Object class
68
66
69
=cut
67
=cut
70
68
71
- 

Return to bug 23681