Bug 9302

Summary: Add ability to merge patron records
Product: Koha Reporter: Nicole C. Engard <nengard>
Component: PatronsAssignee: Kyle M Hall <kyle>
Status: Signed Off --- QA Contact:
Severity: new feature    
Priority: P5 - low CC: bibliwho, ByWaterSandboxes, eveal, george, gmcharlt, hagud, jdelooper, jonathan.druart, josef.moravec, jzairo, katrin.fischer, kyle.m.hall, kyle, misilot, tomascohen
Version: master   
Hardware: All   
OS: All   
Whiteboard:
Change sponsored?: Sponsored Patch complexity: Medium patch
Bot Control: --- When did the bot last check this:
Who signed the patch off: Text to go in the release notes:
Attachments: Bug 9302 - Add ability to merge patron records
Bug 9302 - Add ability to merge patron records
Bug 9302 - Add ability to merge patron records
Bug 9302 - Add ability to merge patron records
Bug 9302 [QA Followup] - Copy merged patrons to deletedborrowers table
Bug 9302 - Add ability to merge patron records
Bug 9302 [QA Followup] Copy merged patrons to deletedborrowers table
Bug 9302 - Add ability to merge patron records
Bug 9302 [QA Followup] Copy merged patrons to deletedborrowers table

Description Nicole C. Engard 2012-12-19 13:32:36 UTC
It would be great if there were a merge patrons feature. If you accidentally end up with one patron with two cards it would be nice to merge their records together so that you don't lose their history or holds or anything.
Comment 1 Cab Vinton 2017-02-26 09:02:31 UTC
Yikes. Surprised to see so little interest in this feature.

Our staff are not perfect & I've identified dozens of duplicate accounts in our own system.

The bib record merge tool offers a useful template for accomplishing something like this.
Comment 2 Katrin Fischer 2017-06-05 10:38:44 UTC
I think it might need a library/libraries sponsoring it. The feature would be useful!
Comment 3 Kyle M Hall 2017-08-30 14:15:20 UTC Comment hidden (obsolete)
Comment 4 Kyle M Hall 2017-08-30 14:24:29 UTC Comment hidden (obsolete)
Comment 5 Hugo Agud 2017-09-04 07:01:31 UTC
I have applied the patch followed the test plan and it works fine!
Comment 6 Katrin Fischer 2017-09-04 09:03:49 UTC
Hi Hugo, please add your sign-off line to patche that you mark as signed off. Instructions on how to do this can be found on the wiki.
Comment 7 Jonathan Druart 2017-09-07 17:43:33 UTC
Readonly: see bug 16588

Koha::Patrons->merge: See 15336, it adds a Koha::Acquisition::Bookseller->merge_with #consistency
Comment 8 Tomás Cohen Arazi 2017-09-11 16:03:05 UTC
Kyle, I'm failing it so it is obvious that some changes are needed for its inclusion!

(In reply to Jonathan Druart from comment #7)
> Readonly: see bug 16588

We are trying explicitly to get rid of Readonly, dicussion on that bug.

> Koha::Patrons->merge: See 15336, it adds a
> Koha::Acquisition::Bookseller->merge_with #consistency

Self explanatory!
Comment 9 Kyle M Hall 2017-10-26 13:26:53 UTC
(In reply to Tomás Cohen Arazi from comment #8)
> Kyle, I'm failing it so it is obvious that some changes are needed for its
> inclusion!
> 
> (In reply to Jonathan Druart from comment #7)
> > Readonly: see bug 16588
> 
> We are trying explicitly to get rid of Readonly, dicussion on that bug.

Will fix!

> > Koha::Patrons->merge: See 15336, it adds a
> > Koha::Acquisition::Bookseller->merge_with #consistency
> 
> Self explanatory!

This one isn't so easy for me ; )
Bookseller->merge_with is a method for a single object, and acts upon it.
Koha::Patrons->merge is a method that accepts a patron, and a list of patrons to merge into. I think it's actually better because the parameters make is clear which patron will be retained. With Bookseller->merge, I cannot tell which Bookseller will be removed and which will be kept without reading the code.
Comment 10 Kyle M Hall 2017-10-26 13:27:18 UTC
Created attachment 68606 [details] [review]
Bug 9302 - Add ability to merge patron records

It would be great if there were a merge patrons feature. If you accidentally end up with one patron with two cards it would be nice to merge their records together so that you don't lose their history or holds or anything.

This patch adds a basic patron merge feature. It attempts to relink all patron related tables from the patron(s) to be merged. It does not attempt to relink librarian account related tables at this time. This feature does not attempt to automatically resolve issues such as duplicate holds. Such a feature could build upon this one though.

Test Plan:
1) Apply this patch
2) Find two or more patrons
3) Perform a patron search that will bring them up on the same page of results,
   or add them all to a list of patrons.
4) Use the 'merge' button to begin the merging process
5) Choose a patron to keep
6) Verify the deleted patrons data ( checkouts, holds, etc )
   are now linked to the kept patron
Comment 11 Josef Moravec 2017-10-29 20:19:17 UTC
Kyle, it's nice feature, and I really would like to have it in Koha.

But qa tools are complaining about this:

 FAIL	Koha/Patrons.pm
   FAIL	  valid
		Useless use of anonymous hash ({}) in void context 

 FAIL	koha-tmpl/intranet-tmpl/prog/en/modules/members/merge-patrons.tt
   FAIL	  forbidden patterns
		forbidden pattern: tab char (line 30)
		forbidden pattern: tab char (line 33)
		forbidden pattern: tab char (line 50)
		forbidden pattern: tab char (line 39)
		forbidden pattern: tab char (line 42)
		forbidden pattern: tab char (line 49)
		forbidden pattern: tab char (line 36)
		forbidden pattern: tab char (line 123)
		forbidden pattern: tab char (line 46)
		forbidden pattern: tab char (line 51)
		forbidden pattern: tab char (line 32)
		forbidden pattern: tab char (line 41)
		forbidden pattern: tab char (line 40)
		forbidden pattern: tab char (line 55)
		forbidden pattern: tab char (line 34)
		forbidden pattern: tab char (line 122)
		forbidden pattern: tab char (line 53)
		forbidden pattern: tab char (line 127)
		forbidden pattern: tab char (line 38)
		forbidden pattern: tab char (line 37)
		forbidden pattern: tab char (line 35)
		forbidden pattern: tab char (line 126)
		forbidden pattern: tab char (line 48)
		forbidden pattern: tab char (line 43)
		forbidden pattern: tab char (line 29)
		forbidden pattern: tab char (line 52)
		forbidden pattern: tab char (line 125)
		forbidden pattern: tab char (line 124)
		forbidden pattern: tab char (line 31)
		forbidden pattern: tab char (line 47)
		forbidden pattern: tab char (line 54)
		forbidden pattern: tab char (line 45)
		forbidden pattern: tab char (line 44)
		forbidden pattern: tab char (line 121)
		forbidden pattern: tab char (line 120)

 FAIL	members/merge-patrons.pl
   FAIL	  valid
		Useless use of anonymous hash ({}) in void context 

 FAIL	t/db_dependent/Patrons.t
   FAIL	  forbidden patterns
		forbidden pattern: tab char (line 149)
		forbidden pattern: tab char (line 148)
   FAIL	  valid
		Useless use of anonymous hash ({}) in void context
Comment 12 John DeLooper 2017-11-02 21:44:03 UTC
I too would love to see this kind of feature added, and am glad to see patches in progress. I think a process for merging creates a smoother experience than the current looking up duplicates and choosing which one to delete.
Comment 13 Owen Leonard 2017-11-09 16:11:37 UTC
This doesn't work for me at all. When I select the patron record to keep and submit the form, I'm redirected to a page which says "Patron records merged into ()" and the records have not been merged.
Comment 14 Nick Clemens 2018-01-12 16:52:58 UTC
*** Bug 19567 has been marked as a duplicate of this bug. ***
Comment 15 Kyle M Hall 2018-01-12 17:51:34 UTC Comment hidden (obsolete)
Comment 16 Kyle M Hall 2018-01-12 19:23:03 UTC Comment hidden (obsolete)
Comment 17 Owen Leonard 2018-01-12 19:29:12 UTC Comment hidden (obsolete)
Comment 18 Owen Leonard 2018-01-12 19:29:15 UTC Comment hidden (obsolete)
Comment 19 ByWaterSandboxes 2018-01-14 18:27:09 UTC
Patch tested with a sandbox, by Ed Veal <eveal@mckinneytexas.org>
Comment 20 ByWaterSandboxes 2018-01-14 18:27:32 UTC
Created attachment 70482 [details] [review]
Bug 9302 - Add ability to merge patron records

It would be great if there were a merge patrons feature. If you
accidentally end up with one patron with two cards it would be nice to
merge their records together so that you don't lose their history or
holds or anything.

This patch adds a basic patron merge feature. It attempts to relink all
patron related tables from the patron(s) to be merged. It does not
attempt to relink librarian account related tables at this time. This
feature does not attempt to automatically resolve issues such as
duplicate holds. Such a feature could build upon this one though.

Test Plan:
1) Apply this patch
2) Find two or more patrons
3) Perform a patron search that will bring them up on the same page of
   results, or add them all to a list of patrons.
4) Use the 'merge' button to begin the merging process
5) Choose a patron to keep
6) Verify the deleted patrons data ( checkouts, holds, etc )
   are now linked to the kept patron

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Ed Veal <eveal@mckinneytexas.org>
Comment 21 ByWaterSandboxes 2018-01-14 18:27:35 UTC
Created attachment 70483 [details] [review]
Bug 9302 [QA Followup] Copy merged patrons to deletedborrowers table

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Ed Veal <eveal@mckinneytexas.org>
Signed-off-by: BWS Sandboxes <ByWaterSandboxes@gmail.com>