Bug 2882 - Delete library silently fails when patrons exist for that library
Summary: Delete library silently fails when patrons exist for that library
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P3 normal (vote)
Assignee: Galen Charlton
QA Contact: Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-23 11:50 UTC by Chris Cormack
Modified: 2012-10-25 23:10 UTC (History)
2 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Cormack 2010-05-21 00:57:32 UTC


---- Reported by koha@brinkerhoff.org 2008-12-23 11:50:19 ----

When I try to delete the 'Franklin' library from the sample data included with Koha 3.00.00 the web interface claims the library entry was deleted:

Library deleted

However the page refreshes and the library is still present.  

[Tue Dec 23 14:48:31 2008] [error] [client 216.107.221.XXX] [Tue Dec 23 14:48:31 2008] branches.pl: DBD::mysql::st execute failed: Cannot delete or update a parent row: a foreign key constraint fails (`koha/borrowers`, CONSTRAINT `borrowers_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)) at /usr/share/koha/lib/C4/Branch.pm line 473., referer: http://XXXXXXXXXX:8080/cgi-bin/koha/admin/branches.pl?branchcode=FRL&branchname=Franklin&op=delete



---- Additional Comments From koha@brinkerhoff.org 2008-12-23 11:53:23 ----

delete from borrowers where branchcode != "LIBRARYCODEIWANTTOKEEP"; allowed me to delete the other libraries as expected -- however branches.pl should probably check to see if there are any constraints that will be violated on delete -- or atleast requery to see if the library still exists after delete and give the user an error.



---- Additional Comments From koha@brinkerhoff.org 2008-12-23 12:03:04 ----

diff --git a/admin/branches.pl b/admin/branches.pl
index fecc030..c01aa59 100755
--- a/admin/branches.pl
+++ b/admin/branches.pl
@@ -123,6 +123,11 @@ elsif ( $op eq 'delete' ) {
     $sth->execute( $branchcode, $branchcode );
     my ($total) = $sth->fetchrow_array;
     $sth->finish;
+
+    my $sth = $dbh->prepare("select count(*) from borrowers where branchcode=?");
+    $sth->execute($branchcode);
+    my ($total) += $sth->fetchrow_array;
+    $sth->finish;

     my $message;




--- Bug imported by chris@bigballofwax.co.nz 2010-05-21 00:57 UTC  ---

This bug was previously known as _bug_ 2882 at http://bugs.koha.org/cgi-bin/bugzilla3/show_bug.cgi?id=2882

Unknown operating system Linux - Other. Setting to default OS "All".
Actual time not defined. Setting to 0.0
The original reporter of this bug does not have
   an account here. Reassigning to the person who moved
   it here: chris@bigballofwax.co.nz.
   Previous reporter was koha@brinkerhoff.org.

Comment 1 MJ Ray (software.coop) 2011-01-17 09:56:58 UTC
This patch does not seem to be present in 3.0.x - reopening and I will try to apply it before the 3.0.7 release.
Comment 2 Owen Leonard 2011-08-22 20:14:55 UTC
Fixed in master.