Bug 26265: (QA follow-up) Remove g option from regex, add few dirs
[koha-equinox.git] / opac / opac-retrieve-file.pl
index b443a7c..d19f9dd 100755 (executable)
@@ -24,14 +24,17 @@ use Encode;
 use C4::Auth;
 use C4::Context;
 use C4::Output;
-use Koha::Upload;
+use Koha::UploadedFiles;
 
 my $input = CGI::->new;
 my $hash = $input->param('id'); # historically called id (used in URLs?)
 
-my $upl = Koha::Upload->new({ public => 1 });
-my $rec = $upl->get({ hashvalue => $hash, filehandle => 1 });
-my $fh = $rec->{fh};
+my $rec = Koha::UploadedFiles->search({
+    hashvalue => $hash, public => 1,
+    # DO NOT REMOVE the public flag: this is an opac script !
+})->next;
+my $fh = $rec? $rec->file_handle: undef;
+
 if( !$rec || !$fh ) {
     my ( $template, $user, $cookie ) = get_template_and_user({
         query           => $input,
@@ -42,8 +45,7 @@ if( !$rec || !$fh ) {
     $template->param( hash => $hash );
     output_html_with_http_headers $input, $cookie, $template->output;
 } else {
-    my @hdr = $upl->httpheaders( $rec->{name} );
-    print Encode::encode_utf8( $input->header( @hdr ) );
+    print Encode::encode_utf8( $input->header( $rec->httpheaders ) );
     while( <$fh> ) {
         print $_;
     }