[Bug 22263] New: Command line script to populate or update items.cn_sort
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=22263 Bug ID: 22263 Summary: Command line script to populate or update items.cn_sort Change sponsored?: --- Product: Koha Version: master Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Installation and upgrade (command-line installer) Assignee: koha-bugs@lists.koha-community.org Reporter: katrin.fischer@bsz-bw.de QA Contact: testopia@bugs.koha-community.org Target Milestone: --- Sometimes cn_sort might be incorrect (wrong configuration when loading the items) or even empty (migration issue). It would be nice to have a script that allowed recalculating and updating the cn_sort field in items. This would be a maintenance script. -- 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=22263 Katrin Fischer <katrin.fischer@bsz-bw.de> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=19915 -- 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=22263 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=21447 -- 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=22263 Séverine Queune <severine.queune@bulac.fr> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |severine.queune@bulac.fr -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=22263 hannah.co@northwestu.edu changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |hannah.co@northwestu.edu -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=22263 Marjorie Barry-Vila <marjorie.barry-vila@collecto.ca> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |marjorie.barry-vila@collect | |o.ca -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=22263 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 211455 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211455&action=edit Bug 22263: Add script to recalculate items.cn_sort Koha only calculates items.cn_sort when an item is created or when its call number or classification source changes. Changing a classification source or filing rule, or a wrong configuration at migration time, leaves existing items with the old sort key, and neither saving an item nor touch_all_items.pl is a good way to fix that on a large catalogue (the latter queues an index job and writes a log entry for every item). This adds misc/maintenance/recalculate_cn_sort.pl. It recomputes the key with the current configuration, writes only the items whose key changes without logging, holds queue or per-item indexing, and queues the changed biblios for reindexing once at the end. It can be limited by classification source (NULL for items without one) or a raw WHERE clause, has a dry run mode, and reports call numbers that produce an empty key. To test: 1. Create two items with call numbers "QA 4" and "QA 90", using a classification source whose filing rule is "generic" 2. Check items.cn_sort: QA_4 and QA_90 3. Administration > Classification sources: change the filing rule of that source to "lcc" 4. Run: misc/maintenance/recalculate_cn_sort.pl --dry-run -v => the two items are listed, nothing is changed 5. Run: misc/maintenance/recalculate_cn_sort.pl --confirm => items.cn_sort is now QA0004 and QA0090 6. Run it again and confirm that nothing is changed 7. Try --cn_source with a source code, and NULL 8. prove t/db_dependent/misc/maintenance/recalculate_cn_sort.t Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> -- 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=22263 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- 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=22263 --- Comment #2 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- This patch adds misc/maintenance/recalculate_cn_sort.pl. Why a new script rather than touch_all_items.pl: touch_all_items.pl does recalculate cn_sort (it marks itemcallnumber and cn_source dirty so that Koha::Item->store recomputes the key), but it calls store with no arguments. On a large catalogue that means one cataloguing log entry (if CataloguingLog is on), one holds queue job (if RealTimeHoldsQueue is on) and, with Elasticsearch, one update_elastic_index job per item, even for items whose key does not change. This script only writes items whose key changes, passes log_action => 0, skip_record_index and skip_holds_queue, and queues the changed biblios for reindexing once at the end (--skip-indexing leaves that to rebuild_elasticsearch.pl). It can be limited with --cn_source (NULL for items with no source, which use DefaultClassificationSource exactly as at save time) and --where, has a --dry-run mode, and reports call numbers that produce an empty cn_sort. That can happen when a filing rule such as LCC cannot parse a call number, for example a Dewey-style "123.4 ABC" with the LCC rule. Background: Koha::Item->store only recomputes cn_sort for an existing item when itemcallnumber or cn_source changes (bug 23463). Changing a classification source or its filing rule therefore never reaches existing items, and saving an item or running batchRebuildItemsTables.pl does not fix that either. Related: bug 41932 (zero-padding in the Generic rule) will also leave existing items with old keys until they are recalculated, so this script should help there too. Tested in KTD: with Elasticsearch enabled, three changed biblios produced a single update_elastic_index job and no action_logs rows. Not tested against a large catalogue. -- 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=22263 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 CC| |martin.renvoize@openfifth.c | |o.uk -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org