Bug 16960: Delete previous patron modifications
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 19 Aug 2016 12:39:35 +0000 (13:39 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Mon, 22 Aug 2016 11:46:05 +0000 (11:46 +0000)
If a patron edit his/her details a second time, we need to delete the
first ones to avoid a "duplicate entry for key PRIMARY" error.

Test plan:
Log in at the OPAC
Edit your details
Edit them again
=> Without this patch, Koha will crash
=> With the patch applied, everything should work as expected

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

opac/opac-memberentry.pl

index 1bf5acf..1a5bac4 100755 (executable)
@@ -227,6 +227,14 @@ elsif ( $action eq 'update' ) {
 
             $borrower_changes{borrowernumber} = $borrowernumber;
 
+            # FIXME update the following with
+            # Koha::Patron::Modifications->search({ borrowernumber => $borrowernumber })->delete;
+            # when bug 17091 will be pushed
+            my $patron_modifications = Koha::Patron::Modifications->search({ borrowernumber => $borrowernumber });
+            while ( my $patron_modification = $patron_modifications->next ) {
+                $patron_modification->delete;
+            }
+
             my $m = Koha::Patron::Modification->new( \%borrower_changes )->store();
 
             $template->param(