Bug 18651: [QA Follow-up] Fix the MAX(issue_id) calculation
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Tue, 20 Jun 2017 13:03:35 +0000 (15:03 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 20 Jun 2017 17:29:22 +0000 (14:29 -0300)
Found this by inserting the same issue_id in old_issues before checkin:
The call to ->search( )->get_column is in scalar context and will
return the number of results, i.e. always 1.
If you have an issue_id 2 in old_issues, it will crash:
    DBIx::Class::Storage::DBI::_dbh_execute(): Duplicate entry '2' for key 'PRIMARY'

The fix is fairly simple: Put get_column in list context and pick the first
array entry.
NOTE: Using DBIx's get_column()->max here might look simpler here.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
C4/Circulation.pm

index 07f1887..e25167d 100644 (file)
@@ -2186,10 +2186,11 @@ sub MarkIssueReturned {
         my $old_checkout_data = $issue->unblessed;
 
         if ( Koha::Old::Checkouts->find( $issue_id ) ) {
-            my $new_issue_id = Koha::Old::Checkouts->search(
+            my $new_issue_id = Koha::Old::Checkouts->search(
                 {},
                 { columns => [ { max_issue_id => { max => 'issue_id' } } ] }
-            )->get_column('max_issue_id') + 1;
+            )->get_column('max_issue_id') )[0];
+            $new_issue_id++;
             $issue_id = $new_issue_id;
         }
         $old_checkout_data->{issue_id} = $issue_id;