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

(-)a/Koha/File/Transport.pm (+13 lines)
Lines 354-359 sub download_file { Link Here
354
    return $self->_download_file( $remote_file, $local_file );
354
    return $self->_download_file( $remote_file, $local_file );
355
}
355
}
356
356
357
=head3 delete_file
358
359
    $transport->delete_file($file);
360
361
Method for deleting a file from the current file server
362
363
=cut
364
365
sub delete_file {
366
    my ( $self, $file ) = @_;
367
    die "Subclass must implement delete_file";
368
}
369
357
=head3 _download_file
370
=head3 _download_file
358
371
359
    $transport->_download_file($remote_file, $local_file);
372
    $transport->_download_file($remote_file, $local_file);
(-)a/Koha/File/Transport/FTP.pm (+29 lines)
Lines 122-127 sub _download_file { Link Here
122
    return 1;
122
    return 1;
123
}
123
}
124
124
125
=head3 delete_file
126
127
    my $success = $server->delete_file($filename);
128
129
Passed a filename, this will delete the file from the current directory of the server connection.
130
131
Returns true on success or undefined on failure.
132
133
=cut
134
135
sub delete_file {
136
    my ( $self, $remote_file ) = @_;
137
    my $operation = "delete";
138
139
    $self->{connection}->delete($remote_file) or return $self->_abort_operation( $operation, $remote_file );
140
141
    $self->add_message(
142
        {
143
            message => $operation,
144
            type    => 'success',
145
            payload => {
146
                remote_file => $remote_file,
147
            }
148
        }
149
    );
150
151
    return 1;
152
}
153
125
=head3 change_directory
154
=head3 change_directory
126
155
127
    my $success = $server->change_directory($directory);
156
    my $success = $server->change_directory($directory);
(-)a/Koha/File/Transport/Local.pm (+57 lines)
Lines 403-408 sub _is_connected { Link Here
403
    return 1;    # Local filesystem is always "connected"
403
    return 1;    # Local filesystem is always "connected"
404
}
404
}
405
405
406
=head3 delete_file
407
408
    $server->delete_file();
409
410
Deletes a file in the current directory.
411
412
Returns true on success or undefined on failure.
413
414
=cut
415
416
sub delete_file {
417
    my ( $self, $remote_file ) = @_;
418
    my $operation = "delete";
419
420
    my $directory = $self->download_directory || $self->{current_directory} || '.';
421
    my $source    = File::Spec->catfile( $directory, $remote_file );
422
423
    # Check if the file exists
424
    unless ( -e $source ) {
425
        $self->add_message(
426
            {
427
                message => $operation,
428
                type    => 'error',
429
                payload => {
430
                    error => "File not found: $source",
431
                    path  => $source
432
                }
433
            }
434
        );
435
        return;
436
    }
437
438
    # Attempt to delete the file
439
    if ( unlink $source ) {
440
        $self->add_message(
441
            {
442
                message => $operation,
443
                type    => 'success',
444
                payload => { path => $source }
445
            }
446
        );
447
    } else {
448
        $self->add_message(
449
            {
450
                message => $operation,
451
                type    => 'error',
452
                payload => {
453
                    error => "File could not be deleted: $source",
454
                    path  => $source
455
                }
456
            }
457
        );
458
    }
459
460
    return 1;
461
}
462
406
=head3 disconnect
463
=head3 disconnect
407
464
408
    $server->disconnect();
465
    $server->disconnect();
(-)a/Koha/File/Transport/SFTP.pm (+30 lines)
Lines 21-26 use Koha::Logger; Link Here
21
21
22
use File::Spec;
22
use File::Spec;
23
use IO::File;
23
use IO::File;
24
use JSON qw( encode_json );
24
use Net::SFTP::Foreign;
25
use Net::SFTP::Foreign;
25
use Try::Tiny;
26
use Try::Tiny;
26
27
Lines 134-139 sub _download_file { Link Here
134
    return 1;
135
    return 1;
135
}
136
}
136
137
138
=head3 delete_file
139
140
    my $success = $server->delete_file($filename);
141
142
Passed a filename, this will delete the file from the current directory of the server connection.
143
144
Returns true on success or undefined on failure.
145
146
=cut
147
148
sub delete_file {
149
    my ( $self, $remote_file ) = @_;
150
    my $operation = "delete";
151
152
    $self->{connection}->remove($remote_file) or return $self->_abort_operation( $operation, $remote_file );
153
154
    $self->add_message(
155
        {
156
            message => $operation,
157
            type    => 'success',
158
            payload => {
159
                remote_file => $remote_file,
160
            }
161
        }
162
    );
163
164
    return 1;
165
}
166
137
=head3 change_directory
167
=head3 change_directory
138
168
139
    my $success = $server->change_directory($directory);
169
    my $success = $server->change_directory($directory);
(-)a/t/db_dependent/Koha/File/Transports.t (-2 / +3 lines)
Lines 29-35 my $schema = Koha::Database->new->schema; Link Here
29
my $builder = t::lib::TestBuilder->new;
29
my $builder = t::lib::TestBuilder->new;
30
30
31
subtest 'Polymorphic object creation' => sub {
31
subtest 'Polymorphic object creation' => sub {
32
    plan tests => 6;
32
    plan tests => 7;
33
33
34
    $schema->storage->txn_begin;
34
    $schema->storage->txn_begin;
35
35
Lines 90-95 subtest 'Polymorphic object creation' => sub { Link Here
90
90
91
    can_ok( $local_transport, 'rename_file' );
91
    can_ok( $local_transport, 'rename_file' );
92
92
93
    can_ok( $local_transport, 'delete_file' );
94
93
    $schema->storage->txn_rollback;
95
    $schema->storage->txn_rollback;
94
};
96
};
95
97
96
- 

Return to bug 41020