Bugzilla – Attachment 59345 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::_delete
Bug-17501-Use-KohaObject-in-KohaUploaddelete.patch (text/plain), 2.46 KB, created by
Jonathan Druart
on 2017-01-20 11:40:31 UTC
(
hide
)
Description:
Bug 17501: Use Koha::Object in Koha::Upload::_delete
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-01-20 11:40:31 UTC
Size:
2.46 KB
patch
obsolete
>From fe2dec719c2d07a730c546b3855601bfdee91b95 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Mon, 21 Nov 2016 14:12:17 +0100 >Subject: [PATCH] Bug 17501: Use Koha::Object in Koha::Upload::_delete > >Note: This is the last occurrence where we use DBI to perform a CRUD >operation. In this case a delete from uploaded_files. > >We now call Koha::UploadedFile[s]->delete to only delete the record >from the table. A next step will be moving the additional functionality >of removing the file(s) too. > >Test plan: >[1] Run t/db_dependent/Upload.t >[2] Delete an upload from tools/upload.pl > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > Koha/Upload.pm | 32 +++++++++++++++----------------- > 1 file changed, 15 insertions(+), 17 deletions(-) > >diff --git a/Koha/Upload.pm b/Koha/Upload.pm >index f30de0e..4f4f5c5 100644 >--- a/Koha/Upload.pm >+++ b/Koha/Upload.pm >@@ -202,15 +202,7 @@ sub get { > > sub delete { > my ( $self, $params ) = @_; >- return if !$params->{id}; >- my @res; >- my $temp = $self->_lookup({ id => $params->{id} }); >- foreach( @$temp ) { >- my $d = $self->_delete( $_ ); >- push @res, $d if $d; >- } >- return if !@res; >- return @res; >+ return $self->_delete( $params->{id} ); > } > > =head1 CLASS METHODS >@@ -411,17 +403,23 @@ sub _lookup { > } > > sub _delete { >- my ( $self, $rec ) = @_; >- my $dbh = C4::Context->dbh; >- my $sql = 'DELETE FROM uploaded_files WHERE id=?'; >- my $file = $self->_full_fname($rec); >+ my ( $self, $id ) = @_; >+ my $rec = Koha::UploadedFiles->find($id) || return; >+ my $filename = $rec->filename; >+ my $file = $self->_full_fname({ >+ permanent => $rec->permanent, >+ dir => $rec->dir, >+ hashvalue => $rec->hashvalue, >+ filename => $filename, >+ }); >+ > if( !-e $file ) { # we will just delete the record > # TODO Should we add a trace here for the missing file? >- $dbh->do( $sql, undef, ( $rec->{id} ) ); >- return $rec->{filename}; >+ $rec->delete; >+ return $filename; > } elsif( unlink($file) ) { >- $dbh->do( $sql, undef, ( $rec->{id} ) ); >- return $rec->{filename}; >+ $rec->delete; >+ return $filename; > } > $self->{files}->{ $rec->{filename} }->{errcode} = 7; > #NOTE: errcode=6 is used to report successful delete (see template) >-- >2.1.4
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