Bugzilla – Attachment 175195 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: Use Koha::Items instead of direct SQL
Bug-35654-Use-KohaItems-instead-of-direct-SQL.patch (text/plain), 3.19 KB, created by
Nick Clemens (kidclamp)
on 2024-12-04 14:45:08 UTC
(
hide
)
Description:
Bug 35654: Use Koha::Items instead of direct SQL
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2024-12-04 14:45:08 UTC
Size:
3.19 KB
patch
obsolete
>From 7339c54ab806aa23e4a788af6f828a8f5646c3f8 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 4 Dec 2024 14:44:55 +0000 >Subject: [PATCH] Bug 35654: Use Koha::Items instead of direct SQL > >--- > misc/cronjobs/delete_items.pl | 30 +++++++++++++----------------- > 1 file changed, 13 insertions(+), 17 deletions(-) > >diff --git a/misc/cronjobs/delete_items.pl b/misc/cronjobs/delete_items.pl >index 0c49076cdf0..b79341c7d72 100755 >--- a/misc/cronjobs/delete_items.pl >+++ b/misc/cronjobs/delete_items.pl >@@ -46,7 +46,7 @@ pod2usage( -verbose => 2 ) > pod2usage( -verbose => 1 ) if $help; > pod2usage( -verbose => 1, -message => 'You must supply at least one --where option' ) if scalar @where == 0; > >-my $where_clause = ' where ' . join( " and ", @where ); >+my $where_clause = join( " AND ", @where ); > > $verbose && say "Where statement: $where_clause"; > if ($delete_biblios) { >@@ -56,37 +56,33 @@ if ($delete_biblios) { > print "Test run only! No data will be deleted.\n" unless $commit; > my $deleted_string = $commit ? "Deleted" : "Would have deleted"; > >-# FIXME Use Koha::Items instead >-my $query = "SELECT itemnumber, biblionumber from items "; >-my $sth = $dbh->prepare( $query . $where_clause ); >-$sth->execute(); >+my $items = Koha::Items->search( \$where_clause ); > >-DELITEM: while ( my $item = $sth->fetchrow_hashref() ) { >+DELITEM: while ( my $item = $items->next ){ #$sth->fetchrow_hashref() ) { > >- my $item_object = Koha::Items->find( $item->{itemnumber} ); >- my $holdings_count = $item_object->biblio->items->count; >+ my $holdings_count = $item->biblio->items->count; > my $error; > >- my $safe_to_delete = $item_object->safe_to_delete; >+ my $safe_to_delete = $item->safe_to_delete; > if ($safe_to_delete) { >- $item_object->safe_delete >+ $item->safe_delete > if $commit; >- $verbose && say "$deleted_string item '$item->{itemnumber}' (of $holdings_count)"; >+ $verbose && say "$deleted_string item " . $item->itemnumber . " ($holdings_count items remain on record)"; > > if ( $delete_biblios && $holdings_count == 1 ) { # aka DO-EET for empty bibs! >- $error = &DelBiblio( $item->{biblionumber} ) if $commit; >+ $error = &DelBiblio( $item->biblionumber ) if $commit; > if ($error) { >- $verbose && say "Could not delete bib '$item->{biblionumber}': $error"; >+ $verbose && say "Could not delete bib " . $item->biblionumber . ": $error"; > } else { >- $verbose && say "No items remaining. $deleted_string bibliographic record '$item->{biblionumber}'"; >+ $verbose && say "No items remaining. $deleted_string bibliographic record " . $item->biblionumber; > } > } > } else { > say sprintf( > "Item '%s' (Barcode: '%s', Title: '%s') cannot deleted: %s", >- $item_object->itemnumber, >- $item_object->barcode, >- $item_object->biblio->title, >+ $item->itemnumber, >+ $item->barcode, >+ $item->biblio->title, > @{ $safe_to_delete->messages }[0]->message > ) if $verbose; > } >-- >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