1 package Koha::IllbatchStatus;
3 # Copyright PTFS Europe 2022
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Koha::Illrequest::Logger;
24 use JSON qw( to_json );
25 use base qw(Koha::Object);
29 Koha::IllbatchStatus - Koha IllbatchStatus Object class
35 $status->create_and_log;
37 Log batch status creation following storage
44 # Ensure code is uppercase and contains only word characters
45 my $fixed_code = uc $self->code;
46 $fixed_code =~ s/\W/_/;
48 # Ensure this status doesn't already exist
49 my $status = Koha::IllbatchStatuses->find( { code => $fixed_code } );
51 return { error => "Duplicate status found" };
54 # Ensure system statuses can't be created
62 my $logger = Koha::Illrequest::Logger->new;
64 $logger->log_something(
67 actionname => 'batch_status_create',
68 objectnumber => $self->id,
69 infos => to_json( {} )
76 $status->update_and_log;
78 Log batch status update following storage
83 my ( $self, $params ) = @_;
85 my $before = { name => $self->name };
87 # Ensure only the name can be changed
88 $self->set( { name => $params->{name} } );
89 my $update = $self->store;
91 my $after = { name => $self->name };
93 my $logger = Koha::Illrequest::Logger->new;
95 $logger->log_something(
98 actionname => 'batch_status_update',
99 objectnumber => $self->id,
110 =head3 delete_and_log
112 $batch->delete_and_log;
114 Log batch status delete
121 # Don't permit deletion of system statuses
122 if ( $self->is_system ) {
126 # Update all batches that use this status to have status UNKNOWN
127 my $affected = Koha::Illbatches->search( { statuscode => $self->code } );
128 $affected->update( { statuscode => 'UNKNOWN' } );
130 my $logger = Koha::Illrequest::Logger->new;
132 $logger->log_something(
135 actionname => 'batch_status_delete',
136 objectnumber => $self->id,
137 infos => to_json( {} )
144 =head2 Internal methods
148 my $type = Koha::IllbatchStatus->_type;
150 Return this object's type
155 return 'IllbatchStatus';
160 Andrew Isherwood <andrew.isherwood@ptfs-europe.com>