Lines 2120-2126
sub MarkIssueReturned {
Link Here
|
2120 |
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." |
2120 |
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." |
2121 |
unless C4::Members::GetMember( borrowernumber => $anonymouspatron ); |
2121 |
unless C4::Members::GetMember( borrowernumber => $anonymouspatron ); |
2122 |
} |
2122 |
} |
|
|
2123 |
my $database = Koha::Database->new(); |
2124 |
my $schema = $database->schema; |
2123 |
my $dbh = C4::Context->dbh; |
2125 |
my $dbh = C4::Context->dbh; |
|
|
2126 |
|
2127 |
my $issue_id = $dbh->selectrow_array( |
2128 |
q|SELECT issue_id FROM issues WHERE itemnumber = ?|, |
2129 |
undef, $itemnumber |
2130 |
); |
2131 |
|
2124 |
my $query = 'UPDATE issues SET returndate='; |
2132 |
my $query = 'UPDATE issues SET returndate='; |
2125 |
my @bind; |
2133 |
my @bind; |
2126 |
if ($dropbox_branch) { |
2134 |
if ($dropbox_branch) { |
Lines 2134-2167
sub MarkIssueReturned {
Link Here
|
2134 |
} else { |
2142 |
} else { |
2135 |
$query .= ' now() '; |
2143 |
$query .= ' now() '; |
2136 |
} |
2144 |
} |
2137 |
$query .= ' WHERE borrowernumber = ? AND itemnumber = ?'; |
2145 |
$query .= ' WHERE issue_id = ?'; |
2138 |
push @bind, $borrowernumber, $itemnumber; |
2146 |
push @bind, $issue_id; |
2139 |
# FIXME transaction |
|
|
2140 |
my $sth_upd = $dbh->prepare($query); |
2141 |
$sth_upd->execute(@bind); |
2142 |
my $sth_copy = $dbh->prepare('INSERT INTO old_issues SELECT * FROM issues |
2143 |
WHERE borrowernumber = ? |
2144 |
AND itemnumber = ?'); |
2145 |
$sth_copy->execute($borrowernumber, $itemnumber); |
2146 |
# anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber |
2147 |
if ( $privacy == 2) { |
2148 |
my $sth_ano = $dbh->prepare("UPDATE old_issues SET borrowernumber=? |
2149 |
WHERE borrowernumber = ? |
2150 |
AND itemnumber = ?"); |
2151 |
$sth_ano->execute($anonymouspatron, $borrowernumber, $itemnumber); |
2152 |
} |
2153 |
my $sth_del = $dbh->prepare("DELETE FROM issues |
2154 |
WHERE borrowernumber = ? |
2155 |
AND itemnumber = ?"); |
2156 |
$sth_del->execute($borrowernumber, $itemnumber); |
2157 |
|
2147 |
|
2158 |
ModItem( { 'onloan' => undef }, undef, $itemnumber ); |
2148 |
# FIXME Improve the return value and handle it from callers |
|
|
2149 |
$schema->txn_do(sub { |
2150 |
$dbh->do( $query, undef, @bind ); |
2159 |
|
2151 |
|
2160 |
if ( C4::Context->preference('StoreLastBorrower') ) { |
2152 |
my $id_already_exists = $dbh->selectrow_array( |
2161 |
my $item = Koha::Items->find( $itemnumber ); |
2153 |
q|SELECT COUNT(*) FROM old_issues WHERE issue_id = ?|, |
2162 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
2154 |
undef, $issue_id |
2163 |
$item->last_returned_by( $patron ); |
2155 |
); |
2164 |
} |
2156 |
|
|
|
2157 |
if ( $id_already_exists ) { |
2158 |
my $new_issue_id = $dbh->selectrow_array(q|SELECT MAX(issue_id)+1 FROM old_issues|); |
2159 |
$dbh->do( |
2160 |
q|UPDATE issues SET issue_id = ? WHERE issue_id = ?|, |
2161 |
undef, $new_issue_id, $issue_id |
2162 |
); |
2163 |
$issue_id = $new_issue_id; |
2164 |
} |
2165 |
|
2166 |
$dbh->do(q|INSERT INTO old_issues SELECT * FROM issues WHERE issue_id = ?|, undef, $issue_id); |
2167 |
|
2168 |
# anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber |
2169 |
if ( $privacy == 2) { |
2170 |
$dbh->do(q|UPDATE old_issues SET borrowernumber=? WHERE issue_id = ?|, undef, $anonymouspatron, $issue_id); |
2171 |
} |
2172 |
|
2173 |
$dbh->do(q|DELETE FROM issues WHERE issue_id = ?|, undef, $issue_id); |
2174 |
|
2175 |
ModItem( { 'onloan' => undef }, undef, $itemnumber ); |
2176 |
|
2177 |
if ( C4::Context->preference('StoreLastBorrower') ) { |
2178 |
my $item = Koha::Items->find( $itemnumber ); |
2179 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
2180 |
$item->last_returned_by( $patron ); |
2181 |
} |
2182 |
}); |
2165 |
} |
2183 |
} |
2166 |
|
2184 |
|
2167 |
=head2 _debar_user_on_return |
2185 |
=head2 _debar_user_on_return |
2168 |
- |
|
|