From c34c06bddfa47efc771f3a0603ace21b781bfce1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 17 Feb 2016 16:21:50 +0000 Subject: [PATCH] Bug 15840: Catch errors if userid already exists when importing patrons Import borrowers tool explodes if userid already exists. This error should be caught to avoid the script to explodes. Test plan: Import a csv file with the same userid used Without this patch, you will get a DBIx::class exception "Duplicate entry ' for key 'userid'" With this patch applied, these patrons won't be inserted but an error will be nicely displayed in the error list. Note that it would be easy to insert the patrons anyway and generate a userid based on the surname and firstname. --- koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt | 5 +++++ tools/import_borrowers.pl | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt index fa955da..f31d7da 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt @@ -90,6 +90,11 @@ [% IF ERROR.borrowernumber %] (for patron with borrowernumber [% ERROR.borrowernumber %])[% END %] [% END %] + [% IF ERROR.duplicate_userid %] +
  • + Userid [% ERROR.userid %] is already used by another patron or is empty. +
  • + [% END %] [% END %] diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl index 42e7a8e..3e67439 100755 --- a/tools/import_borrowers.pl +++ b/tools/import_borrowers.pl @@ -253,6 +253,13 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { next; } + # generate a proper login if none provided + if ( $borrower{userid} eq '' || !Check_Userid( $borrower{userid} ) ) { + push @errors, { duplicate_userid => 1, userid => $borrower{userid} }; + $invalid++; + next LINE; + } + if ($borrowernumber) { # borrower exists -- 2.7.0