=head1 SYNOPSIS
use Koha::Upload;
+ use Koha::UploadedFile;
use Koha::UploadedFiles;
# add an upload (see tools/upload-file.pl)
my $cgi = $upload->cgi;
# Do something with $upload->count, $upload->result or $upload->err
- # get some upload records (in staff)
+ # get some upload records (in staff) via Koha::UploadedFiles
my @uploads1 = Koha::UploadedFiles->search({ filename => $name });
my @uploads2 = Koha::UploadedFiles->search_term({ term => $term });
- # staff download
+ # staff download (via Koha::UploadedFile[s])
my $rec = Koha::UploadedFiles->find( $id );
my $fh = $rec->file_handle;
- my @hdr = Koha::Upload->httpheaders( $rec->filename );
- print Encode::encode_utf8( $input->header( @hdr ) );
+ print Encode::encode_utf8( $input->header( $rec->httpheaders ) );
while( <$fh> ) { print $_; }
$fh->close;
The module has been revised to use Koha::Object[s]; the delete method
has been moved to Koha::UploadedFile[s], as well as the get method.
-=head1 INSTANCE METHODS
-
=cut
use constant KOHA_UPLOAD => 'koha_upload';
__PACKAGE__->mk_ro_accessors( qw|| );
+=head1 INSTANCE METHODS
+
=head2 new
Returns new object based on Class::Accessor.
=head1 CLASS METHODS
-=head2 getCategories
-
- getCategories returns a list of upload category codes and names
-
-=cut
-
-sub getCategories {
- my ( $class ) = @_;
- my $cats = C4::Koha::GetAuthorisedValues('UPLOAD');
- [ map {{ code => $_->{authorised_value}, name => $_->{lib} }} @$cats ];
-}
-
-=head2 httpheaders
-
- httpheaders returns http headers for a retrievable upload
- Will be extended by report 14282
-
-=cut
-
-sub httpheaders {
- my ( $class, $name ) = @_;
- return (
- '-type' => 'application/octet-stream',
- '-attachment' => $name,
- );
-}
-
=head2 allows_add_by
allows_add_by checks if $userid has permission to add uploaded files
return $self->{_file_handle};
}
+=head3 httpheaders
+
+ httpheaders returns http headers for a retrievable upload
+ Will be extended by report 14282
+
+=cut
+
+sub httpheaders {
+ my ( $self ) = @_;
+ return (
+ '-type' => 'application/octet-stream',
+ '-attachment' => $self->filename,
+ );
+}
+
=head2 CLASS METHODS
-=head3 root_directory
+=head3 permanent_directory
=cut
return File::Spec->tmpdir;
}
+=head3 getCategories
+
+ getCategories returns a list of upload category codes and names
+
+=cut
+
+sub getCategories {
+ my ( $class ) = @_;
+ my $cats = C4::Koha::GetAuthorisedValues('UPLOAD');
+ [ map {{ code => $_->{authorised_value}, name => $_->{lib} }} @$cats ];
+}
+
=head3 _type
Returns name of corresponding DBIC resultset
use C4::Auth;
use C4::Context;
use C4::Output;
-use Koha::Upload;
use Koha::UploadedFiles;
my $input = CGI::->new;
$template->param( hash => $hash );
output_html_with_http_headers $input, $cookie, $template->output;
} else {
- my @hdr = Koha::Upload->httpheaders( $rec->filename );
- print Encode::encode_utf8( $input->header( @hdr ) );
+ print Encode::encode_utf8( $input->header( $rec->httpheaders ) );
while( <$fh> ) {
print $_;
}
use C4::Context;
use Koha::Database;
use Koha::Upload;
+use Koha::UploadedFile;
use Koha::UploadedFiles;
my $schema = Koha::Database->new->schema;
}
sub test07 { #simple test for httpheaders and getCategories
- my @hdrs = Koha::Upload->httpheaders('does_not_matter_yet');
+ my $rec = Koha::UploadedFiles->search_term({ term => 'file' })->next;
+ my @hdrs = $rec->httpheaders;
is( @hdrs == 4 && $hdrs[1] =~ /application\/octet-stream/, 1, 'Simple test for httpheaders');
my $builder = t::lib::TestBuilder->new;
$builder->build({ source => 'AuthorisedValue', value => { category => 'UPLOAD', authorised_value => 'HAVE_AT_LEAST_ONE', lib => 'Hi there' } });
- my $cat = Koha::Upload->getCategories;
+ my $cat = Koha::UploadedFile->getCategories;
is( @$cat >= 1, 1, 'getCategories returned at least one category' );
}
use C4::Auth;
use C4::Output;
-use Koha::Upload;
+use Koha::UploadedFile;
use Koha::UploadedFiles;
my $input = CGI::->new;
if ( $op eq 'new' ) {
$template->param(
mode => 'new',
- uploadcategories => Koha::Upload->getCategories,
+ uploadcategories => Koha::UploadedFile->getCategories,
);
output_html_with_http_headers $input, $cookie, $template->output;
$template->param(
mode => 'deleted',
msg => $msg,
- uploadcategories => Koha::Upload->getCategories,
+ uploadcategories => Koha::UploadedFile->getCategories,
);
output_html_with_http_headers $input, $cookie, $template->output;
$template->param(
mode => 'new',
msg => JSON::to_json( { $id => 5 } ),
- uploadcategories => Koha::Upload->getCategories,
+ uploadcategories => Koha::UploadedFile->getCategories,
);
output_html_with_http_headers $input, $cookie, $template->output;
} else {
- my @hdr = Koha::Upload->httpheaders( $rec->filename );
- print Encode::encode_utf8( $input->header(@hdr) );
+ print Encode::encode_utf8( $input->header( $rec->httpheaders ) );
while (<$fh>) {
print $_;
}