1 package Koha::Patron::Restriction::Type;
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);
24 use Koha::Patron::Restriction::Types;
29 Koha::Patron::Restriction::Type - Koha RestrictionType Object class
37 Overloaded delete method that does extra clean up:
38 - Reset all restrictions using the restriction type about to be deleted
39 back to whichever restriction is marked as default
46 # Ensure we can't delete the current default
47 Koha::Exceptions::CannotDeleteDefault->throw if $self->is_default;
49 # Ensure we can't delete system values
50 Koha::Exceptions::CannotDeleteSystem->throw if $self->is_system;
52 return $self->_result->result_source->schema->txn_do(
54 # Update all linked restrictions to the default
56 Koha::Patron::Restriction::Types->find( { is_default => 1 } )->code;
58 # We can't use Koha objects here because Koha::Patron::Debarments
59 # is not a Koha object. So we'll do it old skool
60 my $rows = C4::Context->dbh->do(
61 "UPDATE borrower_debarments SET type = ? WHERE type = ?",
62 undef, ( $default, $self->code ) );
64 return $self->SUPER::delete;
71 Set the current restriction type as the default for manual restrictions
78 $self->_result->result_source->schema->txn_do(
81 Koha::Patron::Restriction::Types->search( { code => { '!=' => $self->code } } );
82 $types->update( { is_default => 0 } );
83 $self->set( { is_default => 1 } );
91 =head2 Internal methods
98 return 'RestrictionType';