From 795d445b16f95cf9a74e45daca0b87b04d65aad5 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 3 Apr 2017 21:43:48 +0200 Subject: [PATCH] Bug 18300: [QA Follow-up] Fix return value inconsistency Content-Type: text/plain; charset=utf-8 As noted on bug report 17669, the return values of delete (both singular and plural), delete_missing and delete_temporary should be consistent. --- Koha/UploadedFiles.pm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Koha/UploadedFiles.pm b/Koha/UploadedFiles.pm index 394a8f5..6e4a802 100644 --- a/Koha/UploadedFiles.pm +++ b/Koha/UploadedFiles.pm @@ -115,24 +115,29 @@ Deletes all records where the actual file is not found. Supports a keep_record hash parameter to do a check only. -Returns the number of missing files (and/or deleted records). +Return value: see delete. =cut sub delete_missing { my ( $self, $params ) = @_; $self = Koha::UploadedFiles->new if !ref($self); # handle class call - my $cnt = 0; + my $rv = 0; while( my $row = $self->next ) { if( my $file = $row->full_path ) { next if -e $file; + if( $params->{keep_record} ) { + $rv++; + next; + } # We are passing keep_file since we already know that the file # is missing and we do not want to see the warning - $row->delete({ keep_file => 1 }) if !$params->{keep_record}; - $cnt++; + my $delete = $row->delete({ keep_file => 1 }) // -1; + # Apply the same logic as in delete for the return value + $rv = ( $delete < 0 || $rv < 0 ) ? -1 : ( $rv + $delete ); } } - return $cnt; + return $rv; } =head3 search_term -- 2.1.4