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
---------
1) back up DB
2) drop DB, create empty DB
3) Apply patch 15842
4) web install all the sample data
5) login as system user and import patron data
   -- sample provided to trigger error.
   -- you will get a DBIx::class exception
      "Duplicate entry ' for key 'userid'"
6) Apply this patch
7) Repeat steps 2-5
   -- patrons won't be inserted but an error
      will be nicely displayed in the error list.
8) run koha qa test tools

Note that it would be easy to insert the patrons anyway and generate a
userid based on the surname and firstname.

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

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

Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
(cherry picked from commit f1e156453a)
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
This commit is contained in:
Jonathan Druart 2016-02-17 16:21:50 +00:00 committed by Julian Maurice
parent 25fdc18f77
commit 8d0a57f524
2 changed files with 12 additions and 0 deletions

View File

@ -90,6 +90,11 @@
[% IF ERROR.borrowernumber %] (for patron with borrowernumber [% ERROR.borrowernumber %])[% END %]
</li>
[% END %]
[% IF ERROR.duplicate_userid %]
<li class="line_error">
Userid [% ERROR.userid %] is already used by another patron or is empty.
</li>
[% END %]
[% END %]
</ul>
</div>

View File

@ -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