Bug 15530 - Editing a course item via a disabled course disables it even if it is on other enabled courses
Summary: Editing a course item via a disabled course disables it even if it is on othe...
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Course reserves (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low major
Assignee: Kyle M Hall (khall)
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-08 16:59 UTC by Kyle M Hall (khall)
Modified: 2019-06-27 09:24 UTC (History)
5 users (show)

See Also:
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 (3.02 KB, patch)
2016-01-08 17:03 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 15530 - Editing a course item via a disabled course disables it even if it is on other enabled courses (3.76 KB, patch)
2016-01-08 17:03 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 15530 - Add Unit Test (2.49 KB, patch)
2016-01-08 17:05 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 15530 - Editing a course item via a disabled course disables it even if it is on other enabled courses (3.76 KB, patch)
2016-01-08 17:05 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 15530 - Add Unit Test (2.55 KB, patch)
2016-01-13 18:08 UTC, Biblibre Sandboxes
Details | Diff | Splinter Review
Bug 15530 - Editing a course item via a disabled course disables it even if it is on other enabled courses (3.82 KB, patch)
2016-01-13 18:08 UTC, Biblibre Sandboxes
Details | Diff | Splinter Review
Bug 15530 - Add Unit Test (2.61 KB, patch)
2016-01-25 11:42 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 15530 - Editing a course item via a disabled course disables it even if it is on other enabled courses (3.88 KB, patch)
2016-01-25 11:42 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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.