From ca70f5093b6993f1c0ba697ef2e32eb5b58ef44a Mon Sep 17 00:00:00 2001 From: Wainui Witika-Park Date: Mon, 7 Aug 2023 15:46:45 +1200 Subject: [PATCH] Bug 31143: Update patrons with dates of 0000-00-00 to NULL To test: 1) Change a patron's value of one or more of the following to 0000-00-00: dateofbirth dateenrolled dateexpiry date_renewed 2) Run the fix_patron_dates.pl (-c -v) 3) Notice the value has changed from 0000-00-00 to NULL Sponsored by: Toi Ohomai Institute of Technology, New Zealand Signed-off-by: David Nind --- misc/cronjobs/fix_patron_dates.pl | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 misc/cronjobs/fix_patron_dates.pl diff --git a/misc/cronjobs/fix_patron_dates.pl b/misc/cronjobs/fix_patron_dates.pl new file mode 100755 index 0000000000..af97d2a177 --- /dev/null +++ b/misc/cronjobs/fix_patron_dates.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use C4::Context; +use C4::Log qw(cronlogaction); +use Getopt::Long qw( GetOptions ); +use Pod::Usage qw( pod2usage ); +use Koha::Logger; +use Koha::Patrons; +use Koha::DateUtils qw( dt_from_string ); +use Koha::Script -cron; +use Data::Dumper; + +my $verbose = 0; +my $doit = 0; + +GetOptions( + 'v|verbose' => \$verbose, + 'c|confirm' => \$doit, +); + +my $count; + +# search patrons that have date fields that are 0000-00-00 +foreach my $date_type (qw(dateofbirth dateenrolled dateexpiry date_renewed)) { + my $borrowers = Koha::Patrons->search( { $date_type=>'0000-00-00' } ); + + if ($doit) { # if confirm flag was run with cronjob + while (my $borrower = $borrowers->next()) { + $count++; + $borrower->$date_type(undef)->store(); + } + } +} + +if ($verbose) { + print "$count wrong dates found"; +} -- 2.30.2