[Bug 43492] New: Normalize library opening hours into a dedicated library_opening_hours table
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 Bug ID: 43492 Summary: Normalize library opening hours into a dedicated library_opening_hours table Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Architecture, internals, and plumbing Assignee: koha-bugs@lists.koha-community.org Reporter: martin.renvoize@openfifth.co.uk QA Contact: testopia@bugs.koha-community.org Target Milestone: --- Library opening hours (Bug 6796) are stored in a single library_hours table with a composite (library_id, day) primary key: exactly one row per weekday per library. This makes it structurally impossible to record more than one opening/closing pair per day (Bug 37616, Bug 37708), and there is no way to represent hours that open on one day and don't close again until a later day (raised as a concern on Bug 36596 against a simple "open and close must always be set together" rule). The Koha::Library::Hour(s) object classes are empty shims with no validation, and there is no relationship at all between these hours and the library Calendar (weekly/repeating/single closures, Bug 42310/42314/42311), which is the underlying problem in Bug 36079. This is the first of a small dependent series that replaces library_hours with a normalized model. This bug covers the schema and object layer: - A new library_opening_hours table, allowing any number of rows per (library, weekday), with an explicit closes_opening_id self-reference so a slot that opens on one day and doesn't close until a later day is represented as two clearly linked rows rather than by guesswork or an offset column. - A new OPENING_HOURS_TYPE authorised value category (seeded with a reserved GENERAL value) so hours can be grouped by what they're for (Bug 37708), reusing Koha's existing authorised values admin screen rather than a bespoke vocabulary. - A Koha::Library::OpeningHours facade (mirroring Koha::Library::Calendar) providing validated CRUD and interval resolution. Migration of existing library_hours data to type GENERAL is included. Follow-up bugs build the Koha::Library accessor and Calendar linkage, REST API, circulation integration, and the admin interface on top of this. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |43493 Blocks| |43494 Blocks| |43495 Blocks| |43496 Depends on| |6796 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=6796 [Bug 6796] Overnight checkouts taking into account opening and closing hours https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43493 [Bug 43493] Link Koha::Library opening hours with the library Calendar https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43494 [Bug 43494] Add REST API endpoints for library opening hours https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43495 [Bug 43495] Use the new opening hours facade in circulation due date calculations https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43496 [Bug 43496] Rework the library opening hours administration interface -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Expanding the scope of this bug: it now also covers reworking the admin interface for editing GENERAL opening hours (previously split out as Bug 43496), so that this single patch is a complete, librarian-testable feature end to end - a librarian can add multiple opening-hours time ranges per day, including one that does not close until a later day, and see them persist - rather than schema/object-layer plumbing with nothing to click through. Bug 43496 is being closed as a duplicate of this one; its scope is folded in here. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks|43495, 43496 | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43495 [Bug 43495] Use the new opening hours facade in circulation due date calculations https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43496 [Bug 43496] Rework the library opening hours administration interface -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |martin.renvoize@openfifth.c |ity.org |o.uk Status|NEW |Needs Signoff Patch complexity|--- |Medium patch -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #2 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205323 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205323&action=edit Bug 43492: Add library_opening_hours table and OPENING_HOURS_TYPE authorised value Adds the library_opening_hours table (surrogate PK, multiple rows per library/weekday allowed, an explicit closes_opening_id self-reference for slots that open on one day and don't close until a later day) alongside the existing library_hours table, and seeds a new OPENING_HOURS_TYPE authorised value category with its reserved GENERAL value. library_hours is intentionally left untouched here - C4::Circulation still reads it directly until Bug 43495 migrates that consumer and drops it, so the two tables coexist until then. Test plan: 1. Apply this patch and run the atomicupdate: ktd --shell --run 'perl installer/data/mysql/updatedatabase.pl' Confirm the library_opening_hours table, the OPENING_HOURS_TYPE category and its GENERAL value are created, and library_hours is untouched. 2. Confirm a fresh install (kohastructure.sql) produces the same result. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #3 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205324 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205324&action=edit Bug 43492: DBIC schema update Automated schema update following the addition of the library_opening_hours table. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #4 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205325 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205325&action=edit Bug 43492: DBIC schema manual updates Adds koha_object_class/koha_objects_class aliases below the DBIC Schema::Loader marker, matching the pattern used for the library calendar closures tables in Bug 42310. No tinyint(1) columns were added by this bug, so no is_boolean flags are needed. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #5 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205326 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205326&action=edit Bug 43492: Add Koha::Library::OpeningHours object classes Adds Koha::Library::OpeningHours::Slot / Slots (Koha::Object(s) over library_opening_hours, validating weekday range, the open/close/link combination, and the type against OPENING_HOURS_TYPE) and the Koha::Library::OpeningHours facade (mirroring Koha::Library::Calendar), which resolves closes_opening_id links and per-type fallback into plain weekly intervals for is_open_at/next_change. Koha::Library->opening_hours and Calendar-aware availability checks are added in Bug 43493. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #6 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205327 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205327&action=edit Bug 43492: Unit tests Covers weekday/open-close/type validation, same-day and overnight resolution, linked multi-day spans via closes_opening_id, permanently-open (unterminated) slots, is_open_at/next_change, and the per-type fallback/isolation rule. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #7 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205328 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205328&action=edit Bug 43492: Rework the library opening hours administration interface Reworks the Administration > Libraries edit/view screens to support any number of time ranges per weekday for the GENERAL opening hours type, replacing the fixed one-row-per-weekday library_hours editor. - admin/branches.pl: adds a Koha::Library->opening_hours accessor and replaces the old day[]/open_time[]/close_time[] handling (which wrote directly to Koha::Library::Hour(s)) with a full replace-on-save of the library's GENERAL type slots via the new facade. Other opening hours types are untouched here - they're managed via the API (Bug 43494). - branches.tt: each weekday now renders zero or more slot rows plus an "Add another time range" control; a slot whose close time is not after its open time is accepted as closing the next day (no separate control needed - this falls straight out of the facade's own rule). Also fixes a pre-existing typo ("noEnerSubmit") that meant close_time inputs never actually got the enter-key-submit guard. - Koha::Library.pm: adds the opening_hours() accessor itself (the Calendar-aware composition on top of it lands in Bug 43493). Note: until Bug 43493 migrates C4::Circulation::CalcDateDue onto the new facade, hours entered through this updated form do not yet affect due date calculations - CalcDateDue still reads the legacy library_hours table directly. Likewise, the libraries list page's "Library hours" preview column still reads library_hours via the existing REST API embed and will not reflect hours entered here until Bug 43494 lands the typed embed. Also verified in-browser that Bug 37456's reported issue (unable to type times directly) no longer reproduces - the flatpickr time-only fields already accept typed input. Test plan: 1. Apply this patch and restart_all. 2. Administration > Libraries > edit a library. 3. Add several time ranges to a weekday, including one where the close time is earlier than the open time (e.g. 22:00-02:00). 4. Save. Reload the edit page and the view page: all ranges should be present and correctly grouped by weekday. 5. Remove a range and re-save: it should no longer be listed or stored. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |ASSIGNED -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #8 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Further expanding this bug's scope after testing surfaced two problems with splitting the migration and CalcDateDue switch into a separate bug (43493): 1. Between this bug landing and 43493 landing, existing library_hours data would vanish from the admin UI (which only reads the new table) while CalcDateDue kept silently reading the old, now-unedited data - a worse intermediate state than either bug alone intended. 2. Editing hours via the new UI would not affect circulation due date calculations until 43493 landed, and the two data sets could drift. Matching how Bug 42310 actually handled this (normalize the schema and migrate its consumer together, in the same bug), this bug now also: - Migrates library_hours data into library_opening_hours (complete open/close pairs only - a row with only one of the two set never had a usable meaning under the old model) and drops library_hours. - Switches C4::Circulation::CalcDateDue onto the new facade, removing Koha::Library::Hour(s) entirely. - Adds a type dropdown to the admin UI (populated from the OPENING_HOURS_TYPE authorised value category), so a slot's purpose can be set without the API. A safety net (Koha::Library::OpeningHours->unlinked_slots) means this simple per-row editor never touches a multi-day closes_opening_id-linked span it has no controls for - those remain API-only. - Adds a minimal typed library_opening_hours embed on /libraries (pulled forward from Bug 43494), since the libraries admin list page's "Library hours" column depends on it and would otherwise be left broken. Bug 43493 is now scoped down to just the Calendar-linkage piece (Koha::Library->opening_hours composing with ->calendar, resolving Bug 36079) on top of an already-complete opening hours system. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #205323|0 |1 is obsolete| | Attachment #205324|0 |1 is obsolete| | Attachment #205325|0 |1 is obsolete| | Attachment #205326|0 |1 is obsolete| | Attachment #205327|0 |1 is obsolete| | Attachment #205328|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #9 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205370 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205370&action=edit Bug 43492: Add library_opening_hours table and OPENING_HOURS_TYPE authorised value Adds the library_opening_hours table (surrogate PK, multiple rows per library/weekday allowed, an explicit closes_opening_id self-reference for slots that open on one day and don't close until a later day), seeds a new OPENING_HOURS_TYPE authorised value category with its reserved GENERAL value, and migrates library_hours data into the new table (complete open/close pairs only - a row with only one of the two set never had a usable meaning under the old model, and is not the same thing as a new-model open-ended slot), dropping library_hours once migrated. Test plan: 1. Apply this patch and run the atomicupdate: ktd --shell --run 'perl installer/data/mysql/updatedatabase.pl' Confirm the library_opening_hours table, the OPENING_HOURS_TYPE category and its GENERAL value are created, existing library_hours data is migrated across, and library_hours is dropped. 2. Confirm a fresh install (kohastructure.sql) produces the same result. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #10 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205371 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205371&action=edit Bug 43492: DBIC schema update Automated schema update following the addition of the library_opening_hours table and removal of library_hours. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #12 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205373 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205373&action=edit Bug 43492: Add Koha::Library::OpeningHours object classes Adds Koha::Library::OpeningHours::Slot / Slots (Koha::Object(s) over library_opening_hours, validating weekday range, the open/close/link combination, and the type against OPENING_HOURS_TYPE) and the Koha::Library::OpeningHours facade (mirroring Koha::Library::Calendar), which resolves closes_opening_id links and per-type fallback into plain weekly intervals for is_open_at/next_change/next_open/previous_close. unlinked_slots() supports simple (non-multi-day-linked) editors, such as the admin UI added later in this bug, without risking corruption of closes_opening_id-linked spans they don't have controls for. Calendar-aware availability checks (consulting Koha::Library->calendar) are added in Bug 43493. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #13 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205374 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205374&action=edit Bug 43492: Unit tests Covers weekday/open-close/type validation, same-day and overnight resolution, linked multi-day spans via closes_opening_id, permanently-open (unterminated) slots, is_open_at/next_change/next_open/previous_close, the per-type fallback/isolation rule, and unlinked_slots. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #14 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205375 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205375&action=edit Bug 43492: Add Koha::Library opening hours accessors, remove Koha::Library::Hour(s) Adds Koha::Library->opening_hours (the facade, for querying/managing hours) and Koha::Library->library_opening_hours (a plain Koha::Objects accessor over all of a library's slots, mirroring the shape of the old library_hours accessor - used for the REST API embed). Removes the now-unused Koha::Library->library_hours accessor and the Koha::Library::Hour(s) classes entirely, following how Bug 42310 fully replaced the old Koha::Calendar namespace rather than keeping a compat shim. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #15 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205376 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205376&action=edit Bug 43492: Switch CalcDateDue onto Koha::Library::OpeningHours C4::Circulation::CalcDateDue was the only functional consumer of library_hours: for hourly loan periods it looked up today's/tomorrow's Koha::Library::Hours row directly and snapped the due time to open_time/close_time depending on ConsiderLibraryHoursInCirculation, with the snap-target hardcoded from those two single rows. Replaces that direct table access with Koha::Library->opening_hours (is_open_at/next_open/previous_close), preserving the exact same close/open/ignore branching and calendar-duration handling as before, but now correctly handling multiple slots per day and slots that cross midnight (previously unrepresentable at all) - covered by new overnight test cases in CalcDateDue.t alongside the full existing suite, which still passes unchanged, confirming behaviour is preserved for the existing single-slot-per-day cases. Calendar-aware availability (consulting Koha::Library->calendar, for Bug 36079) is added in Bug 43493 - CalcDateDue benefits from it automatically once that lands, since it calls the same facade methods. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #16 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205377 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205377&action=edit Bug 43492: Add a typed library_opening_hours embed on /libraries The old library_hours embed (an untyped array with no items schema) is replaced with library_opening_hours, backed by the new Koha::Library->library_opening_hours accessor and a proper library_opening_hour definition, so /libraries and /libraries/{id} responses carry every opening hours slot (any type) with a real schema instead of an opaque array. This is a minimal slice of what will become the fuller REST API in Bug 43494 (dedicated CRUD endpoints) - pulled forward here because the libraries admin list page's "Library hours" column depends on it, and that page would otherwise be left showing stale/broken data once library_hours (and its embed) no longer exist. Requires `yarn build && restart_all` for the rebuilt OpenAPI spec to take effect. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 --- Comment #17 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205378 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205378&action=edit Bug 43492: Rework the library opening hours administration interface Reworks the Administration > Libraries edit/view screens to support any number of time ranges per weekday, each with its own type, replacing the fixed one-row-per-weekday library_hours editor. - admin/branches.pl: replaces the old day[]/open_time[]/close_time[] handling (which wrote directly to Koha::Library::Hour(s)) with a full replace-on-save of the library's "simple" slots (see Koha::Library::OpeningHours->unlinked_slots) via the new facade. Slots that are part of a closes_opening_id link (open on one day, close on a later one) are never touched by this editor - they can only be created/edited via the API, so this simple per-row form can't corrupt a link it has no controls for. - branches.tt: each weekday now renders zero or more slot rows (day, type, open time, close time) plus an "Add another time range" control; a slot whose close time is not after its open time is accepted as closing the next day. The type dropdown is populated from the OPENING_HOURS_TYPE authorised value category via the existing AuthorisedValues plugin - no bespoke vocabulary UI needed. Also fixes a pre-existing typo ("noEnerSubmit") that meant close_time inputs never actually got the enter-key-submit guard, and updates the libraries list page's DataTable to read the new typed library_opening_hours embed (Bug 43492's REST commit), filtering to the GENERAL type and grouping potentially-multiple slots per weekday. Also verified in-browser that Bug 37456's reported issue (unable to type times directly) no longer reproduces - the flatpickr time-only fields already accept typed input. Test plan: 1. Apply this patch, run `yarn build`, and restart_all. 2. Administration > Libraries > edit a library. 3. Add several time ranges to a weekday, including one where the close time is earlier than the open time (e.g. 22:00-02:00), and at least one with a non-GENERAL type (add one via Administration > Authorized values > OPENING_HOURS_TYPE first). 4. Save. Reload the edit page and the view page: all ranges should be present, correctly grouped by weekday, with the right type selected. 5. Remove a range and re-save: it should no longer be listed or stored. 6. Via the API or a Perl one-liner, create a slot that opens on one day and doesn't close until a later one (closes_opening_id). Confirm it does NOT appear in this form, and re-saving the form leaves it completely untouched. 7. Confirm the libraries list page's "Library hours" column still shows each library's GENERAL hours correctly. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |43506 Blocks| |43507 Blocks| |37708 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=37708 [Bug 37708] Library hours should be extended to allow for multiple opening times per day include what the libary is open for https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43506 [Bug 43506] Add a way to copy opening hours from one library to another https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43507 [Bug 43507] Add date-specific and annually-repeating opening hours overrides -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |tomascohen@gmail.com --- Comment #18 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- *** Bug 36596 has been marked as a duplicate of this bug. *** -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43492 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks|43506 | Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43506 [Bug 43506] Add a way to copy opening hours from one library to another -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org