Lines 76-81
use base qw(Class::Accessor);
Link Here
|
76 |
use C4::Context; |
76 |
use C4::Context; |
77 |
use C4::Koha; |
77 |
use C4::Koha; |
78 |
use Koha::UploadedFile; |
78 |
use Koha::UploadedFile; |
|
|
79 |
use Koha::UploadedFiles; |
79 |
|
80 |
|
80 |
__PACKAGE__->mk_ro_accessors( qw|| ); |
81 |
__PACKAGE__->mk_ro_accessors( qw|| ); |
81 |
|
82 |
|
Lines 306-318
sub _create_file {
Link Here
|
306 |
$self->{files}->{$filename}->{errcode} = 4; #no tempdir |
307 |
$self->{files}->{$filename}->{errcode} = 4; #no tempdir |
307 |
} else { |
308 |
} else { |
308 |
my $dir = $self->_dir; |
309 |
my $dir = $self->_dir; |
309 |
my $fn = $self->{files}->{$filename}->{hash}. '_'. $filename; |
310 |
my $hashval = $self->{files}->{$filename}->{hash}; |
310 |
if( -e "$dir/$fn" && @{ $self->_lookup({ |
311 |
my $fn = $hashval. '_'. $filename; |
311 |
hashvalue => $self->{files}->{$filename}->{hash} }) } ) { |
312 |
|
312 |
# if the file exists and it is registered, then set error |
313 |
# if the file exists and it is registered, then set error |
|
|
314 |
# if it exists, but is not in the database, we will overwrite |
315 |
if( -e "$dir/$fn" && |
316 |
Koha::UploadedFiles->search({ |
317 |
hashvalue => $hashval, |
318 |
uploadcategorycode => $self->{category}, |
319 |
})->count ) { |
313 |
$self->{files}->{$filename}->{errcode} = 1; #already exists |
320 |
$self->{files}->{$filename}->{errcode} = 1; #already exists |
314 |
return; |
321 |
return; |
315 |
} |
322 |
} |
|
|
323 |
|
316 |
$fh = IO::File->new( "$dir/$fn", "w"); |
324 |
$fh = IO::File->new( "$dir/$fn", "w"); |
317 |
if( $fh ) { |
325 |
if( $fh ) { |
318 |
$fh->binmode; |
326 |
$fh->binmode; |
Lines 381-409
sub _register {
Link Here
|
381 |
|
389 |
|
382 |
sub _lookup { |
390 |
sub _lookup { |
383 |
my ( $self, $params ) = @_; |
391 |
my ( $self, $params ) = @_; |
384 |
my $dbh = C4::Context->dbh; |
392 |
|
385 |
my $sql = q| |
393 |
my ( $cond, $attr, %pubhash ); |
386 |
SELECT id,hashvalue,filename,dir,filesize,uploadcategorycode,public,permanent,owner |
394 |
%pubhash = $self->{public}? ( public => 1 ): (); |
387 |
FROM uploaded_files |
|
|
388 |
|; |
389 |
my @pars; |
390 |
if( $params->{id} ) { |
395 |
if( $params->{id} ) { |
391 |
return [] if $params->{id} !~ /^\d+(,\d+)*$/; |
396 |
return [] if $params->{id} !~ /^\d+(,\d+)*$/; |
392 |
$sql.= 'WHERE id IN ('.$params->{id}.')'; |
397 |
$cond = { id => [ split ',', $params->{id} ], %pubhash }; |
393 |
@pars = (); |
|
|
394 |
} elsif( $params->{hashvalue} ) { |
398 |
} elsif( $params->{hashvalue} ) { |
395 |
$sql.= 'WHERE hashvalue=?'; |
399 |
$cond = { hashvalue => $params->{hashvalue}, %pubhash }; |
396 |
@pars = ( $params->{hashvalue} ); |
|
|
397 |
} elsif( $params->{term} ) { |
400 |
} elsif( $params->{term} ) { |
398 |
$sql.= 'WHERE (filename LIKE ? OR hashvalue LIKE ?)'; |
401 |
$cond = |
399 |
@pars = ( '%'.$params->{term}.'%', '%'.$params->{term}.'%' ); |
402 |
[ { filename => { like => '%'.$params->{term}.'%' }, %pubhash }, |
|
|
403 |
{ hashvalue => { like => '%'.$params->{term}.'%' }, %pubhash } ]; |
400 |
} else { |
404 |
} else { |
401 |
return []; |
405 |
return []; |
402 |
} |
406 |
} |
403 |
$sql.= $self->{public}? ' AND public=1': ''; |
407 |
$attr = { order_by => { -asc => 'id' }}; |
404 |
$sql.= ' ORDER BY id'; |
408 |
|
405 |
my $temp= $dbh->selectall_arrayref( $sql, { Slice => {} }, @pars ); |
409 |
return Koha::UploadedFiles->search( $cond, $attr )->unblessed; |
406 |
return $temp; |
410 |
# Does always return an arrayref (perhaps an empty one) |
407 |
} |
411 |
} |
408 |
|
412 |
|
409 |
sub _delete { |
413 |
sub _delete { |
410 |
- |
|
|