Bugzilla – Attachment 187932 Details for
Bug 41020
Add ability to use file transports for marc ordering accounts
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 41020: Add ability to delete files to Koha::File::Transport and derived classes
Bug-41020-Add-ability-to-delete-files-to-KohaFileT.patch (text/plain), 5.59 KB, created by
Kyle M Hall (khall)
on 2025-10-15 18:37:07 UTC
(
hide
)
Description:
Bug 41020: Add ability to delete files to Koha::File::Transport and derived classes
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2025-10-15 18:37:07 UTC
Size:
5.59 KB
patch
obsolete
>From 4f9de9c283fa5da56fde5defdfeac2074dfdd453 Mon Sep 17 00:00:00 2001 >From: John Doe <you@example.com> >Date: Wed, 15 Oct 2025 18:06:47 +0000 >Subject: [PATCH] Bug 41020: Add ability to delete files to > Koha::File::Transport and derived classes > >--- > Koha/File/Transport.pm | 15 +++++++- > Koha/File/Transport/FTP.pm | 29 ++++++++++++++ > Koha/File/Transport/Local.pm | 55 +++++++++++++++++++++++++++ > Koha/File/Transport/SFTP.pm | 29 ++++++++++++++ > t/db_dependent/Koha/File/Transports.t | 4 +- > 5 files changed, 129 insertions(+), 3 deletions(-) > >diff --git a/Koha/File/Transport.pm b/Koha/File/Transport.pm >index 188aaa1ec8e..b543ce21f10 100644 >--- a/Koha/File/Transport.pm >+++ b/Koha/File/Transport.pm >@@ -184,8 +184,6 @@ sub test_connection { > > =head2 Subclass methods > >-Interface methods that must be implemented by subclasses >- > =head3 connect > > $transport->connect(); >@@ -225,6 +223,19 @@ sub download_file { > die "Subclass must implement download_file"; > } > >+=head3 delete_file >+ >+ $transport->delete_file($file); >+ >+Method for deleting a file from the current file server >+ >+=cut >+ >+sub delete_file { >+ my ( $self, $file ) = @_; >+ die "delete_file method not implemented in subclass"; >+} >+ > =head3 change_directory > > my $files = $transport->change_directory($path); >diff --git a/Koha/File/Transport/FTP.pm b/Koha/File/Transport/FTP.pm >index f965ebd0ede..b07e21b41e4 100644 >--- a/Koha/File/Transport/FTP.pm >+++ b/Koha/File/Transport/FTP.pm >@@ -126,6 +126,35 @@ sub download_file { > return 1; > } > >+=head3 delete_file >+ >+ my $success = $server->delete_file($filename); >+ >+Passed a filename, this will delete the file from the current directory of the server connection. >+ >+Returns true on success or undefined on failure. >+ >+=cut >+ >+sub delete_file { >+ my ( $self, $remote_file ) = @_; >+ my $operation = "delete"; >+ >+ $self->{connection}->delete($remote_file) or return $self->_abort_operation( $operation, $remote_file ); >+ >+ $self->add_message( >+ { >+ message => $operation, >+ type => 'success', >+ payload => { >+ remote_file => $remote_file, >+ } >+ } >+ ); >+ >+ return 1; >+} >+ > =head3 change_directory > > my $success = $server->change_directory($directory); >diff --git a/Koha/File/Transport/Local.pm b/Koha/File/Transport/Local.pm >index 729a7f4a13b..4bd24e5cad6 100644 >--- a/Koha/File/Transport/Local.pm >+++ b/Koha/File/Transport/Local.pm >@@ -405,6 +405,61 @@ For local transport, this is a no-op as there are no connections to close. > > =cut > >+sub delete_file { >+ my ( $self, $remote_file ) = @_; >+ my $operation = "delete"; >+ >+ my $directory = $self->download_directory || $self->{current_directory} || '.'; >+ my $source = File::Spec->catfile( $directory, $remote_file ); >+ >+ # Check if the file exists >+ unless ( -e $source ) { >+ $self->add_message( >+ { >+ message => $operation, >+ type => 'error', >+ payload => { >+ error => "File not found: $source", >+ path => $source >+ } >+ } >+ ); >+ return; >+ } >+ >+ # Attempt to delete the file >+ if ( unlink $source ) { >+ $self->add_message( >+ { >+ message => $operation, >+ type => 'success', >+ payload => { path => $source } >+ } >+ ); >+ } else { >+ $self->add_message( >+ { >+ message => $operation, >+ type => 'error', >+ payload => { >+ error => "File could not be deleted: $source", >+ path => $source >+ } >+ } >+ ); >+ } >+ >+ return 1; >+} >+ >+=head3 disconnect >+ >+ $server->disconnect(); >+ >+For local transport, this is a no-op as there are no connections to close. >+ >+=cut >+ > sub disconnect { > my ($self) = @_; > >diff --git a/Koha/File/Transport/SFTP.pm b/Koha/File/Transport/SFTP.pm >index d0abdd69d3a..179d1c17802 100644 >--- a/Koha/File/Transport/SFTP.pm >+++ b/Koha/File/Transport/SFTP.pm >@@ -138,6 +138,35 @@ sub download_file { > return 1; > } > >+=head3 delete_file >+ >+ my $success = $server->delete_file($filename); >+ >+Passed a filename, this will delete the file from the current directory of the server connection. >+ >+Returns true on success or undefined on failure. >+ >+=cut >+ >+sub delete_file { >+ my ( $self, $remote_file ) = @_; >+ my $operation = "delete"; >+ >+ $self->{connection}->remove($remote_file) or return $self->_abort_operation( $operation, $remote_file ); >+ >+ $self->add_message( >+ { >+ message => $operation, >+ type => 'success', >+ payload => { >+ remote_file => $remote_file, >+ } >+ } >+ ); >+ >+ return 1; >+} >+ > =head3 change_directory > > my $success = $server->change_directory($directory); >diff --git a/t/db_dependent/Koha/File/Transports.t b/t/db_dependent/Koha/File/Transports.t >index 928c48423f0..597bd646bb4 100755 >--- a/t/db_dependent/Koha/File/Transports.t >+++ b/t/db_dependent/Koha/File/Transports.t >@@ -29,7 +29,7 @@ my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; > > subtest 'Polymorphic object creation' => sub { >- plan tests => 6; >+ plan tests => 7; > > $schema->storage->txn_begin; > >@@ -90,6 +90,8 @@ subtest 'Polymorphic object creation' => sub { > > can_ok( $local_transport, 'rename_file' ); > >+ can_ok( $local_transport, 'delete_file' ); >+ > $schema->storage->txn_rollback; > }; > >-- >2.39.5 (Apple Git-154)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 41020
:
187931
|
187932
|
187933
|
187934
|
187935
|
187936
|
187937
|
187938
|
187939
|
187940
|
187941
|
187942