From 4d26038dd23060de979f0b1751b05c5e4cc76083 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 17 Feb 2012 09:36:38 -0500 Subject: [PATCH] Bug 6027 - Delete biblios if deleting all their items in batch deletion Optionally delete bibliographic record when batch deleting items, if no items remain on the record. Adds deleting of reserves to DelBiblio. Since subscriptions are deleted automatically, it made sense for deletion of reserves to maintain the same behavior. Signed-off-by: Liz Rea I like the way this works, and it does. Passes tests. Signed-off-by: Paul Poulain --- C4/Biblio.pm | 7 +++++ C4/Items.pm | 1 + C4/Reserves.pm | 6 ++--- C4/Search.pm | 1 + .../prog/en/modules/tools/batchMod-del.tt | 6 ++++- tools/batchMod.pl | 27 ++++++++++++++----- 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 432eb6b426..39a2b7abd4 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -430,6 +430,13 @@ sub DelBiblio { C4::Serials::DelSubscription( $subscription->{subscriptionid} ); } + # We delete any existing holds + require C4::Reserves; + my ($count, $reserves) = C4::Reserves::GetReservesFromBiblionumber($biblionumber); + foreach my $res ( @$reserves ) { + C4::Reserves::CancelReserve( $res->{'biblionumber'}, $res->{'itemnumber'}, $res->{'borrowernumber'} ); + } + # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio # for at least 2 reasons : # - we need to read the biblio if NoZebra is set (to remove it from the indexes diff --git a/C4/Items.pm b/C4/Items.pm index 676c91b37e..2f32c988ef 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -26,6 +26,7 @@ use C4::Context; use C4::Koha; use C4::Biblio; use C4::Dates qw/format_date format_date_in_iso/; +use C4::Search qw/SimpleSearch/; use MARC::Record; use C4::ClassSource; use C4::Log; diff --git a/C4/Reserves.pm b/C4/Reserves.pm index a63e30ff8e..276658ceed 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -98,7 +98,7 @@ BEGIN { &GetReservesToBranch &GetReserveCount &GetReserveFee - &GetReserveInfo + &GetReserveInfo &GetReserveStatus &GetOtherReserves @@ -901,8 +901,8 @@ sub CancelExpiredReserves { Cancels a reserve. Use either C<$biblionumber> or C<$itemnumber> to specify the item to -cancel, but not both: if both are given, C<&CancelReserve> does -nothing. +cancel, but not both: if both are given, C<&CancelReserve> uses +C<$itemnumber>. C<$borrowernumber> is the borrower number of the patron on whose behalf the book was reserved. diff --git a/C4/Search.pm b/C4/Search.pm index 7adb6254d6..9bc0af2842 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -71,6 +71,7 @@ This module provides searching functions for Koha's bibliographic databases &AddSearchHistory &GetDistinctValues &enabled_staff_search_views + &SimpleSearch ); # make all your functions, whether exported or not; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tt index af2a239ebd..3f0f4b9e51 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tt @@ -133,6 +133,7 @@ for( x=0; x [% IF ( too_many_items ) %][% ELSE %] +

[% END %] Cancel @@ -146,7 +147,10 @@ for( x=0; x

[% deleted_items %] item(s) deleted.

+
+

[% deleted_items %] item(s) deleted.

+ [% IF delete_records %]

[% deleted_records %] record(s) deleted.

[% END %] +
[% IF ( not_deleted_items ) %]

[% not_deleted_items %] item(s) could not be deleted: [% FOREACH not_deleted_itemnumber IN not_deleted_itemnumbers %][% not_deleted_itemnumber.itemnumber %][% END %]

diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 440e516f14..9d59e3a6e8 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -41,6 +41,7 @@ my $error = $input->param('error'); my @itemnumbers = $input->param('itemnumber'); my $op = $input->param('op'); my $del = $input->param('del'); +my $del_records = $input->param('del_records'); my $completedJobID = $input->param('completedJobID'); my $runinbackground = $input->param('runinbackground'); @@ -76,8 +77,9 @@ my $items_display_hashref; my $frameworkcode=""; my $tagslib = &GetMarcStructure(1,$frameworkcode); -my $deleted_items = 0; # Numbers of deleted items -my $not_deleted_items = 0; # Numbers of items that could not be deleted +my $deleted_items = 0; # Number of deleted items +my $deleted_records = 0; # Number of deleted records ( with no items attached ) +my $not_deleted_items = 0; # Number of items that could not be deleted my @not_deleted; # List of the itemnumbers that could not be deleted my %cookies = parse CGI::Cookie($cookie); @@ -156,7 +158,7 @@ if ($op eq "action") { foreach my $itemnumber(@itemnumbers){ $job->progress($i) if $runinbackground; - my $itemdata=GetItem($itemnumber); + my $itemdata = GetItem($itemnumber); if ($input->param("del")){ my $return = DelItemCheck(C4::Context->dbh, $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'}); if ($return == 1) { @@ -171,15 +173,24 @@ if ($op eq "action") { $return => 1 }; } + + # If there are no items left, delete the biblio + if ( $del_records ) { + my $itemscount = GetItemsCount($itemdata->{'biblionumber'}); + if ( $itemscount == 0 ) { + my $error = DelBiblio($itemdata->{'biblionumber'}); + $deleted_records++ unless ( $error ); + } + } } else { if ($values_to_modify || $values_to_blank) { my $localmarcitem = Item2Marc($itemdata); UpdateMarcWith( $marcitem, $localmarcitem ); eval{ - if ( my $item = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) ) { - LostItem($itemnumber, 'MARK RETURNED', 'CHARGE FEE') if $item->{itemlost}; - } - }; + if ( my $item = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) ) { + LostItem($itemnumber, 'MARK RETURNED', 'CHARGE FEE') if $item->{itemlost}; + } + }; } } $i++; @@ -433,6 +444,8 @@ if ($op eq "action") { $template->param( not_deleted_items => $not_deleted_items, deleted_items => $deleted_items, + delete_records => $del_records, + deleted_records => $deleted_records, not_deleted_loop => \@not_deleted ); } -- 2.39.5