#
# This file is part of Koha.
#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 3 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
#
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
=head1 NAME
=cut
-use constant KOHA_UPLOAD => 'koha_upload';
+use constant KOHA_UPLOAD => 'koha_upload';
use constant BYTES_DIGEST => 2048;
+use constant ERR_EXISTS => 'UPLERR_ALREADY_EXISTS';
+use constant ERR_PERMS => 'UPLERR_CANNOT_WRITE';
+use constant ERR_ROOT => 'UPLERR_NO_ROOT_DIR';
+use constant ERR_TEMP => 'UPLERR_NO_TEMP_DIR';
use Modern::Perl;
use CGI; # no utf8 flag, since it may interfere with binary uploads
use Digest::MD5;
use Encode;
-use File::Spec;
use IO::File;
use Time::HiRes;
=head2 err
- Returns hash with errors in format { file => err, ... }
+ Returns hashref with errors in format { file => { code => err }, ... }
Undefined if there are no errors.
=cut
my $err;
foreach my $f ( keys %{ $self->{files} } ) {
my $e = $self->{files}->{$f}->{errcode};
- $err->{ $f } = $e if $e;
+ $err->{ $f }->{code} = $e if $e;
}
return $err;
}
my ( $self, $params ) = @_;
$self->{rootdir} = Koha::UploadedFile->permanent_directory;
- $self->{tmpdir} = Koha::UploadedFile->temporary_directory;
+ $self->{tmpdir} = C4::Context::temporary_directory;
$params->{tmp} = $params->{temp} if !exists $params->{tmp};
$self->{temporary} = $params->{tmp}? 1: 0; #default false
$self->{files}->{$filename}->{errcode} ) {
#skip
} elsif( !$self->{temporary} && !$self->{rootdir} ) {
- $self->{files}->{$filename}->{errcode} = 3; #no rootdir
+ $self->{files}->{$filename}->{errcode} = ERR_ROOT; #no rootdir
} elsif( $self->{temporary} && !$self->{tmpdir} ) {
- $self->{files}->{$filename}->{errcode} = 4; #no tempdir
+ $self->{files}->{$filename}->{errcode} = ERR_TEMP; #no tempdir
} else {
my $dir = $self->_dir;
my $hashval = $self->{files}->{$filename}->{hash};
hashvalue => $hashval,
uploadcategorycode => $self->{category},
})->count ) {
- $self->{files}->{$filename}->{errcode} = 1; #already exists
+ $self->{files}->{$filename}->{errcode} = ERR_EXISTS;
return;
}
$fh->binmode;
$self->{files}->{$filename}->{fh}= $fh;
} else {
- $self->{files}->{$filename}->{errcode} = 2; #not writable
+ $self->{files}->{$filename}->{errcode} = ERR_PERMS;
}
}
return $fh;