1 package Koha
::UploadedFile
;
3 # Copyright Rijksmuseum 2016
5 # This file is part of Koha.
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
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.
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.
25 use parent
qw(Koha::Object);
29 Koha::UploadedFile - Koha::Object class for single uploaded file
33 use Koha::UploadedFile;
41 =head2 INSTANCE METHODS
46 It deletes not only the record, but also the actual file (unless you pass
47 the keep_file parameter).
49 Returns filename on successful delete or undef.
54 my ( $self, $params ) = @_;
56 my $name = $self->filename;
57 my $file = $self->full_path;
59 if( $params->{keep_file
} ) {
60 return $name if $self->SUPER::delete;
61 } elsif( !-e
$file ) { # we will just delete the record
62 warn "Removing record for $name within category ".
63 $self->uploadcategorycode. ", but file was missing.";
64 return $name if $self->SUPER::delete;
65 } elsif( unlink($file) ) {
66 return $name if $self->SUPER::delete;
68 warn "Problem while deleting: $file";
70 return; # something went wrong
75 Returns the fully qualified path name for an uploaded file.
81 my $path = File
::Spec
->catfile(
83 $self->permanent_directory: $self->temporary_directory,
85 $self->hashvalue. '_'. $self->filename,
92 Returns a file handle for an uploaded file.
98 $self->{_file_handle
} = IO
::File
->new( $self->full_path, "r" );
99 return if !$self->{_file_handle
};
100 $self->{_file_handle
}->binmode;
101 return $self->{_file_handle
};
106 httpheaders returns http headers for a retrievable upload
107 Will be extended by report 14282
114 '-type' => 'application/octet-stream',
115 '-attachment' => $self->filename,
121 =head3 permanent_directory
125 sub permanent_directory
{
127 return C4
::Context
->config('upload_path');
134 sub temporary_directory
{
136 return File
::Spec
->tmpdir;
141 getCategories returns a list of upload category codes and names
147 my $cats = C4
::Koha
::GetAuthorisedValues
('UPLOAD');
148 [ map {{ code
=> $_->{authorised_value
}, name
=> $_->{lib
} }} @
$cats ];
153 Returns name of corresponding DBIC resultset
158 return 'UploadedFile';
163 Marcel de Rooy (Rijksmuseum)
165 Koha Development Team