Bug 6725: Make patron duplicate matching flexible
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 5 Aug 2020 10:20:08 +0000 (12:20 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 18 Aug 2020 15:39:48 +0000 (17:39 +0200)
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 <kelly@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

installer/data/mysql/atomicupdate/bug_6725.perl [new file with mode: 0644]
installer/data/mysql/sysprefs.sql
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref
members/memberentry.pl

diff --git a/installer/data/mysql/atomicupdate/bug_6725.perl b/installer/data/mysql/atomicupdate/bug_6725.perl
new file mode 100644 (file)
index 0000000..9507062
--- /dev/null
@@ -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");
+}
index d1efc4b..3f5442c 100644 (file)
@@ -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'),
index 30621ec..fa7a797 100644 (file)
@@ -228,6 +228,12 @@ Patrons:
                housebound: "Housebound roles"
                additional: "Additional attributes and identifiers"
                messaging: "Patron messaging preferences"
+     -
+         - "The following <a href='http://schema.koha-community.org/__VERSION__/tables/borrowers.html' target='blank'>database columns</a>:"
+         - pref: PatronDuplicateMatchingAddFields
+           type: modalselect
+           source: borrowers
+         - "will be used deduplicate patrons."
     Patron relationships:
      -
          - "Guarantors can be the following of those they guarantee:"
index 671ec5c..fd684c5 100755 (executable)
@@ -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?