Lines 2145-2151
sub MarkIssueReturned {
Link Here
|
2145 |
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." |
2145 |
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." |
2146 |
unless C4::Members::GetMember( borrowernumber => $anonymouspatron ); |
2146 |
unless C4::Members::GetMember( borrowernumber => $anonymouspatron ); |
2147 |
} |
2147 |
} |
|
|
2148 |
my $database = Koha::Database->new(); |
2149 |
my $schema = $database->schema; |
2148 |
my $dbh = C4::Context->dbh; |
2150 |
my $dbh = C4::Context->dbh; |
|
|
2151 |
|
2152 |
my $issue_id = $dbh->selectrow_array( |
2153 |
q|SELECT issue_id FROM issues WHERE itemnumber = ?|, |
2154 |
undef, $itemnumber |
2155 |
); |
2156 |
|
2149 |
my $query = 'UPDATE issues SET returndate='; |
2157 |
my $query = 'UPDATE issues SET returndate='; |
2150 |
my @bind; |
2158 |
my @bind; |
2151 |
if ($dropbox_branch) { |
2159 |
if ($dropbox_branch) { |
Lines 2159-2192
sub MarkIssueReturned {
Link Here
|
2159 |
} else { |
2167 |
} else { |
2160 |
$query .= ' now() '; |
2168 |
$query .= ' now() '; |
2161 |
} |
2169 |
} |
2162 |
$query .= ' WHERE borrowernumber = ? AND itemnumber = ?'; |
2170 |
$query .= ' WHERE issue_id = ?'; |
2163 |
push @bind, $borrowernumber, $itemnumber; |
2171 |
push @bind, $issue_id; |
2164 |
# FIXME transaction |
2172 |
|
2165 |
my $sth_upd = $dbh->prepare($query); |
2173 |
# FIXME Improve the return value and handle it from callers |
2166 |
$sth_upd->execute(@bind); |
2174 |
$schema->txn_do(sub { |
2167 |
my $sth_copy = $dbh->prepare('INSERT INTO old_issues SELECT * FROM issues |
2175 |
$dbh->do( $query, undef, @bind ); |
2168 |
WHERE borrowernumber = ? |
2176 |
|
2169 |
AND itemnumber = ?'); |
2177 |
my $id_already_exists = $dbh->selectrow_array( |
2170 |
$sth_copy->execute($borrowernumber, $itemnumber); |
2178 |
q|SELECT COUNT(*) FROM old_issues WHERE issue_id = ?|, |
2171 |
# anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber |
2179 |
undef, $issue_id |
2172 |
if ( $privacy == 2) { |
2180 |
); |
2173 |
my $sth_ano = $dbh->prepare("UPDATE old_issues SET borrowernumber=? |
2181 |
|
2174 |
WHERE borrowernumber = ? |
2182 |
if ( $id_already_exists ) { |
2175 |
AND itemnumber = ?"); |
2183 |
my $new_issue_id = $dbh->selectrow_array(q|SELECT MAX(issue_id)+1 FROM old_issues|); |
2176 |
$sth_ano->execute($anonymouspatron, $borrowernumber, $itemnumber); |
2184 |
$dbh->do( |
2177 |
} |
2185 |
q|UPDATE issues SET issue_id = ? WHERE issue_id = ?|, |
2178 |
my $sth_del = $dbh->prepare("DELETE FROM issues |
2186 |
undef, $new_issue_id, $issue_id |
2179 |
WHERE borrowernumber = ? |
2187 |
); |
2180 |
AND itemnumber = ?"); |
2188 |
$issue_id = $new_issue_id; |
2181 |
$sth_del->execute($borrowernumber, $itemnumber); |
2189 |
} |
2182 |
|
2190 |
|
2183 |
ModItem( { 'onloan' => undef }, undef, $itemnumber ); |
2191 |
$dbh->do(q|INSERT INTO old_issues SELECT * FROM issues WHERE issue_id = ?|, undef, $issue_id); |
2184 |
|
2192 |
|
2185 |
if ( C4::Context->preference('StoreLastBorrower') ) { |
2193 |
# anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber |
2186 |
my $item = Koha::Items->find( $itemnumber ); |
2194 |
if ( $privacy == 2) { |
2187 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
2195 |
$dbh->do(q|UPDATE old_issues SET borrowernumber=? WHERE issue_id = ?|, undef, $anonymouspatron, $issue_id); |
2188 |
$item->last_returned_by( $patron ); |
2196 |
} |
2189 |
} |
2197 |
|
|
|
2198 |
$dbh->do(q|DELETE FROM issues WHERE issue_id = ?|, undef, $issue_id); |
2199 |
|
2200 |
ModItem( { 'onloan' => undef }, undef, $itemnumber ); |
2201 |
|
2202 |
if ( C4::Context->preference('StoreLastBorrower') ) { |
2203 |
my $item = Koha::Items->find( $itemnumber ); |
2204 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
2205 |
$item->last_returned_by( $patron ); |
2206 |
} |
2207 |
}); |
2190 |
} |
2208 |
} |
2191 |
|
2209 |
|
2192 |
=head2 _debar_user_on_return |
2210 |
=head2 _debar_user_on_return |
2193 |
- |
|
|