Bug 26180: Add descending option to rebuild_elasticsearch.pl
[koha-ffzg.git] / Koha / Uploader.pm
index 7a02d11..4cd6aaf 100644 (file)
@@ -6,18 +6,18 @@ package Koha::Uploader;
 #
 # 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
 
@@ -58,8 +58,12 @@ Koha::Uploader - Facilitate file uploads (temporary and permanent)
 
 =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
@@ -143,7 +147,7 @@ sub result {
 
 =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
@@ -189,7 +193,7 @@ sub _init {
     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
@@ -220,9 +224,9 @@ sub _create_file {
             $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};
@@ -235,7 +239,7 @@ sub _create_file {
             hashvalue          => $hashval,
             uploadcategorycode => $self->{category},
         })->count ) {
-            $self->{files}->{$filename}->{errcode} = 1; #already exists
+            $self->{files}->{$filename}->{errcode} = ERR_EXISTS;
             return;
         }
 
@@ -244,7 +248,7 @@ sub _create_file {
             $fh->binmode;
             $self->{files}->{$filename}->{fh}= $fh;
         } else {
-            $self->{files}->{$filename}->{errcode} = 2; #not writable
+            $self->{files}->{$filename}->{errcode} = ERR_PERMS;
         }
     }
     return $fh;