Bug 17501: Move Koha::Upload::delete to Koha::UploadedFile[s]
[koha.git] / Koha / UploadedFiles.pm
1 package Koha::UploadedFiles;
2
3 # Copyright Rijksmuseum 2016
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21
22 #use Koha::Database;
23 use Koha::UploadedFile;
24
25 use parent qw(Koha::Objects);
26
27 =head1 NAME
28
29 Koha::UploadedFiles - Koha::Objects class for uploaded files
30
31 =head1 SYNOPSIS
32
33 use Koha::UploadedFiles;
34
35 =head1 DESCRIPTION
36
37 Description
38
39 =head1 METHODS
40
41 =head2 INSTANCE METHODS
42
43 =head3 delete, delete_errors
44
45 Delete uploaded files.
46 Returns true if no errors occur.
47 Delete_errors returns the number of errors when deleting files.
48
49 =cut
50
51 sub delete {
52     my ( $self ) = @_;
53     # We use the individual delete on each resultset record
54     my $err = 0;
55     while( my $row = $self->_resultset->next ) {
56         my $kohaobj = Koha::UploadedFile->_new_from_dbic( $row );
57         $err++ if !$kohaobj->delete;
58     }
59     $self->{delete_errors} = $err;
60     return $err==0;
61 }
62
63 sub delete_errors {
64     my ( $self ) = @_;
65     return $self->{delete_errors};
66 }
67
68 =head2 CLASS METHODS
69
70 =head3 _type
71
72 Returns name of corresponding DBIC resultset
73
74 =cut
75
76 sub _type {
77     return 'UploadedFile';
78 }
79
80 =head3 object_class
81
82 Returns name of corresponding Koha object class
83
84 =cut
85
86 sub object_class {
87     return 'Koha::UploadedFile';
88 }
89
90 =head1 AUTHOR
91
92 Marcel de Rooy (Rijksmuseum)
93
94 Koha Development Team
95
96 =cut
97
98 1;