Bugzilla – Attachment 62497 Details for
Bug 18300
Delete missing upload records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18300: [QA Follow-up] Fix return value inconsistency
Bug-18300-QA-Follow-up-Fix-return-value-inconsiste.patch (text/plain), 3.80 KB, created by
Jonathan Druart
on 2017-04-20 18:29:32 UTC
(
hide
)
Description:
Bug 18300: [QA Follow-up] Fix return value inconsistency
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-04-20 18:29:32 UTC
Size:
3.80 KB
patch
obsolete
>From b4e10480bc7f11dcbcfb839d712c48cf62842e7f Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Mon, 3 Apr 2017 21:43:48 +0200 >Subject: [PATCH] Bug 18300: [QA Follow-up] Fix return value inconsistency > >As noted on bug report 17669, the return values of delete (both singular >and plural), delete_missing and delete_temporary should be consistent. > >Removed the if-construction around full_path. We do not need it; in the >very exceptional case that full_path would be empty, we should delete >the record since the file is missing. > >Adjusted POD and unit tests accordingly. > >Test plan: >Run t/db_dependent/Upload.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > Koha/UploadedFiles.pm | 24 +++++++++++++++--------- > t/db_dependent/Upload.t | 9 ++++++--- > 2 files changed, 21 insertions(+), 12 deletions(-) > >diff --git a/Koha/UploadedFiles.pm b/Koha/UploadedFiles.pm >index 61e9702..b6804f2 100644 >--- a/Koha/UploadedFiles.pm >+++ b/Koha/UploadedFiles.pm >@@ -115,24 +115,30 @@ 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: If you pass keep_record, it returns the number of records where >+the file is not found, or 0E0. Otherwise it returns a number, 0E0 or -1 just >+as delete does. > > =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; >- # 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 $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 >+ # Apply the same logic as in delete for the return value >+ my $delete = $row->delete({ keep_file => 1 }); # 1, 0E0 or -1 >+ $rv = ( $delete < 0 || $rv < 0 ) ? -1 : ( $rv + $delete ); > } >- return $cnt; >+ return $rv==0 ? "0E0" : $rv; > } > > =head3 search_term >diff --git a/t/db_dependent/Upload.t b/t/db_dependent/Upload.t >index 0489fee..8d77362 100644 >--- a/t/db_dependent/Upload.t >+++ b/t/db_dependent/Upload.t >@@ -193,20 +193,23 @@ subtest 'Test delete via UploadedFile as well as UploadedFiles' => sub { > }; > > subtest 'Test delete_missing' => sub { >- plan tests => 4; >+ plan tests => 5; > > # If we add files via TestBuilder, they do not exist > my $upload01 = $builder->build({ source => 'UploadedFile' }); > my $upload02 = $builder->build({ source => 'UploadedFile' }); > # dry run first > my $deleted = Koha::UploadedFiles->delete_missing({ keep_record => 1 }); >- is( $deleted, 2, 'Expect two missing files' ); >+ is( $deleted, 2, 'Expect two records with missing files' ); > isnt( Koha::UploadedFiles->find( $upload01->{id} ), undef, 'Not deleted' ); > $deleted = Koha::UploadedFiles->delete_missing; >- is( $deleted, 2, 'Deleted two missing files' ); >+ ok( $deleted =~ /^(2|-1)$/, 'Deleted two records with missing files' ); > is( Koha::UploadedFiles->search({ > id => [ $upload01->{id}, $upload02->{id} ], > })->count, 0, 'Records are gone' ); >+ # Repeat it >+ $deleted = Koha::UploadedFiles->delete_missing; >+ is( $deleted, "0E0", "Return value of 0E0 expected" ); > }; > > subtest 'Call search_term with[out] private flag' => sub { >-- >2.9.3
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 18300
:
61250
|
61470
|
61778
|
61810
|
61821
|
61822
|
62496
| 62497