From 556eb677186b738c036fd13a7cc3461c3f8c3d48 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 12 Mar 2014 03:33:50 +0000 Subject: [PATCH] Bug 108661: (follow-up) enshrine letting CardnumberLength specify just a maximum This patch finishes the work started in one of the previous follow-ups and allows CardnumberLength to be set to a value like ',5'. In conjunction with not including cardnumber in BorrowerMandatoryField, this allows a cardnumber to not be required but, if present, to not exceed the specified length. This patch also updates t/db_dependent/Members.t so that it runs in a transaction, tests the new return value of checkcardnumber, and manages the CardnumberLength syspref. To test: [1] Verify that prove -v t/db_dependent/Members.t and prove -v t/Members/cardnumber.t pass. [2] Set CardnumberLength to ",5" and take cardnubmer out of the BorrowerMandatoryField list. [3] Verify that you can save a patron record without a cardnumber, but if you supply one, that it can be at most 5 characters long. [4] Add cardnumber back to BorrowerMandatoryField. This time, the minimum length is 1 even though CardnumberLength is ",5". Signed-off-by: Galen Charlton --- C4/Members.pm | 14 ++++++++++- .../en/modules/admin/preferences/patrons.pref | 5 ++-- .../prog/en/modules/members/memberentrygen.tt | 2 +- t/Members/cardnumber.t | 23 +++++++++---------- t/db_dependent/Members.t | 16 ++++++++++++- 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 9b358051f6..486a61d771 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -1349,8 +1349,20 @@ sub checkcardnumber { return 0; } +=head2 get_cardnumber_length + + my ($min, $max) = C4::Members::get_cardnumber_length() + +Returns the minimum and maximum length for patron cardnumbers as +determined by the CardnumberLength system preference, the +BorrowerMandatoryField system preference, and the width of the +database column. + +=cut + sub get_cardnumber_length { - my ( $min, $max ) = ( 1, 16 ); # borrowers.cardnumber is a varchar(16) + my ( $min, $max ) = ( 0, 16 ); # borrowers.cardnumber is a nullable varchar(16) + $min = 1 if C4::Context->preference('BorrowerMandatoryField') =~ /cardnumber/; if ( my $cardnumber_length = C4::Context->preference('CardnumberLength') ) { # Is integer and length match if ( $cardnumber_length =~ m|^\d+$| ) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref index ac1d1da805..9732d1aff5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -134,6 +134,7 @@ Patrons: no: "Don't" - enable the ability to upload and attach arbitrary files to a borrower record. - - - Card numbers for patrons must be strictly equal to + - Card numbers for patrons must be - pref: CardnumberLength - - characters. The length can be a single number or a range separated by a comma ( i.e. Min,Max ). + - "characters long. The length can be a single number to specify an exact length, a range separated by a comma (i.e., 'Min,Max'), or a maximum with no minimum (i.e., ',Max')." + - "If 'cardnumber' is included in the BorrowerMandatoryField list, the minimum length, if not specified here, defaults to one." diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index ffdb44b2f1..720193f54e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -894,7 +894,7 @@ [% IF ( mandatorycardnumber ) %]