From 353d8b9d2deb161acf3349be96e204e138dd5133 Mon Sep 17 00:00:00 2001 From: Christophe Croullebois Date: Thu, 28 Feb 2013 16:15:07 +0100 Subject: [PATCH 1/1] Bug 9730: AnonymiseIssueHistory fails quietly if AnonymousPatron is not a valid entry it fails also if 'AnonymousPatron' = 0 With the patch in this case the borrowernumber becomes NULL --- C4/Circulation.pm | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index f1c8662..32bf162 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2861,15 +2861,21 @@ sub AnonymiseIssueHistory { my $dbh = C4::Context->dbh; my $query = " UPDATE old_issues - SET borrowernumber = ? - WHERE returndate < ? - AND borrowernumber IS NOT NULL "; - # The default of 0 does not work due to foreign key constraints - # The anonymisation will fail quietly if AnonymousPatron is not a valid entry - my $anonymouspatron = (C4::Context->preference('AnonymousPatron')) ? C4::Context->preference('AnonymousPatron') : 0; - my @bind_params = ($anonymouspatron, $date); + # If there is no preference for 'AnonymousPatron' we update borrowernumber to NULL + my (@bind_params, $anonymouspatron); + if ($anonymouspatron = (C4::Context->preference('AnonymousPatron'))){ + $query .= " SET borrowernumber = ?"; + @bind_params = ($anonymouspatron, $date); + }else { + $query .= " SET borrowernumber = NULL"; + @bind_params = ($date); + } + + $query .= " WHERE returndate < ? + AND borrowernumber IS NOT NULL"; + if (defined $borrowernumber) { $query .= " AND borrowernumber = ?"; push @bind_params, $borrowernumber; -- 1.7.9.5