Browse Source

Bug 30023: Make MarkIssueReturned use ->anonymize

Koha::Old::Checkout->anonymize takes care of checking the syspref and
raises an exception if not set. So no we can now leverage on it, instead
of checking manually and then tweaking the checkout object manually as
well.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Circulation/MarkIssueReturned.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
22.05.x
Tomás Cohen Arazi 2 years ago
committed by Fridolin Somers
parent
commit
42181dfce7
  1. 13
      C4/Circulation.pm
  2. 11
      t/db_dependent/Circulation/MarkIssueReturned.t

13
C4/Circulation.pm

@ -2341,17 +2341,6 @@ sub MarkIssueReturned {
my $issue_id = $issue->issue_id;
my $anonymouspatron;
if ( $privacy && $privacy == 2 ) {
# The default of 0 will not work due to foreign key constraints
# The anonymisation will fail if AnonymousPatron is not a valid entry
# We need to check if the anonymous patron exist, Koha will fail loudly if it does not
# Note that a warning should appear on the about page (System information tab).
$anonymouspatron = C4::Context->preference('AnonymousPatron');
die "Fatal error: the patron ($borrowernumber) has requested their circulation history be anonymized on check-in, but the AnonymousPatron system preference is empty or not set correctly."
unless Koha::Patrons->find( $anonymouspatron );
}
my $schema = Koha::Database->schema;
# FIXME Improve the return value and handle it from callers
@ -2372,7 +2361,7 @@ sub MarkIssueReturned {
# anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber
if ( $privacy && $privacy == 2) {
$old_checkout->borrowernumber($anonymouspatron)->store;
$old_checkout->anonymize;
}
# And finally delete the issue

11
t/db_dependent/Circulation/MarkIssueReturned.t

@ -76,7 +76,7 @@ subtest 'Failure tests' => sub {
subtest 'Anonymous patron tests' => sub {
plan tests => 2;
plan tests => 3;
$schema->storage->txn_begin;
@ -99,8 +99,13 @@ subtest 'Anonymous patron tests' => sub {
t::lib::Mocks::mock_preference( 'AnonymousPatron', '' );
my $issue = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
eval { C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ) };
like ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, 'AnonymousPatron is not set - Fatal error on anonymization' );
throws_ok
{ C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item->itemnumber, undef, 2 ); }
'Koha::Exceptions::SysPref::NotSet',
'AnonymousPatron not set causes an exception';
is( $@->syspref, 'AnonymousPatron', 'AnonymousPatron is not set - Fatal error on anonymization' );
Koha::Checkouts->find( $issue->issue_id )->delete;
# Create a valid anonymous user

Loading…
Cancel
Save