View | Details | Raw Unified | Return to bug 9942
Collapse All | Expand All

(-)a/C4/Circulation.pm (-6 / +22 lines)
Lines 1892-1899 sub AddReturn { Link Here
1892
                }
1892
                }
1893
            }
1893
            }
1894
1894
1895
            MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
1895
            eval {
1896
                $circControlBranch, $return_date, $borrower->{'privacy'} );
1896
                MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
1897
                    $circControlBranch, $return_date, $borrower->{'privacy'} );
1898
            };
1899
            if ( $@ ) {
1900
                $messages->{'Wrongbranch'} = {
1901
                    Wrongbranch => $branch,
1902
                    Rightbranch => $message
1903
                };
1904
                carp $@;
1905
                return ( 0, { WasReturned => 0 }, $issue, $borrower );
1906
            }
1897
1907
1898
            # FIXME is the "= 1" right?  This could be the borrower hash.
1908
            # FIXME is the "= 1" right?  This could be the borrower hash.
1899
            $messages->{'WasReturned'} = 1;
1909
            $messages->{'WasReturned'} = 1;
Lines 2071-2076 routine in C<C4::Accounts>. Link Here
2071
sub MarkIssueReturned {
2081
sub MarkIssueReturned {
2072
    my ( $borrowernumber, $itemnumber, $dropbox_branch, $returndate, $privacy ) = @_;
2082
    my ( $borrowernumber, $itemnumber, $dropbox_branch, $returndate, $privacy ) = @_;
2073
2083
2084
    my $anonymouspatron;
2085
    if ( $privacy == 2 ) {
2086
        # The default of 0 will not work due to foreign key constraints
2087
        # The anonymisation will fail if AnonymousPatron is not a valid entry
2088
        # We need to check if the anonymous patron exist, Koha will fail loudly if it does not
2089
        # Note that a warning should appear on the about page (System information tab).
2090
        $anonymouspatron = C4::Context->preference('AnonymousPatron');
2091
        die "Fatal error: the patron ($borrowernumber) has requested a privacy on returning item but the AnonymousPatron pref is not set correctly"
2092
            unless C4::Members::GetMember( borrowernumber => $anonymouspatron );
2093
    }
2074
    my $dbh   = C4::Context->dbh;
2094
    my $dbh   = C4::Context->dbh;
2075
    my $query = 'UPDATE issues SET returndate=';
2095
    my $query = 'UPDATE issues SET returndate=';
2076
    my @bind;
2096
    my @bind;
Lines 2096-2105 sub MarkIssueReturned { Link Here
2096
    $sth_copy->execute($borrowernumber, $itemnumber);
2116
    $sth_copy->execute($borrowernumber, $itemnumber);
2097
    # anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber
2117
    # anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber
2098
    if ( $privacy == 2) {
2118
    if ( $privacy == 2) {
2099
        # The default of 0 does not work due to foreign key constraints
2100
        # The anonymisation will fail quietly if AnonymousPatron is not a valid entry
2101
        # FIXME the above is unacceptable - bug 9942 relates
2102
        my $anonymouspatron = (C4::Context->preference('AnonymousPatron')) ? C4::Context->preference('AnonymousPatron') : 0;
2103
        my $sth_ano = $dbh->prepare("UPDATE old_issues SET borrowernumber=?
2119
        my $sth_ano = $dbh->prepare("UPDATE old_issues SET borrowernumber=?
2104
                                  WHERE borrowernumber = ?
2120
                                  WHERE borrowernumber = ?
2105
                                  AND itemnumber = ?");
2121
                                  AND itemnumber = ?");
(-)a/installer/data/mysql/updatedatabase.pl (+33 lines)
Lines 9978-9983 if ( CheckVersion($DBversion) ) { Link Here
9978
    SetVersion($DBversion);
9978
    SetVersion($DBversion);
9979
}
9979
}
9980
9980
9981
$DBversion = "3.19.00.XXX";
9982
if ( CheckVersion($DBversion) ) {
9983
    my $msg;
9984
    if ( C4::Context->preference('OPACPrivacy') ) {
9985
        if ( my $anonymous_patron = C4::Context->preference('AnonymousPatron') ) {
9986
            my $anonymous_patron_exists = $dbh->selectcol_arrayref(q|
9987
                SELECT COUNT(*)
9988
                FROM borrowers
9989
                WHERE borrowernumber=?
9990
            |, {}, $anonymous_patron);
9991
            unless ( $anonymous_patron_exists->[0] ) {
9992
                $msg = "Configuration WARNING: OPACPrivacy is set but AnonymousPatron is not linked to an existing patron";
9993
            }
9994
        }
9995
        else {
9996
            $msg = "Configuration WARNING: OPACPrivacy is set but AnonymousPatron is not";
9997
        }
9998
    }
9999
    else {
10000
        my $patrons_have_required_anonymity = $dbh->selectcol_arrayref(q|
10001
            SELECT COUNT(*)
10002
            FROM borrowers
10003
            WHERE privacy = 2
10004
        |, {} );
10005
        if ( $patrons_have_required_anonymity->[0] ) {
10006
            $msg = "Configuration WARNING: OPACPrivacy is not set but $patrons_have_required_anonymity->[0] patrons have required anonymity (perhaps in a previous configuration). You should fix that asap.";
10007
        }
10008
    }
10009
10010
    $msg //= "Privacy is correctly set";
10011
    print "Upgrade to $DBversion done (Bug 9942: $msg\n";
10012
    SetVersion ($DBversion);
10013
}
9981
10014
9982
# DEVELOPER PROCESS, search for anything to execute in the db_update directory
10015
# DEVELOPER PROCESS, search for anything to execute in the db_update directory
9983
# SEE bug 13068
10016
# SEE bug 13068
(-)a/t/db_dependent/Circulation/MarkIssueReturned.t (-1 / +55 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 2;
21
use Test::Warn;
22
23
use C4::Branch;
24
use C4::Circulation;
25
use C4::Members;
26
use t::lib::Mocks;
27
28
my $dbh = C4::Context->dbh;
29
$dbh->{AutoCommit} = 0;
30
$dbh->{RaiseError} = 1;
31
32
t::lib::Mocks::mock_preference('AnonymousPatron', '');
33
34
my $branchcode = 'B';
35
ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
36
37
my $categorycode = 'C';
38
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
39
40
my %item_branch_infos = (
41
    homebranch => $branchcode,
42
    holdingbranch => $branchcode,
43
);
44
45
my $borrowernumber = AddMember( categorycode => $categorycode, branchcode => $branchcode );
46
47
eval { C4::Circulation::MarkIssueReturned( $borrowernumber, 'itemnumber', 'dropbox_branch', 'returndate', 2 ) };
48
like ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, );
49
50
my $anonymous_borrowernumber = AddMember( categorycode => $categorycode, branchcode => $branchcode );
51
t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_borrowernumber);
52
# The next call will raise an error, because data are not correctly set
53
$dbh->{PrintError} = 0;
54
eval { C4::Circulation::MarkIssueReturned( $borrowernumber, 'itemnumber', 'dropbox_branch', 'returndate', 2 ) };
55
unlike ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, );

Return to bug 9942