Bugzilla – Attachment 58615 Details for
Bug 17501
Koha Objects for uploaded files
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17501: Use Koha::Object in Koha::Upload::_lookup
Bug-17501-Use-KohaObject-in-KohaUploadlookup.patch (text/plain), 3.67 KB, created by
Tomás Cohen Arazi (tcohen)
on 2017-01-05 18:39:36 UTC
(
hide
)
Description:
Bug 17501: Use Koha::Object in Koha::Upload::_lookup
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2017-01-05 18:39:36 UTC
Size:
3.67 KB
patch
obsolete
>From e4d96ee8056ef659184c6df258555e37fe324418 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Mon, 21 Nov 2016 08:48:02 +0100 >Subject: [PATCH] Bug 17501: Use Koha::Object in Koha::Upload::_lookup > >The _lookup routine performs a few select statements on uploaded_files. >In this patch the SQL statements are replaced with Koha::Object calls. >One call of _lookup is replaced directly by Koha::UploadedFiles. > >Note: _lookup can be removed in a later stage. > >Test plan: >[1] Run t/db_dependent/Upload.t >[2] Upload a file in some upload category >[3] Try to upload the same file into the same category. Error? >[4] Try to upload the same file in another category. Should work. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/Upload.pm | 42 +++++++++++++++++++++++------------------- > 1 file changed, 23 insertions(+), 19 deletions(-) > >diff --git a/Koha/Upload.pm b/Koha/Upload.pm >index 2e4aa04c6c..f30de0e7d6 100644 >--- a/Koha/Upload.pm >+++ b/Koha/Upload.pm >@@ -76,6 +76,7 @@ use base qw(Class::Accessor); > use C4::Context; > use C4::Koha; > use Koha::UploadedFile; >+use Koha::UploadedFiles; > > __PACKAGE__->mk_ro_accessors( qw|| ); > >@@ -306,13 +307,20 @@ sub _create_file { > $self->{files}->{$filename}->{errcode} = 4; #no tempdir > } else { > my $dir = $self->_dir; >- my $fn = $self->{files}->{$filename}->{hash}. '_'. $filename; >- if( -e "$dir/$fn" && @{ $self->_lookup({ >- hashvalue => $self->{files}->{$filename}->{hash} }) } ) { >+ my $hashval = $self->{files}->{$filename}->{hash}; >+ my $fn = $hashval. '_'. $filename; >+ > # if the file exists and it is registered, then set error >+ # if it exists, but is not in the database, we will overwrite >+ if( -e "$dir/$fn" && >+ Koha::UploadedFiles->search({ >+ hashvalue => $hashval, >+ uploadcategorycode => $self->{category}, >+ })->count ) { > $self->{files}->{$filename}->{errcode} = 1; #already exists > return; > } >+ > $fh = IO::File->new( "$dir/$fn", "w"); > if( $fh ) { > $fh->binmode; >@@ -381,29 +389,25 @@ sub _register { > > sub _lookup { > my ( $self, $params ) = @_; >- my $dbh = C4::Context->dbh; >- my $sql = q| >-SELECT id,hashvalue,filename,dir,filesize,uploadcategorycode,public,permanent,owner >-FROM uploaded_files >- |; >- my @pars; >+ >+ my ( $cond, $attr, %pubhash ); >+ %pubhash = $self->{public}? ( public => 1 ): (); > if( $params->{id} ) { > return [] if $params->{id} !~ /^\d+(,\d+)*$/; >- $sql.= 'WHERE id IN ('.$params->{id}.')'; >- @pars = (); >+ $cond = { id => [ split ',', $params->{id} ], %pubhash }; > } elsif( $params->{hashvalue} ) { >- $sql.= 'WHERE hashvalue=?'; >- @pars = ( $params->{hashvalue} ); >+ $cond = { hashvalue => $params->{hashvalue}, %pubhash }; > } elsif( $params->{term} ) { >- $sql.= 'WHERE (filename LIKE ? OR hashvalue LIKE ?)'; >- @pars = ( '%'.$params->{term}.'%', '%'.$params->{term}.'%' ); >+ $cond = >+ [ { filename => { like => '%'.$params->{term}.'%' }, %pubhash }, >+ { hashvalue => { like => '%'.$params->{term}.'%' }, %pubhash } ]; > } else { > return []; > } >- $sql.= $self->{public}? ' AND public=1': ''; >- $sql.= ' ORDER BY id'; >- my $temp= $dbh->selectall_arrayref( $sql, { Slice => {} }, @pars ); >- return $temp; >+ $attr = { order_by => { -asc => 'id' }}; >+ >+ return Koha::UploadedFiles->search( $cond, $attr )->unblessed; >+ # Does always return an arrayref (perhaps an empty one) > } > > sub _delete { >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17501
:
57751
|
57752
|
57753
|
57754
|
57755
|
57756
|
57757
|
57758
|
57759
|
58613
|
58614
|
58615
|
58616
|
58617
|
58618
|
58619
|
58620
|
58621
|
58809
|
59342
|
59343
|
59344
|
59345
|
59346
|
59347
|
59348
|
59349
|
59350
|
59351