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

(-)a/Koha/UploadedFile.pm (+6 lines)
Lines 73-78 sub delete { Link Here
73
73
74
    my $name = $self->filename;
74
    my $name = $self->filename;
75
    my $file = $self->full_path;
75
    my $file = $self->full_path;
76
    my $public_filepath = $self->local_public_path;
76
77
77
    my $retval = $self->SUPER::delete;
78
    my $retval = $self->SUPER::delete;
78
    if( !defined($retval) ) { # undef is Unknown (-1)
79
    if( !defined($retval) ) { # undef is Unknown (-1)
Lines 90-95 sub delete { Link Here
90
    } elsif( ! unlink($file) ) {
91
    } elsif( ! unlink($file) ) {
91
        warn "Problem while deleting: $file";
92
        warn "Problem while deleting: $file";
92
    }
93
    }
94
95
    if( -e $public_filepath and ! unlink($public_filepath) ) {
96
        warn "Problem while deleting: $public_filepath";
97
    }
98
93
    return $retval;
99
    return $retval;
94
}
100
}
95
101
(-)a/t/db_dependent/Upload.t (-2 / +15 lines)
Lines 51-56 our $uploads = [ Link Here
51
# Redirect upload dir structure and mock C4::Context and CGI
51
# Redirect upload dir structure and mock C4::Context and CGI
52
my $tempdir = tempdir( CLEANUP => 1 );
52
my $tempdir = tempdir( CLEANUP => 1 );
53
t::lib::Mocks::mock_config('upload_path', $tempdir);
53
t::lib::Mocks::mock_config('upload_path', $tempdir);
54
    my $publictempdir = tempdir( CLEANUP => 1 );
55
    my $public_base_url = 'http://my_opac/public_dir';
56
    t::lib::Mocks::mock_config('upload_public_path', $publictempdir);
57
    t::lib::Mocks::mock_config('upload_public_url', $public_base_url);
54
my $specmod = Test::MockModule->new( 'C4::Context' );
58
my $specmod = Test::MockModule->new( 'C4::Context' );
55
$specmod->mock( 'temporary_directory' => sub { return $tempdir; } );
59
$specmod->mock( 'temporary_directory' => sub { return $tempdir; } );
56
my $cgimod = Test::MockModule->new( 'CGI' );
60
my $cgimod = Test::MockModule->new( 'CGI' );
Lines 149-155 subtest 'Add same file in same category' => sub { Link Here
149
};
153
};
150
154
151
subtest 'Test delete via UploadedFile as well as UploadedFiles' => sub {
155
subtest 'Test delete via UploadedFile as well as UploadedFiles' => sub {
152
    plan tests => 12;
156
    plan tests => 14;
153
157
154
    # add temporary file with same name and contents (file4)
158
    # add temporary file with same name and contents (file4)
155
    my $upl = Koha::Uploader->new({ tmp => 1 });
159
    my $upl = Koha::Uploader->new({ tmp => 1 });
Lines 193-198 subtest 'Test delete via UploadedFile as well as UploadedFiles' => sub { Link Here
193
    ok( $delete =~ /^(0E0|-1)$/, 'Repeated delete unsuccessful' );
197
    ok( $delete =~ /^(0E0|-1)$/, 'Repeated delete unsuccessful' );
194
    is( -e $path, 1, 'File exists if keep_file is passed on deleting' );
198
    is( -e $path, 1, 'File exists if keep_file is passed on deleting' );
195
    # NOTE: Koha::Object->delete does not return 0E0 (yet?)
199
    # NOTE: Koha::Object->delete does not return 0E0 (yet?)
200
201
    # testing delete direct public path
202
    $upl = Koha::Uploader->new({ tmp => 1 });
203
    $upl->cgi;
204
    $kohaobj = Koha::UploadedFiles->find( $upl->result );
205
    my $local_public_path = $kohaobj->local_public_path;
206
    is( -e $local_public_path, 1, 'Local public file exist after create' );
207
    $delete = $kohaobj->delete;
208
    ok( $delete=~/^-?1$/, 'Delete successful' );
209
    isnt( -e $local_public_path, 1, 'Local public file no longer found after delete' );
196
};
210
};
197
211
198
subtest 'Test delete_missing' => sub {
212
subtest 'Test delete_missing' => sub {
199
- 

Return to bug 22508