From 72d91ac3616437f30b1719b7bb95cdcc85802615 Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Wed, 11 Nov 2009 15:19:24 +0100 Subject: [PATCH] Adding a warning On subscription deletion for item If we really wanted to delete all items linked to a subscription when we delete a subscription we should change the database structure as such : ALTER TABLE serialitems ADD FOREIGN KEY ( itemnumber ) REFERENCES items (itemnumber) ON DELETE CASCADE ; ALTER TABLE serial CHANGE subscriptionid subscriptionid INT( 11 ) NOT NULL ALTER TABLE serial ADD INDEX subscription ( subscriptionid ) ALTER TABLE serial ADD FOREIGN KEY ( subscriptionid ) REFERENCES subscription (subscriptionid) ON DELETE CASCADE ; --- C4/Serials.pm | 26 ++++++++++++++++++++++++++ serials/subscription-detail.pl | 4 +++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 8bfa6590d0..daf9a87a79 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -2237,6 +2237,32 @@ sub CountIssues { return $countreceived; } +=head2 HasItems + +=over 4 + +$result = &HasItems($subscriptionid) + + +=back + +=cut + +sub HasItems { + my ($subscriptionid) = @_; + my $dbh = C4::Context->dbh; + my $query = qq| + SELECT COUNT(serialitems.itemnumber) + FROM serial + LEFT JOIN serialitems USING(serialid) + WHERE subscriptionid=? AND serialitems.serialid NOT NULL + |; + my $sth=$dbh->prepare($query); + $sth->execute($subscriptionid); + my ($countitems)=$sth->fetchrow; + return $countitems; +} + =head2 abouttoexpire =over 4 diff --git a/serials/subscription-detail.pl b/serials/subscription-detail.pl index c425296693..9e358a2305 100755 --- a/serials/subscription-detail.pl +++ b/serials/subscription-detail.pl @@ -56,10 +56,12 @@ if ($op eq 'del') { # Asking for confirmation if the subscription has not strictly expired yet or if it has linked issues my $strictlyexpired = HasSubscriptionStrictlyExpired($subscriptionid); my $linkedissues = CountIssues($subscriptionid); - if ($strictlyexpired == 0 || $linkedissues > 0) { + my $countitems = HasItems($subscriptionid); + if ($strictlyexpired == 0 || $linkedissues > 0 || $countitems>0) { $template->param(NEEDSCONFIRMATION => 1); if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); } if ($linkedissues > 0) { $template->param("LINKEDISSUES" => 1); } + if ($countitems > 0) { $template->param("LINKEDITEMS" => 1); } } else { $issueconfirmed = "1"; } -- 2.39.5