Bugzilla – Attachment 175193 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: (follow-up) Simplify variable use and only delete when commit is set
Bug-35654-follow-up-Simplify-variable-use-and-only.patch (text/plain), 3.69 KB, created by
Nick Clemens (kidclamp)
on 2024-12-04 14:31:40 UTC
(
hide
)
Description:
Bug 35654: (follow-up) Simplify variable use and only delete when commit is set
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2024-12-04 14:31:40 UTC
Size:
3.69 KB
patch
obsolete
>From 77a76e78793c2cc23474ff1ac7490d9d1dc0ba3d Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 4 Dec 2024 13:32:20 +0000 >Subject: [PATCH] Bug 35654: (follow-up) Simplify variable use and only delete > when commit is set > >This patch leans up some things: > - version option does nothing, so removed > - warn when not setting commit and show conditional messages > - remove use of Koha::Biblios and use item object methods >--- > misc/cronjobs/delete_items.pl | 19 +++++++++---------- > 1 file changed, 9 insertions(+), 10 deletions(-) > >diff --git a/misc/cronjobs/delete_items.pl b/misc/cronjobs/delete_items.pl >index ad3e6e834ea..7764ca6830f 100755 >--- a/misc/cronjobs/delete_items.pl >+++ b/misc/cronjobs/delete_items.pl >@@ -23,7 +23,6 @@ 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,7 +43,6 @@ my $OPTIONS = { > , commit => '' > , help => '' > , manual => '' >- , version => '' > , del_bibs => '' > } > }; >@@ -52,7 +50,6 @@ my $OPTIONS = { > GetOptions( > 'where=s' => $OPTIONS->{where} > , 'v|verbose' => sub { $OPTIONS->{flags}->{verbose} = 1 } >- , 'V|version' => sub { $OPTIONS->{flags}->{version} = 1 } > , 'h|help' => sub { $OPTIONS->{flags}->{help} = 1 } > , 'm|manual' => sub { $OPTIONS->{flags}->{manual} = 1 } > , 'c|commit' => sub { $OPTIONS->{flags}->{commit} = 1 } # aka DO-EET! >@@ -76,6 +73,9 @@ if( $OPTIONS->{flags}->{del_bibs} ) { > verbose "Deleting empty bib records!" > } > >+print "Test run only! No data will be deleted.\n" unless $OPTIONS->{flags}->{commit}; >+my $deleted_string = $OPTIONS->{flags}->{commit} ? "Deleted" : "Would have deleted"; >+ > # FIXME Use Koha::Items instead > $GLOBAL->{sth}->{target_items} = $dbh->prepare( $query->{target_items} . $where_clause ); > $GLOBAL->{sth}->{target_items}->execute(); >@@ -83,27 +83,26 @@ $GLOBAL->{sth}->{target_items}->execute(); > DELITEM: while ( my $item = $GLOBAL->{sth}->{target_items}->fetchrow_hashref() ) { > > 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 $holdings_count = $item_object->biblio->items->count; > my $error; > > my $safe_to_delete = $item_object->safe_to_delete; > if ($safe_to_delete) { > $item_object->safe_delete > if $OPTIONS->{flags}->{commit}; >- verbose "Deleting item '$item->{itemnumber}' (of $holdings_count)"; >+ verbose "$deleted_string item '$item->{itemnumber}' (of $holdings_count)"; > > if ( $OPTIONS->{flags}->{del_bibs} && $holdings_count == 1 ) { # aka DO-EET for empty bibs! >- $error = &DelBiblio( $item->{biblionumber} ); >+ $error = &DelBiblio( $item->{biblionumber} ) if $OPTIONS->{flags}->{commit}; > if ($error) { > verbose "Could not delete bib '$item->{biblionumber}': $error"; > } else { >- verbose "Last item deleted - deleting bib '$item->{biblionumber}'"; >+ verbose "No items remaining. $deleted_string bibliographic record '$item->{biblionumber}'"; > } > } > } else { >- verbose sprintf "Item '%s' (Barcode: '%s', Title: '%s') not deleted: %s", >- $item->{itemnumber}, >+ verbose sprintf "Item '%s' (Barcode: '%s', Title: '%s') cannot deleted: %s", >+ $item_object->itemnumber, > $item_object->barcode, > $item_object->biblio->title, > @{ $safe_to_delete->messages }[0]->message; >-- >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
| 175193 |
175194
|
175195
|
175208
|
175209