1 package Koha::RestrictionType;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use base qw(Koha::Object);
22 use Koha::RestrictionTypes;
27 Koha::RestrictionType - Koha RestrictionType Object class
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
44 # Find out what the default is
45 my $default = Koha::RestrictionTypes->find({ is_default => 1 })->code;
46 # Ensure we're not trying to delete a is_system type (this includes
48 return 0 if $self->is_system == 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 = ?",
54 ($default, $self->code)
57 # Now do the delete if the update was successful
59 my $deleted = $self->SUPER::delete($self);
68 Set the current restriction type as the default for manual restrictions
75 $self->_result->result_source->schema->txn_do(
78 Koha::RestrictionTypes->search( { code => { '!=' => $self->code } } );
79 $types->update( { is_default => 0 } );
80 $self->set( { is_default => 1 } );
88 =head2 Internal methods
95 return 'RestrictionType';