Bug 25232: DBRev 20.06.00.002
[koha-ffzg.git] / Koha / UploadedFile.pm
index 160c2d3..83c7ab7 100644 (file)
@@ -4,18 +4,18 @@ package Koha::UploadedFile;
 #
 # 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>.
 
 use Modern::Perl;
 use File::Spec;
@@ -61,7 +61,10 @@ Delete uploaded file.
 It deletes not only the record, but also the actual file (unless you pass
 the keep_file parameter).
 
-Returns filename on successful delete or undef.
+Returns number of deleted records (1 or 0E0), or -1 for unknown.
+Please keep in mind that a deleted record does not automatically imply a
+deleted file; a warning may have been raised.
+(TODO: Use exceptions.)
 
 =cut
 
@@ -78,7 +81,6 @@ sub delete {
         warn "Removing record for $name within category ".
             $self->uploadcategorycode. ", but file was missing.";
     } elsif( ! unlink($file) ) {
-        $retval = 0;
         warn "Problem while deleting: $file";
     }
     return $retval;
@@ -93,8 +95,9 @@ Returns the fully qualified path name for an uploaded file.
 sub full_path {
     my ( $self ) = @_;
     my $path = File::Spec->catfile(
-        $self->permanent?
-            $self->permanent_directory: $self->temporary_directory,
+        $self->permanent
+            ? $self->permanent_directory
+            : C4::Context->temporary_directory,
         $self->dir,
         $self->hashvalue. '_'. $self->filename,
     );
@@ -125,10 +128,17 @@ Will be extended by report 14282
 
 sub httpheaders {
     my ( $self ) = @_;
-    return (
-        '-type'       => 'application/octet-stream',
-        '-attachment' => $self->filename,
-    );
+    if( $self->filename =~ /\.pdf$/ ) {
+        return (
+            '-type'       => 'application/pdf',
+            'Content-Disposition' => 'inline; filename='.$self->filename,
+        );
+    } else {
+        return (
+            '-type'       => 'application/octet-stream',
+            '-attachment' => $self->filename,
+        );
+    }
 }
 
 =head2 CLASS METHODS
@@ -144,17 +154,6 @@ sub permanent_directory {
     return C4::Context->config('upload_path');
 }
 
-=head3 tmp_directory
-
-Returns root directory for temporary storage
-
-=cut
-
-sub temporary_directory {
-    my ( $class ) = @_;
-    return File::Spec->tmpdir;
-}
-
 =head3 _type
 
 Returns name of corresponding DBIC resultset