Bug 35654

Summary: Add option to delete_items.pl to delete record if existing item getting deleted is the only one attached to the bib
Product: Koha Reporter: Enica Davis <enica>
Component: CatalogingAssignee: Bugs List <koha-bugs>
Status: Signed Off --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: andrew, angela.berrett, m.de.rooy, magnus, mspinney
Version: unspecified   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Bug 35654: Add option to delete_items.pl cronjob to delete empty bibs
Bug 35654: Add option to delete_items.pl cronjob to delete empty bibs

Description Enica Davis 2023-12-27 14:19:09 UTC
Apologies if there's a duplicate bug.

It would be great to add a parameter to delete_items.pl to delete the record if the last item getting deleted is the only one that remains.
Comment 1 Magnus Enger 2024-04-04 08:41:06 UTC
Sorry, what steps do you take to get to delete_items.pl?
Comment 2 Katrin Fischer 2024-04-04 19:59:04 UTC
It's a CLI script in misc/cronjobs :)
Comment 3 Angela Berrett 2024-04-05 17:11:40 UTC
Would this be optional or be coded to always happen?  We would definitely want to choose when to delete the record or not.
Comment 4 Katrin Fischer 2024-04-05 17:21:13 UTC
Hi Angela, I believe that this was filed with the idea to make it an option for the CLI script, so you'd add it or not as needed, similar to how you can check the checkbox in the GUI or leave it off.
Comment 5 Brendan Lawlor 2024-11-14 01:45:48 UTC
Created attachment 174480 [details] [review]
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
Comment 6 Andrew Fuerste-Henry 2024-11-14 14:26:28 UTC
Created attachment 174529 [details] [review]
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
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>