From 74312ddd4445789a55bddc53d0edf42ffa189823 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 5 Aug 2020 12:20:08 +0200 Subject: [PATCH] Bug 6725: Make patron duplicate matching flexible This patch adds a new system preference PatronDuplicateMatchingAddFields to list the patron's attributes to use for deduplication. The default value is surname, firstname and dateofbirth to keep existing behaviour. Test plan: 0. Apply the patch and execute the update DB entry 1. Create a new patron with surname, firstname 2. Create another patron with the same surname, firstname values => Confirm you get the duplicate warning 3. Modify the syspref to edit the list of attributes used to dedup 4. Repeat 1 and 2 with different values and confirm that you get the behaviours you expect Note: This is only impacting the add patron form from the UI, not the import patrons tool. Signed-off-by: Kelly McElligott Signed-off-by: Katrin Fischer --- installer/data/mysql/atomicupdate/bug_6725.perl | 11 +++++++++++ installer/data/mysql/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/patrons.pref | 6 ++++++ members/memberentry.pl | 7 +++---- 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_6725.perl diff --git a/installer/data/mysql/atomicupdate/bug_6725.perl b/installer/data/mysql/atomicupdate/bug_6725.perl new file mode 100644 index 0000000000..9507062c7c --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_6725.perl @@ -0,0 +1,11 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + + $dbh->do( q{ + INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES + ('PatronDuplicateMatchingAddFields','surname|firstname|dateofbirth', NULL,'A list of fields separated by "|" to deduplicate patrons when created','Free') + }); + + # Always end with this (adjust the bug info) + NewVersion( $DBversion, 6725, "Adds PatronDuplicateMatchingAddFields system preference"); +} diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index d1efc4b42c..3f5442c4c0 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -482,6 +482,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OverduesBlockRenewing','allow','allow|blockitem|block','If any of patron checked out documents is late, should renewal be allowed, blocked only on overdue items or blocked on whatever checked out document','Choice'), ('PatronAnonymizeDelay','',NULL,'Delay for anonymizing patrons', 'Integer'), ('PatronAutoComplete','1','Try|Don\'t try','to guess the patron being entered while typing a patron search for circulation or patron search. Only returns the first 10 results at a time.','YesNo'), +('PatronDuplicateMatchingAddFields','surname|firstname|dateofbirth', NULL,'A list of fields separated by "|" to deduplicate patrons when created','Free') ('patronimages','0',NULL,'Enable patron images for the Staff Client','YesNo'), ('PatronRemovalDelay','',NULL,'Delay for removing anonymized patrons', 'Integer'), ('PatronSelfModificationBorrowerUnwantedField','',NULL,'Name the fields you don\'t want to display when a patron is editing their information via the OPAC.','free'), 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 30621ec8f7..fa7a797982 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 @@ -228,6 +228,12 @@ Patrons: housebound: "Housebound roles" additional: "Additional attributes and identifiers" messaging: "Patron messaging preferences" + - + - "The following database columns:" + - pref: PatronDuplicateMatchingAddFields + type: modalselect + source: borrowers + - "will be used deduplicate patrons." Patron relationships: - - "Guarantors can be the following of those they guarantee:" diff --git a/members/memberentry.pl b/members/memberentry.pl index 985a96446c..de8bffdd0a 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -254,11 +254,10 @@ if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' ) # Test uniqueness of surname, firstname and dateofbirth if ( ( $op eq 'insert' ) and !$nodouble ) { + my @dup_fields = split '\|', C4::Context->preference('PatronDuplicateMatchingAddFields'); my $conditions; - $conditions->{surname} = $newdata{surname} if $newdata{surname}; - if ( $category_type ne 'I' ) { - $conditions->{firstname} = $newdata{firstname} if $newdata{firstname}; - $conditions->{dateofbirth} = $newdata{dateofbirth} if $newdata{dateofbirth}; + for my $f ( @dup_fields ) { + $conditions->{$f} = $newdata{$f} if $newdata{$f}; } $nodouble = 1; my $patrons = Koha::Patrons->search($conditions); # FIXME Should be search_limited? -- 2.11.0