From 44c4b3fca6eff57dd88989309970fe9cebfb8b6e Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Sun, 20 Nov 2016 16:10:33 +0100 Subject: [PATCH] Bug 17501: Use Koha::Object in Koha::Upload::_register The _register routine basically inserts a new record in uploaded_files. It should use Koha::UploadedFile now. Test plan: [1] Run t/db_dependent/Upload.t [2] Upload a file via Tools/Upload. Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- Koha/Upload.pm | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/Koha/Upload.pm b/Koha/Upload.pm index ceff56aa33..2e4aa04c6c 100644 --- a/Koha/Upload.pm +++ b/Koha/Upload.pm @@ -75,6 +75,7 @@ use base qw(Class::Accessor); use C4::Context; use C4::Koha; +use Koha::UploadedFile; __PACKAGE__->mk_ro_accessors( qw|| ); @@ -365,22 +366,17 @@ sub _done { sub _register { my ( $self, $filename, $size ) = @_; - my $dbh= C4::Context->dbh; - my $sql= 'INSERT INTO uploaded_files (hashvalue, filename, dir, filesize, - owner, uploadcategorycode, public, permanent) VALUES (?,?,?,?,?,?,?,?)'; - my @pars= ( - $self->{files}->{$filename}->{hash}, - $filename, - $self->{category}, - $size, - $self->{uid}, - $self->{category}, - $self->{public}, - $self->{temporary}? 0: 1, - ); - $dbh->do( $sql, undef, @pars ); - my $i = $dbh->last_insert_id(undef, undef, 'uploaded_files', undef); - $self->{files}->{$filename}->{id} = $i if $i; + my $rec = Koha::UploadedFile->new({ + hashvalue => $self->{files}->{$filename}->{hash}, + filename => $filename, + dir => $self->{category}, + filesize => $size, + owner => $self->{uid}, + uploadcategorycode => $self->{category}, + public => $self->{public}, + permanent => $self->{temporary}? 0: 1, + })->store; + $self->{files}->{$filename}->{id} = $rec->id if $rec; } sub _lookup { -- 2.39.5