From 93ff61c10d671afb6c7be2dd24076383b839f182 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sun, 24 Apr 2016 17:39:13 +0100 Subject: [PATCH] Bug 16276: Make delete_patrons.pl deal with --last_seen This patch modify the delete_patrons.pl cronjob to deal with the last_seen option. To test it, you just have to use the --last_seen option and pass a valid date (iso format) Example: perl misc/cronjobs/delete_patrons.pl --last_seen="1984-02-04" --confirm will delete all the patrons who do not have been active since this date. Sponsored-by: BULAC - http://www.bulac.fr/ Signed-off-by: Nicolas Legrand https://bugs.koha-community.org/show_bug.cgi?id=12276 Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall --- misc/cronjobs/delete_patrons.pl | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/misc/cronjobs/delete_patrons.pl b/misc/cronjobs/delete_patrons.pl index a76d1ddf2b..58b231125b 100755 --- a/misc/cronjobs/delete_patrons.pl +++ b/misc/cronjobs/delete_patrons.pl @@ -9,13 +9,14 @@ use C4::Members; use Koha::DateUtils; use C4::Log; -my ( $help, $verbose, $not_borrowed_since, $expired_before, $category_code, - $branchcode, $confirm ); +my ( $help, $verbose, $not_borrowed_since, $expired_before, $last_seen, + $category_code, $branchcode, $confirm ); GetOptions( 'h|help' => \$help, 'v|verbose' => \$verbose, 'not_borrowed_since:s' => \$not_borrowed_since, 'expired_before:s' => \$expired_before, + 'last_seen:s' => \$last_seen, 'category_code:s' => \$category_code, 'library:s' => \$branchcode, 'c|confirm' => \$confirm, @@ -31,9 +32,12 @@ $not_borrowed_since = dt_from_string( $not_borrowed_since, 'iso' ) $expired_before = dt_from_string( $expired_before, 'iso' ) if $expired_before; -unless ( $not_borrowed_since or $expired_before or $category_code or $branchcode ) { +if ( $last_seen and not C4::Context->preference('TrackLastPatronActivity') ) { + pod2usage(q{The --last_seen option cannot be used with TrackLastPatronActivity turned off}); +} + +unless ( $not_borrowed_since or $expired_before or $last_seen or $category_code or $branchcode ) { pod2usage(q{At least one filter is mandatory}); - exit; } cronlogaction(); @@ -42,6 +46,7 @@ my $members = GetBorrowersToExpunge( { not_borrowed_since => $not_borrowed_since, expired_before => $expired_before, + last_seen => $last_seen, category_code => $category_code, branchcode => $branchcode, } @@ -108,7 +113,7 @@ delete_patrons - This script deletes patrons =head1 SYNOPSIS -delete_patrons.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--not_borrowed_since=DATE] [--expired_before=DATE] [--category_code=CAT] [--library=LIBRARY] +delete_patrons.pl [-h|--help] [-v|--verbose] [-c|--confirm] [--not_borrowed_since=DATE] [--expired_before=DATE] [--last-seen=DATE] [--category_code=CAT] [--library=LIBRARY] Dates should be in ISO format, e.g., 2013-07-19, and can be generated with `date -d '-3 month' "+%Y-%m-%d"`. @@ -133,6 +138,12 @@ Delete patrons who have not borrowed since this date. Delete patrons with an account expired before this date. +=item B<--last_seen> + +Delete patrons who have not been connected since this date. + +The system preference TrackLastPatronActivity must be enabled to use this option. + =item B<--category_code> Delete patrons who have this category code. -- 2.39.5