View | Details | Raw Unified | Return to bug 17501
Collapse All | Expand All

(-)a/Koha/Upload.pm (-18 / +15 lines)
Lines 202-216 sub get { Link Here
202
202
203
sub delete {
203
sub delete {
204
    my ( $self, $params ) = @_;
204
    my ( $self, $params ) = @_;
205
    return if !$params->{id};
205
    return $self->_delete( $params->{id} );
206
    my @res;
207
    my $temp = $self->_lookup({ id => $params->{id} });
208
    foreach( @$temp ) {
209
        my $d = $self->_delete( $_ );
210
        push @res, $d if $d;
211
    }
212
    return if !@res;
213
    return @res;
214
}
206
}
215
207
216
=head1 CLASS METHODS
208
=head1 CLASS METHODS
Lines 411-427 sub _lookup { Link Here
411
}
403
}
412
404
413
sub _delete {
405
sub _delete {
414
    my ( $self, $rec ) = @_;
406
    my ( $self, $id ) = @_;
415
    my $dbh = C4::Context->dbh;
407
    my $rec = Koha::UploadedFiles->find($id) || return;
416
    my $sql = 'DELETE FROM uploaded_files WHERE id=?';
408
    my $filename = $rec->filename;
417
    my $file = $self->_full_fname($rec);
409
    my $file = $self->_full_fname({
410
        permanent => $rec->permanent,
411
        dir       => $rec->dir,
412
        hashvalue => $rec->hashvalue,
413
        filename  => $filename,
414
    });
415
418
    if( !-e $file ) { # we will just delete the record
416
    if( !-e $file ) { # we will just delete the record
419
        # TODO Should we add a trace here for the missing file?
417
        # TODO Should we add a trace here for the missing file?
420
        $dbh->do( $sql, undef, ( $rec->{id} ) );
418
        $rec->delete;
421
        return $rec->{filename};
419
        return $filename;
422
    } elsif( unlink($file) ) {
420
    } elsif( unlink($file) ) {
423
        $dbh->do( $sql, undef, ( $rec->{id} ) );
421
        $rec->delete;
424
        return $rec->{filename};
422
        return $filename;
425
    }
423
    }
426
    $self->{files}->{ $rec->{filename} }->{errcode} = 7;
424
    $self->{files}->{ $rec->{filename} }->{errcode} = 7;
427
    #NOTE: errcode=6 is used to report successful delete (see template)
425
    #NOTE: errcode=6 is used to report successful delete (see template)
428
- 

Return to bug 17501