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.
48 Returns filename on successful delete or undef.
55 my $name = $self->filename;
56 my $file = $self->full_path;
58 if( !-e
$file ) { # we will just delete the record
59 warn "Removing record for $name within category ".
60 $self->uploadcategorycode. ", but file was missing.";
61 return $name if $self->SUPER::delete;
62 } elsif( unlink($file) ) {
63 return $name if $self->SUPER::delete;
65 warn "Problem while deleting: $file";
67 return; # something went wrong
72 Returns the fully qualified path name for an uploaded file.
78 my $path = File
::Spec
->catfile(
80 $self->permanent_directory: $self->temporary_directory,
82 $self->hashvalue. '_'. $self->filename,
93 sub permanent_directory
{
95 return C4
::Context
->config('upload_path');
102 sub temporary_directory
{
104 return File
::Spec
->tmpdir;
109 Returns name of corresponding DBIC resultset
114 return 'UploadedFile';
119 Marcel de Rooy (Rijksmuseum)
121 Koha Development Team