diff --git a/Koha/File/Transport/Local.pm b/Koha/File/Transport/Local.pm index 14838b5eaf..c332b2f26f 100644 --- a/Koha/File/Transport/Local.pm +++ b/Koha/File/Transport/Local.pm @@ -138,14 +138,10 @@ sub _upload_file { my $upload_dir = $self->_working_directory('upload_directory'); unless ( defined $upload_dir ) { - $self->add_message( - { - message => $operation, - type => 'error', - payload => { error => 'No upload directory configured or set via change_directory()' } - } + return $self->_abort_operation( + $operation, + { error => 'No upload directory configured or set via change_directory()' } ); - return; } my $destination = File::Spec->catfile( $upload_dir, $remote_file ); @@ -185,14 +181,10 @@ sub _download_file { my $download_dir = $self->_working_directory('download_directory'); unless ( defined $download_dir ) { - $self->add_message( - { - message => $operation, - type => 'error', - payload => { error => 'No download directory configured or set via change_directory()' } - } + return $self->_abort_operation( + $operation, + { error => 'No download directory configured or set via change_directory()' } ); - return; } my $source = File::Spec->catfile( $download_dir, $remote_file ); @@ -296,14 +288,10 @@ sub _list_files { my $directory = $self->_working_directory('download_directory'); unless ( defined $directory ) { - $self->add_message( - { - message => $operation, - type => 'error', - payload => { error => 'No download directory configured or set via change_directory()' } - } + return $self->_abort_operation( + $operation, + { error => 'No download directory configured or set via change_directory()' } ); - return; } unless ( -d $directory ) { @@ -387,14 +375,10 @@ sub _rename_file { my $directory = $self->_working_directory('download_directory'); unless ( defined $directory ) { - $self->add_message( - { - message => $operation, - type => 'error', - payload => { error => 'No download directory configured or set via change_directory()' } - } + return $self->_abort_operation( + $operation, + { error => 'No download directory configured or set via change_directory()' } ); - return; } my $old_path = File::Spec->catfile( $directory, $old_name ); diff --git a/t/db_dependent/Koha/File/Transport/Local.t b/t/db_dependent/Koha/File/Transport/Local.t index c4a83f5d59..348aaad6d4 100755 --- a/t/db_dependent/Koha/File/Transport/Local.t +++ b/t/db_dependent/Koha/File/Transport/Local.t @@ -119,7 +119,7 @@ subtest 'current_directory() tests' => sub { }; subtest 'an unconfigured directory fails cleanly instead of falling back to "." (the Koha process cwd)' => sub { - plan tests => 8; + plan tests => 10; $schema->storage->txn_begin; @@ -151,6 +151,11 @@ subtest 'an unconfigured directory fails cleanly instead of falling back to "." 'error explains the directory is unconfigured, rather than silently listing an unrelated directory' ); + my $reloaded = Koha::File::Transports->find( $transport->id ); + my $persisted_status = decode_json( $reloaded->status ); + is( $persisted_status->{status}, 'errors', 'a "not configured" error also persists an "errors" status' ); + is( $persisted_status->{operations}[-1]{code}, 'list', 'persisted status records the failing operation' ); + my $renamed = $transport->rename_file( 'a.txt', 'b.txt' ); is( $renamed, undef, 'rename_file() fails the same way when no download_directory is configured' );