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

(-)a/C4/Circulation.pm (-6 / +22 lines)
Lines 1899-1906 sub AddReturn { Link Here
1899
                }
1899
                }
1900
            }
1900
            }
1901
1901
1902
            MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
1902
            eval {
1903
                $circControlBranch, $return_date, $borrower->{'privacy'} );
1903
                MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
1904
                    $circControlBranch, $return_date, $borrower->{'privacy'} );
1905
            };
1906
            if ( $@ ) {
1907
                $messages->{'Wrongbranch'} = {
1908
                    Wrongbranch => $branch,
1909
                    Rightbranch => $message
1910
                };
1911
                carp $@;
1912
                return ( 0, { WasReturned => 0 }, $issue, $borrower );
1913
            }
1904
1914
1905
            # FIXME is the "= 1" right?  This could be the borrower hash.
1915
            # FIXME is the "= 1" right?  This could be the borrower hash.
1906
            $messages->{'WasReturned'} = 1;
1916
            $messages->{'WasReturned'} = 1;
Lines 2075-2080 routine in C<C4::Accounts>. Link Here
2075
sub MarkIssueReturned {
2085
sub MarkIssueReturned {
2076
    my ( $borrowernumber, $itemnumber, $dropbox_branch, $returndate, $privacy ) = @_;
2086
    my ( $borrowernumber, $itemnumber, $dropbox_branch, $returndate, $privacy ) = @_;
2077
2087
2088
    my $anonymouspatron;
2089
    if ( $privacy == 2 ) {
2090
        # The default of 0 will not work due to foreign key constraints
2091
        # The anonymisation will fail if AnonymousPatron is not a valid entry
2092
        # We need to check if the anonymous patron exist, Koha will fail loudly if it does not
2093
        # Note that a warning should appear on the about page (System information tab).
2094
        $anonymouspatron = C4::Context->preference('AnonymousPatron');
2095
        die "Fatal error: the patron ($borrowernumber) has requested a privacy on returning item but the AnonymousPatron pref is not set correctly"
2096
            unless C4::Members::GetMember( borrowernumber => $anonymouspatron );
2097
    }
2078
    my $dbh   = C4::Context->dbh;
2098
    my $dbh   = C4::Context->dbh;
2079
    my $query = 'UPDATE issues SET returndate=';
2099
    my $query = 'UPDATE issues SET returndate=';
2080
    my @bind;
2100
    my @bind;
Lines 2100-2109 sub MarkIssueReturned { Link Here
2100
    $sth_copy->execute($borrowernumber, $itemnumber);
2120
    $sth_copy->execute($borrowernumber, $itemnumber);
2101
    # anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber
2121
    # anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber
2102
    if ( $privacy == 2) {
2122
    if ( $privacy == 2) {
2103
        # The default of 0 does not work due to foreign key constraints
2104
        # The anonymisation will fail quietly if AnonymousPatron is not a valid entry
2105
        # FIXME the above is unacceptable - bug 9942 relates
2106
        my $anonymouspatron = (C4::Context->preference('AnonymousPatron')) ? C4::Context->preference('AnonymousPatron') : 0;
2107
        my $sth_ano = $dbh->prepare("UPDATE old_issues SET borrowernumber=?
2123
        my $sth_ano = $dbh->prepare("UPDATE old_issues SET borrowernumber=?
2108
                                  WHERE borrowernumber = ?
2124
                                  WHERE borrowernumber = ?
2109
                                  AND itemnumber = ?");
2125
                                  AND itemnumber = ?");
(-)a/installer/data/mysql/updatedatabase.pl (+34 lines)
Lines 10595-10600 if ( CheckVersion($DBversion) ) { Link Here
10595
    SetVersion($DBversion);
10595
    SetVersion($DBversion);
10596
}
10596
}
10597
10597
10598
$DBversion = "3.21.00.XXX";
10599
if ( CheckVersion($DBversion) ) {
10600
    my $msg;
10601
    if ( C4::Context->preference('OPACPrivacy') ) {
10602
        if ( my $anonymous_patron = C4::Context->preference('AnonymousPatron') ) {
10603
            my $anonymous_patron_exists = $dbh->selectcol_arrayref(q|
10604
                SELECT COUNT(*)
10605
                FROM borrowers
10606
                WHERE borrowernumber=?
10607
            |, {}, $anonymous_patron);
10608
            unless ( $anonymous_patron_exists->[0] ) {
10609
                $msg = "Configuration WARNING: OPACPrivacy is set but AnonymousPatron is not linked to an existing patron";
10610
            }
10611
        }
10612
        else {
10613
            $msg = "Configuration WARNING: OPACPrivacy is set but AnonymousPatron is not";
10614
        }
10615
    }
10616
    else {
10617
        my $patrons_have_required_anonymity = $dbh->selectcol_arrayref(q|
10618
            SELECT COUNT(*)
10619
            FROM borrowers
10620
            WHERE privacy = 2
10621
        |, {} );
10622
        if ( $patrons_have_required_anonymity->[0] ) {
10623
            $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.";
10624
        }
10625
    }
10626
10627
    $msg //= "Privacy is correctly set";
10628
    print "Upgrade to $DBversion done (Bug 9942: $msg)\n";
10629
    SetVersion ($DBversion);
10630
}
10631
10598
# DEVELOPER PROCESS, search for anything to execute in the db_update directory
10632
# DEVELOPER PROCESS, search for anything to execute in the db_update directory
10599
# SEE bug 13068
10633
# SEE bug 13068
10600
# if there is anything in the atomicupdate, read and execute it.
10634
# if there is anything in the atomicupdate, read and execute it.
(-)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