+=head3 delete_missing
+
+ $cnt = Koha::UploadedFiles->delete_missing();
+
+ $cnt = Koha::UploadedFiles->delete_missing({ keep_record => 1 });
+
+Deletes all records where the actual file is not found.
+
+Supports a keep_record hash parameter to do a check only.
+
+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 $rv = 0;
+ while( my $row = $self->next ) {
+ 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 $deleted = eval { $row->delete({ keep_file => 1 }) };
+ $rv++ if $deleted && !$@;
+ }
+ return $rv==0 ? "0E0" : $rv;
+}
+