1 package Koha::Preservation::Train;
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 JSON qw( to_json );
25 use base qw(Koha::Object);
27 use Koha::Preservation::Processings;
28 use Koha::Preservation::Train::Items;
30 use Koha::Exceptions::Preservation;
34 Koha::Preservation::Train - Koha Train Object class
42 =head3 default_processing
44 Return the default processing object for this train
48 sub default_processing {
50 my $rs = $self->_result->default_processing;
52 return Koha::Preservation::Processing->_new_from_dbic($rs);
57 Add item to this train
59 my $train_item = $train->add_item({item_id => $itemnumber, processing_id => $processing_id});
60 my $train_item = $train->add_item({barcode => $barcode, processing_id => $processing_id});
65 my ( $self, $train_item ) = @_;
67 my $not_for_loan = C4::Context->preference('PreservationNotForLoanWaitingListIn');
69 my $key = exists $train_item->{item_id} ? 'itemnumber' : 'barcode';
70 my $item = Koha::Items->find( { $key => $train_item->{item_id} || $train_item->{barcode} } );
71 Koha::Exceptions::Preservation::ItemNotFound->throw unless $item;
72 Koha::Exceptions::Preservation::ItemNotInWaitingList->throw if $item->notforloan != $not_for_loan;
74 my $train_item_rs = $self->_result->add_to_preservation_trains_items(
76 item_id => $item->itemnumber,
77 processing_id => $train_item->{processing_id} || $self->default_processing_id,
81 $item->notforloan( $self->not_for_loan )->store;
82 return Koha::Preservation::Train::Item->_new_from_dbic($train_item_rs);
87 my $train_items = $train->add_items([$item_1, $item_2]);
94 my ( $self, $train_items ) = @_;
96 for my $train_item (@$train_items) {
98 push @added_items, $self->add_item($train_item);
101 # FIXME Do we rollback and raise an error or just skip it?
102 # FIXME See status code 207 partial success
103 warn "Item not added to train: " . $_;
106 return Koha::Preservation::Train::Items->search( { train_item_id => [ map { $_->train_item_id } @added_items ] } );
111 my $items = $train->items;
113 Return the items in this train.
119 my $items_rs = $self->_result->preservation_trains_items;
120 return Koha::Preservation::Train::Items->_new_from_dbic($items_rs)
123 =head2 Internal methods
130 return 'PreservationTrain';