Bugzilla – Attachment 174480 Details for
Bug 35654
Add option to delete_items.pl to delete record if existing item getting deleted is the only one attached to the bib
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35654: Add option to delete_items.pl cronjob to delete empty bibs
Bug-35654-Add-option-to-deleteitemspl-cronjob-to-d.patch (text/plain), 4.84 KB, created by
Brendan Lawlor
on 2024-11-14 01:45:48 UTC
(
hide
)
Description:
Bug 35654: Add option to delete_items.pl cronjob to delete empty bibs
Filename:
MIME Type:
Creator:
Brendan Lawlor
Created:
2024-11-14 01:45:48 UTC
Size:
4.84 KB
patch
obsolete
>From 3852c9f4303c2e78251c8de2261e9774e77a4f6f Mon Sep 17 00:00:00 2001 >From: Brendan Lawlor <blawlor@clamsnet.org> >Date: Wed, 13 Nov 2024 21:26:43 +0000 >Subject: [PATCH] Bug 35654: Add option to delete_items.pl cronjob to delete > empty bibs > >This patch adds a new option to the delete_items cronjob > >When --del_bibs is set, bib records will be deleted >if the last item is deleted. > >The following plan assumes default ktd data. > >To test: >1. Apply patch >2. Check the holdings for bib #115 and see 3 items > http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=115 >2. Run the cron with the following flags > perl ./misc/cronjobs/delete_items.pl --where "biblionumber=115 and homebranch ='MPL'" --verbose --del_bibs --commit >3. Notice in the output the count of current items on the bib record: > Where statement: where biblionumber=115 and homebranch='MPL' > Deleting empty bib records! > Deleting item '237' (of 3) > Deleting item '238' (of 2) >4. Confirm the two Midway items were deleted from bib #115, and the bib still exists with one item >4. Run the cron again but change the the --where flag to delete all the items from bib #115 > perl ./misc/cronjobs/delete_items.pl --where "biblionumber=115" --verbose --del_bibs --commit >5. Notice in the output the bib is deleted after the last item is deleted > Where statement: where biblionumber=115 > Deleting empty bib records! > Deleting item '239' (of 1) > Last item deleted - deleting bib '115' >8. Confirm the bib #115 was deleted >9. Add some more items and test with some other --where parameters >10. Test with and without --commit and --del_bibs, test the --help flag > >Sponsored-by: CLAMS >--- > misc/cronjobs/delete_items.pl | 39 ++++++++++++++++++++++++++++------- > 1 file changed, 31 insertions(+), 8 deletions(-) > >diff --git a/misc/cronjobs/delete_items.pl b/misc/cronjobs/delete_items.pl >index ac86b07648..ad3e6e834e 100755 >--- a/misc/cronjobs/delete_items.pl >+++ b/misc/cronjobs/delete_items.pl >@@ -21,8 +21,9 @@ use Getopt::Long qw( GetOptions ); > use Pod::Usage qw( pod2usage ); > > use Koha::Script -cron; >- >+use C4::Biblio qw( DelBiblio ); > use C4::Context; >+use Koha::Biblios; > use Koha::Items; > > my $dbh = C4::Context->dbh(); >@@ -44,6 +45,7 @@ my $OPTIONS = { > , help => '' > , manual => '' > , version => '' >+ , del_bibs => '' > } > }; > >@@ -54,6 +56,7 @@ GetOptions( > , 'h|help' => sub { $OPTIONS->{flags}->{help} = 1 } > , 'm|manual' => sub { $OPTIONS->{flags}->{manual} = 1 } > , 'c|commit' => sub { $OPTIONS->{flags}->{commit} = 1 } # aka DO-EET! >+ , 'del_bibs' => sub { $OPTIONS->{flags}->{del_bibs} = 1 } > ); > > my @where = @{ $OPTIONS->{where} }; >@@ -69,6 +72,9 @@ sub verbose { > my $where_clause = ' where ' . join ( " and ", @where ); > > verbose "Where statement: $where_clause"; >+if( $OPTIONS->{flags}->{del_bibs} ) { >+ verbose "Deleting empty bib records!" >+} > > # FIXME Use Koha::Items instead > $GLOBAL->{sth}->{target_items} = $dbh->prepare( $query->{target_items} . $where_clause ); >@@ -76,18 +82,31 @@ $GLOBAL->{sth}->{target_items}->execute(); > > DELITEM: while ( my $item = $GLOBAL->{sth}->{target_items}->fetchrow_hashref() ) { > >- my $item_object = Koha::Items->find($item->{itemnumber}); >+ my $item_object = Koha::Items->find( $item->{itemnumber} ); >+ my $bibs_object = Koha::Biblios->find( $item_object->biblionumber ); >+ my $holdings_count = $bibs_object->items->count; >+ my $error; >+ > my $safe_to_delete = $item_object->safe_to_delete; >- if( $safe_to_delete ) { >+ if ($safe_to_delete) { > $item_object->safe_delete > if $OPTIONS->{flags}->{commit}; >- verbose "Deleting '$item->{itemnumber}'"; >+ verbose "Deleting item '$item->{itemnumber}' (of $holdings_count)"; >+ >+ if ( $OPTIONS->{flags}->{del_bibs} && $holdings_count == 1 ) { # aka DO-EET for empty bibs! >+ $error = &DelBiblio( $item->{biblionumber} ); >+ if ($error) { >+ verbose "Could not delete bib '$item->{biblionumber}': $error"; >+ } else { >+ verbose "Last item deleted - deleting bib '$item->{biblionumber}'"; >+ } >+ } > } else { > verbose sprintf "Item '%s' (Barcode: '%s', Title: '%s') not deleted: %s", >- $item->{itemnumber}, >- $item_object->barcode, >- $item_object->biblio->title, >- @{$safe_to_delete->messages}[0]->message; >+ $item->{itemnumber}, >+ $item_object->barcode, >+ $item_object->biblio->title, >+ @{ $safe_to_delete->messages }[0]->message; > } > } > >@@ -130,6 +149,10 @@ clause querying the items table. These are joined by C<AND>. > > No items will be deleted unless the C<--commit> flag is present. > >+=item B<--del_bibs> >+ >+Deletes the bibliographic record if the last item is deleted. >+ > =back > > =cut >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35654
:
174480
|
174529