From 41397c855397aee9847943c2f124e0bdc8ba7eb7 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 18 Oct 2018 18:00:15 -0300 Subject: [PATCH] Bug 21603: Remove incorrect GROUP BY from C4::CourseReserves 'koha_kohadev.c.department' isn't in GROUP BY Test plan: Prove that the test fail without this patch and pass with this patch applied (switch on the SQL modes) Signed-off-by: Andrew Isherwood Signed-off-by: Nick Clemens --- C4/CourseReserves.pm | 8 ++++---- t/db_dependent/CourseReserves.t | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/C4/CourseReserves.pm b/C4/CourseReserves.pm index 458697960f..997f725995 100644 --- a/C4/CourseReserves.pm +++ b/C4/CourseReserves.pm @@ -966,9 +966,9 @@ sub SearchCourses { my $enabled = $params{'enabled'} || '%'; my @params; - my $query = "SELECT c.* FROM courses c"; - - $query .= " + my $query = " + SELECT c.course_id, c.department, c.course_number, c.section, c.course_name, c.term, c.staff_note, c.public_note, c.students_count, c.enabled, c.timestamp + FROM courses c LEFT JOIN course_instructors ci ON ( c.course_id = ci.course_id ) LEFT JOIN borrowers b @@ -992,7 +992,7 @@ sub SearchCourses { ) AND c.enabled LIKE ? - GROUP BY c.course_id + GROUP BY c.course_id, c.department, c.course_number, c.section, c.course_name, c.term, c.staff_note, c.public_note, c.students_count, c.enabled, c.timestamp "; $term //= ''; diff --git a/t/db_dependent/CourseReserves.t b/t/db_dependent/CourseReserves.t index 2dabc67638..42d8d1f670 100755 --- a/t/db_dependent/CourseReserves.t +++ b/t/db_dependent/CourseReserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 26; +use Test::More tests => 27; use Koha::Database; use t::lib::TestBuilder; @@ -136,4 +136,7 @@ DelCourse($course_id); $course = GetCourse($course_id); ok( !defined( $course->{'course_id'} ), "DelCourse deleted course successfully" ); +$courses = SearchCourses(); # FIXME Lack of tests for SearchCourses +is( ref($courses), 'ARRAY', 'SearchCourses should not crash and return an arrayref' ); + $schema->storage->txn_rollback; -- 2.39.5