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

(-)a/Koha/File/Transport.pm (+13 lines)
Lines 225-230 sub download_file { Link Here
225
    die "Subclass must implement download_file";
225
    die "Subclass must implement download_file";
226
}
226
}
227
227
228
=head3 delete_file
229
230
    $transport->delete_file($file);
231
232
Method for deleting a file from the current file server
233
234
=cut
235
236
sub delete_file {
237
    my ( $self, $file ) = @_;
238
    die "delete_file method not implemented in subclass";
239
}
240
228
=head3 change_directory
241
=head3 change_directory
229
242
230
    my $files = $transport->change_directory($path);
243
    my $files = $transport->change_directory($path);
(-)a/Koha/File/Transport/FTP.pm (+29 lines)
Lines 126-131 sub download_file { Link Here
126
    return 1;
126
    return 1;
127
}
127
}
128
128
129
=head3 delete_file
130
131
    my $success = $server->delete_file($filename);
132
133
Passed a filename, this will delete the file from the current directory of the server connection.
134
135
Returns true on success or undefined on failure.
136
137
=cut
138
139
sub delete_file {
140
    my ( $self, $remote_file ) = @_;
141
    my $operation = "delete";
142
143
    $self->{connection}->delete($remote_file) or return $self->_abort_operation( $operation, $remote_file );
144
145
    $self->add_message(
146
        {
147
            message => $operation,
148
            type    => 'success',
149
            payload => {
150
                remote_file => $remote_file,
151
            }
152
        }
153
    );
154
155
    return 1;
156
}
157
129
=head3 change_directory
158
=head3 change_directory
130
159
131
    my $success = $server->change_directory($directory);
160
    my $success = $server->change_directory($directory);
(-)a/Koha/File/Transport/Local.pm (+57 lines)
Lines 397-402 sub rename_file { Link Here
397
    return 1;
397
    return 1;
398
}
398
}
399
399
400
=head3 delete_file
401
402
    $server->delete_file();
403
404
Deletes a file in the current directory.
405
406
Returns true on success or undefined on failure.
407
408
=cut
409
410
sub delete_file {
411
    my ( $self, $remote_file ) = @_;
412
    my $operation = "delete";
413
414
    my $directory = $self->download_directory || $self->{current_directory} || '.';
415
    my $source    = File::Spec->catfile( $directory, $remote_file );
416
417
    # Check if the file exists
418
    unless ( -e $source ) {
419
        $self->add_message(
420
            {
421
                message => $operation,
422
                type    => 'error',
423
                payload => {
424
                    error => "File not found: $source",
425
                    path  => $source
426
                }
427
            }
428
        );
429
        return;
430
    }
431
432
    # Attempt to delete the file
433
    if ( unlink $source ) {
434
        $self->add_message(
435
            {
436
                message => $operation,
437
                type    => 'success',
438
                payload => { path => $source }
439
            }
440
        );
441
    } else {
442
        $self->add_message(
443
            {
444
                message => $operation,
445
                type    => 'error',
446
                payload => {
447
                    error => "File could not be deleted: $source",
448
                    path  => $source
449
                }
450
            }
451
        );
452
    }
453
454
    return 1;
455
}
456
400
=head3 disconnect
457
=head3 disconnect
401
458
402
    $server->disconnect();
459
    $server->disconnect();
(-)a/Koha/File/Transport/SFTP.pm (+29 lines)
Lines 138-143 sub download_file { Link Here
138
    return 1;
138
    return 1;
139
}
139
}
140
140
141
=head3 delete_file
142
143
    my $success = $server->delete_file($filename);
144
145
Passed a filename, this will delete the file from the current directory of the server connection.
146
147
Returns true on success or undefined on failure.
148
149
=cut
150
151
sub delete_file {
152
    my ( $self, $remote_file ) = @_;
153
    my $operation = "delete";
154
155
    $self->{connection}->remove($remote_file) or return $self->_abort_operation( $operation, $remote_file );
156
157
    $self->add_message(
158
        {
159
            message => $operation,
160
            type    => 'success',
161
            payload => {
162
                remote_file => $remote_file,
163
            }
164
        }
165
    );
166
167
    return 1;
168
}
169
141
=head3 change_directory
170
=head3 change_directory
142
171
143
    my $success = $server->change_directory($directory);
172
    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