Bug 15530

Summary: Editing a course item via a disabled course disables it even if it is on other enabled courses
Product: Koha Reporter: Kyle M Hall (khall) <kyle>
Component: Course reservesAssignee: Kyle M Hall (khall) <kyle>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: major    
Priority: P5 - low CC: brendan, f.demians, jonathan.druart, julian.maurice, sandboxes
Version: unspecified   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Bug 15530 - Add Unit Test
Bug 15530 - Editing a course item via a disabled course disables it even if it is on other enabled courses
Bug 15530 - Add Unit Test
Bug 15530 - Editing a course item via a disabled course disables it even if it is on other enabled courses
Bug 15530 - Add Unit Test
Bug 15530 - Editing a course item via a disabled course disables it even if it is on other enabled courses
Bug 15530 - Add Unit Test
Bug 15530 - Editing a course item via a disabled course disables it even if it is on other enabled courses

Description Kyle M Hall (khall) 2016-01-08 16:59:25 UTC
It appears that if the course item is edited by clicking the edit link from an active course, the course item will be set to enabled and the fields will be swapped, if the same course item is edited from a course that is *not* active, the course item will be set to *not* enabled, and the original fields will be swapped back in!

The short term work-around is to only edit course items from an enabled course if the item has a course that is enabled. If all the courses it is on are disabled, it doesn't matter what course the item is edited from.
Comment 1 Kyle M Hall (khall) 2016-01-08 17:03:16 UTC Comment hidden (obsolete)
Comment 2 Kyle M Hall (khall) 2016-01-08 17:03:23 UTC Comment hidden (obsolete)
Comment 3 Kyle M Hall (khall) 2016-01-08 17:05:07 UTC Comment hidden (obsolete)
Comment 4 Kyle M Hall (khall) 2016-01-08 17:05:14 UTC Comment hidden (obsolete)
Comment 5 Biblibre Sandboxes 2016-01-13 18:08:15 UTC
Patch tested with a sandbox, by Margaret Holt <mholt@bastyr.edu>
Comment 6 Biblibre Sandboxes 2016-01-13 18:08:38 UTC Comment hidden (obsolete)
Comment 7 Biblibre Sandboxes 2016-01-13 18:08:41 UTC Comment hidden (obsolete)
Comment 8 Jonathan Druart 2016-01-14 11:24:38 UTC
Kyle, where is this enable/disable value used?
Comment 9 Kyle M Hall (khall) 2016-01-19 15:40:05 UTC
(In reply to Jonathan Druart from comment #8)
> Kyle, where is this enable/disable value used?

"enabled" on a course item tells us if the fields have been swapped with the actual corresponding item fields. The incorrect assumption in the code was that the "enabled" value of the course an item was on would match the "enabled" value of the course itself. This is incorrect, as the value of "enabled" should be yes if *any* course the item is on is enabled.
Comment 10 Jonathan Druart 2016-01-20 09:59:37 UTC
So if I understand correctly (not sure at all!), the course_items.enabled values could be retrieved from course_reserves.enabled?
In this case, why don't we remove this column instead of trying to keep it up-to-date?
Comment 11 Kyle M Hall (khall) 2016-01-20 11:36:13 UTC
(In reply to Jonathan Druart from comment #10)
> So if I understand correctly (not sure at all!), the course_items.enabled
> values could be retrieved from course_reserves.enabled?
> In this case, why don't we remove this column instead of trying to keep it
> up-to-date?

No, that is not quite right, here is the mapping:

courses <=> courses_reserves <=> course_items

course_reserves is a many to many join table between courses and course_items, so that a given item can be on course reserve for many courses at once.

The short answer is, if all courses a course_item is part of are disabled, then the course_item should be disabled. If *any* of the courses are enabled, the course_item should be enabled. The 'enabled' flag again tells us whether the itype, ccode, holdingbranch and/or location field have been swapped with the originals.
Comment 12 Jonathan Druart 2016-01-25 11:42:06 UTC
Created attachment 47248 [details] [review]
Bug 15530 - Add Unit Test

Signed-off-by: Margaret Holt <mholt@bastyr.edu>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 13 Jonathan Druart 2016-01-25 11:42:22 UTC
Created attachment 47249 [details] [review]
Bug 15530 - Editing a course item via a disabled course disables it even if it is on other enabled courses

It appears that if the course item is edited by clicking the edit link
from an active course, the course item will be set to enabled and the
fields will be swapped, if the same course item is edited from a course
that is *not* active, the course item will be set to *not* enabled, and
the original fields will be swapped back in!

The short term work-around is to only edit course items from an enabled
course if the item has a course that is enabled. If all the courses it
is on are disabled, it doesn't matter what course the item is edited
from.

Test Plan:
1) Create two courses, 1 enabled and 1 disabled
2) Add an item as a course reserve to both courses
3) Edit the course reserve data for the item via the enabled course
4) Note the course item is enabled ( easy way is to check the database )
5) Edit the same course reserve data, but via the disabled course
6) Note the course item is now disabled even though it is part of
   an enabled course!
7) Apply this patch
8) Repeat steps 1 through 5
9) Note the course item is still enabled

Signed-off-by: Margaret Holt <mholt@bastyr.edu>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 14 Brendan Gallagher 2016-01-27 01:02:17 UTC
Pushed to Master - Should be in the May 2016 release. - Thanks!
Comment 15 Julian Maurice 2016-01-27 14:34:46 UTC
Patches pushed to 3.22.x, will be in 3.22.3
Comment 16 Frédéric Demians 2016-02-12 06:35:02 UTC
This patch has been pushed to 3.20.x, will be in 3.20.9.