Go to file
Martin Renvoize 61f0432e9d
Bug 34000: Prevent re-issuance of auto-generated cardnumbers
When autoMemberNum is enabled, Koha picks the next cardnumber as
MAX(numeric cardnumber in borrowers) + 1. If patron A's auto-generated
cardnumber is later changed (e.g. they get a physical card) or the
patron is deleted, the original number becomes "free" and the next
self-registrant is assigned it -- inheriting anything third-party
services (OverDrive, Hoopla, unauthenticated self-check) have keyed on
the cardnumber.

This patch makes Koha::Patron::fixup_cardnumber use a monotonic counter
(the autoMemberNumValue syspref) so that once a number has been
auto-generated for any patron, it is never auto-generated again.

The syspref row is locked with SELECT ... FOR UPDATE inside the
existing txn_do, which serialises concurrent callers via InnoDB
row-level locking and addresses the race condition raised against
earlier revisions of this patch.

The formula is: next = MAX(counter, db_max) + 1. When the counter is 0
(pre-upgrade or missing syspref), this degrades gracefully to
db_max + 1 -- the legacy behaviour -- so no feature toggle is needed.
The counter is only bumped when Koha actually auto-generates a
cardnumber; plugin- or caller-supplied values do not touch it.

Test plan:
1. Enable autoMemberNum.
2. Self-register patron A via OPAC, note cardnumber N.
3. Edit patron A in the staff interface, change cardnumber to
   something non-numeric like "MANUAL-XYZ".
4. Self-register patron B.
5. Confirm B gets N+1, NOT N.
6. Delete patron A.
7. Self-register patron C.
8. Confirm C gets N+2, NOT A's original number.
9. Install a plugin implementing the patron_barcode_transform hook;
   confirm it still runs and its value is honoured (counter is not
   bumped when the plugin supplies a cardnumber).

Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-04-28 15:48:22 -06:00
.github/workflows Bug 40027: Use GitHub workflow to automatically close PRs opened on the Koha repo there 2025-10-06 09:15:26 -06:00
C4 Bug 42136: prevent cgi, directory, and file plugins from use in user-entered templates 2026-04-28 15:48:20 -06:00
Koha Bug 34000: Prevent re-issuance of auto-generated cardnumbers 2026-04-28 15:48:22 -06:00
acqui Bug 41454: Remove unused dbh calls 2026-04-15 09:14:51 -06:00
admin Bug 42156: Add a stdno index for authid 2026-04-23 09:25:03 -06:00
api Bug 41311: Add ability for SIP to send patron home library ( branchcode ) in AO field 2026-04-23 16:04:07 -06:00
authorities Bug 21453: Copy data to the correct subfields when linking authorities with authorities 2026-04-23 09:24:58 -06:00
basket Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
bin Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
bookings Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
catalogue Bug 42107: Add search scores to staff results page 2026-04-15 11:37:12 -06:00
cataloguing Bug 42221: Fix EAN-13 autoBarcode not incrementing 2026-04-16 15:54:09 -06:00
circ Bug 35267: Apply preferences to preview and mailing 2026-04-17 09:18:06 -06:00
clubs Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
course_reserves Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
debian Bug 42366: Fix debug_mode test for koha-conf.xml 2026-04-28 15:48:12 -06:00
docs Bug 41319: Automate sponsor tracking from git trailers 2026-03-05 08:33:44 -07:00
erm Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
errors Bug 28146: Respect ReplytoDefault in error pages 2025-10-09 14:58:41 -06:00
etc Bug 39789: (QA follow-up) fix redundancy in koha-conf.xml 2026-04-23 16:04:06 -06:00
ill Bug 40504: Add 'managedby' to illrequests 2026-03-26 14:21:22 +01:00
installer Bug 34000: Add autoMemberNumValue system preference 2026-04-28 15:48:21 -06:00
koha-tmpl Bug 42253: (QA follow-up) prevent XSS injection in data- attribute 2026-04-28 15:48:20 -06:00
labels Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
lib Bug 41521: Silent perlcritic warnings 2026-03-24 09:55:54 +01:00
members Bug 35267: Migrate accounts_summary to printslip 2026-04-17 09:18:07 -06:00
misc Bug 41062: Add an option to erm_run_harvester.pl to specify provider IDs 2026-04-23 09:24:47 -06:00
offline_circ Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac Bug 40659: (follow-up) Use UI language for custom virtual card layout 2026-04-23 16:04:13 -06:00
patron_lists Bug 32176: Remove duplicated code to select patron from autocomplete 2025-10-31 15:26:25 -06:00
patroncards Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
plugins Bug 25952: Skip invalid repositories when searching for plugins 2025-11-21 08:41:52 -07:00
pos Bug 41585: Fix cash refund payouts not appearing in register transactions 2026-03-21 17:26:44 +00:00
preservation Bug 35267: Apply preferences to preview and mailing 2026-04-17 09:18:06 -06:00
recalls Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
reports Bug 42190: Add "Back to normal view" 2026-04-24 11:43:21 -06:00
reserve Bug 23269: (follow-up) Cleanup code 2026-03-21 20:28:14 +00:00
reviews Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
rotating_collections Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
serials Bug 36466: (follow-up) Use NULL for blank planned and published dates instead of today 2026-02-06 15:17:33 -07:00
services Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
sip2 Bug 37893: Fix http links 2025-11-18 11:21:20 -07:00
skel
…
suggestion Bug 42071: Add 'show' to options that load a single suggestion 2026-03-12 15:19:46 -06:00
svc Bug 38136: Refactor database translations (alternative) 2026-04-15 11:37:14 -06:00
t Bug 42136: Add tests 2026-04-28 15:48:21 -06:00
tags Bug 41076: Adjust our perl tidiness for v20250105 2026-02-05 09:03:51 -07:00
tools Bug 40659: (follow-up) include substitutions in the possible options for template 2026-04-23 16:04:12 -06:00
virtualshelves Bug 40916: Fix another occurance 2025-10-06 09:15:22 -06:00
xt Bug 41216: Adjust POD 2026-04-10 09:48:10 -06:00
.codespell-ignore Bug 40950: Add 'falsy' programming idiom to codespell dictionary 2025-10-06 09:15:23 -06:00
.editorconfig
…
.git-blame-ignore-revs Bug 39096: Add 'tidy all' commits to a git blame ignore file 2025-02-17 13:10:25 +01:00
.gitignore Bug 40383: (follow-up) Add css files to gitignore 2026-04-13 14:56:34 +01:00
.htaccess
…
.mailmap Bug 40041: (follow-up) Fix periods and add Robert Fox 2025-12-05 09:29:04 -07:00
.nvmrc Bug 42353: Store the node version in .nvmrc 2026-04-15 09:14:53 -06:00
.perlcriticrc
…
.perltidyrc
…
.prettierrc.js Bug 38664: Treat .vue files like other JS files 2025-02-11 14:58:25 +01:00
.proverc.dist
…
.stylelintrc.json
…
INSTALL
…
Koha.pm Bug 42447: DBRev 25.12.00.051 2026-04-24 11:43:24 -06:00
LICENSE Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
MANIFEST.SKIP
…
Makefile.PL Bug 41076: Adjust our perl tidiness for v20250105 2026-02-05 09:03:51 -07:00
README
…
README.md Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
README.robots
…
SECURITY.md Bug 40527: Initial draft of SECURITY.md 2025-10-09 14:58:41 -06:00
about.pl Bug 39789: Display the trusted proxy IP addresses and reverse proxy IP header on about page 2026-04-23 16:04:05 -06:00
app.psgi Bug 38365: Integrate CSP middleware into Plack apps 2026-03-16 11:57:12 +01:00
build-resources.PL Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
changelanguage.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
cpanfile Bug 41521: Remove deps from cpanfile 2026-03-24 09:55:53 +01:00
cypress.config.ts Bug 41362: Allow Cypress tests to use KOHA_USER and KOHA_PASS as override 2026-01-06 07:45:35 -07:00
eslint.config.mjs Bug 38524: Enable ESLint for .ts and .vue files 2025-01-16 15:56:17 +01:00
fix-perl-path.PL Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
gulpfile.js Bug 42356: Silence Sass if-function deprecation warning 2026-04-17 09:18:15 -06:00
help.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
kohaversion.pl Bug 38664: Tidy the whole codebase 2025-02-11 14:58:24 +01:00
mainpage.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
package.json Bug 41587: (follow-up) Fix js-yaml version conflict with resolutions override 2026-03-20 09:04:21 +00:00
rewrite-config.PL Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
rspack.config.js Bug 41587: (follow-up) Clean Cypress plugin dist on rebuild to prevent stale sourcemaps 2026-03-20 15:16:28 +00:00
tsconfig.json
…
yarn.lock Bug 41587: (follow-up) Fix js-yaml version conflict with resolutions override 2026-03-20 09:04:21 +00:00

README.md

Koha is a free software integrated library system (ILS).

Koha is distributed under the GNU GPL version 3 or later.

Note: Koha does not accept pull requests from git hosting sites.

Note: This project has its own bug tracker, to report a bug or submit a patch visit https://bugs.koha-community.org.

For guidelines on submitting patches for Koha please visit https://wiki.koha-community.org/wiki/SubmitingAPatch

The developers handbook can be found at https://wiki.koha-community.org/wiki/Developer_handbook

https://koha-community.org/

Koha Logo