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

(-)a/Koha/File/Transport.pm (-2 / +13 lines)
Lines 184-191 sub test_connection { Link Here
184
184
185
=head2 Subclass methods
185
=head2 Subclass methods
186
186
187
Interface methods that must be implemented by subclasses
188
189
=head3 connect
187
=head3 connect
190
188
191
    $transport->connect();
189
    $transport->connect();
Lines 225-230 sub download_file { Link Here
225
    die "Subclass must implement download_file";
223
    die "Subclass must implement download_file";
226
}
224
}
227
225
226
=head3 delete_file
227
228
    $transport->delete_file($file);
229
230
Method for deleting a file from the current file server
231
232
=cut
233
234
sub delete_file {
235
    my ( $self, $file ) = @_;
236
    die "delete_file method not implemented in subclass";
237
}
238
228
=head3 change_directory
239
=head3 change_directory
229
240
230
    my $files = $transport->change_directory($path);
241
    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 (+55 lines)
Lines 405-410 For local transport, this is a no-op as there are no connections to close. Link Here
405
405
406
=cut
406
=cut
407
407
408
sub delete_file {
409
    my ( $self, $remote_file ) = @_;
410
    my $operation = "delete";
411
412
    my $directory = $self->download_directory || $self->{current_directory} || '.';
413
    my $source    = File::Spec->catfile( $directory, $remote_file );
414
415
    # Check if the file exists
416
    unless ( -e $source ) {
417
        $self->add_message(
418
            {
419
                message => $operation,
420
                type    => 'error',
421
                payload => {
422
                    error => "File not found: $source",
423
                    path  => $source
424
                }
425
            }
426
        );
427
        return;
428
    }
429
430
    # Attempt to delete the file
431
    if ( unlink $source ) {
432
        $self->add_message(
433
            {
434
                message => $operation,
435
                type    => 'success',
436
                payload => { path => $source }
437
            }
438
        );
439
    } else {
440
        $self->add_message(
441
            {
442
                message => $operation,
443
                type    => 'error',
444
                payload => {
445
                    error => "File could not be deleted: $source",
446
                    path  => $source
447
                }
448
            }
449
        );
450
    }
451
452
    return 1;
453
}
454
455
=head3 disconnect
456
457
    $server->disconnect();
458
459
For local transport, this is a no-op as there are no connections to close.
460
461
=cut
462
408
sub disconnect {
463
sub disconnect {
409
    my ($self) = @_;
464
    my ($self) = @_;
410
465
(-)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