From 0f938b2c1355de61616b8ee9412a65cfbb4e8997 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 9 Mar 2017 15:54:02 -0300 Subject: [PATCH] Bug 18242: [SOLUTION 1]Remove primary key on old_issues.issue_id The table old_issues has a primary key defined on the issue_id column. This issue_id comes from the issues table when an item is checked in. In some case the value of issue_id already exists in the table Basically this happens when an item is returned and mysqld is restarted: The auto increment value for issues.issue_id will be reset to MAX(issue_id)+1 (which is the value of the last entry of old_issues). See also the description of bug 18003 for more informations. The easier solution seems to add a new column id as a primary key. The changes to the codebase are very small. However this will raise few problems: - We can no longer assume that accountlines.issue_id==old_issues.id (I guess it is problematic). - Code in Koha::REST::V1::_object_ownership_by_checkout_id is wrong assuming that old_issues.issuing_id is unique --- C4/Circulation.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index af5acce..22906c8 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2164,9 +2164,13 @@ sub MarkIssueReturned { # FIXME transaction my $sth_upd = $dbh->prepare($query); $sth_upd->execute(@bind); - my $sth_copy = $dbh->prepare('INSERT INTO old_issues SELECT * FROM issues - WHERE borrowernumber = ? - AND itemnumber = ?'); + my $sth_copy = $dbh->prepare(q| + INSERT INTO old_issues( issue_id, borrowernumber, itemnumber, date_due, branchcode, returndate, lastreneweddate, `return`, renewals, auto_renew, timestamp, issuedate, onsite_checkout ) + SELECT issue_id, borrowernumber, itemnumber, date_due, branchcode, returndate, lastreneweddate, `return`, renewals, auto_renew, timestamp, issuedate, onsite_checkout + FROM issues + WHERE borrowernumber = ? + AND itemnumber = ? + |); $sth_copy->execute($borrowernumber, $itemnumber); # anonymise patron checkout immediately if $privacy set to 2 and AnonymousPatron is set to a valid borrowernumber if ( $privacy == 2) { -- 2.9.3