Bug 37418

Summary: Expand delete_patron.pl with option to not delete patrons with restrictions
Product: Koha Reporter: Michaela Sieber <michaela.sieber>
Component: Command-line UtilitiesAssignee: Raphael Straub <raphael.straub>
Status: Pushed to main --- QA Contact: Thomas Klausner <domm>
Severity: enhancement    
Priority: P5 - low CC: clemens.tubach, domm, gmcharlt, kyle.m.hall, lauren_denny, lisette, lucas, robin
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: Sponsored
Patch complexity: Small patch Documentation contact:
Documentation submission: Text to go in the release notes:
This feature adds a new parameter to the cronjob delete_patrons.pl which gives an option to not delete patrons with given restriction types. The parameter `--without_restriction_type` is repeatable.
Version(s) released in:
25.05.00
Circulation function:
Attachments: Bug 37418: delete_patrons.pl: Exclude patrons with restrictions
Bug 37418: delete_patrons.pl: Exclude patrons with restrictions
Bug 37418: (follow-up) Add unit tests for GetBorrowersToExpunge()
Bug 37418: delete_patrons.pl: Exclude patrons with restrictions
Bug 37418: (follow-up) Add unit tests for GetBorrowersToExpunge()
Bug 37418: delete_patrons.pl: Exclude patrons with restrictions

Description Michaela Sieber 2024-07-22 08:13:17 UTC
In some cases we don't want borrowers / patrons not to be deleted if they have certain restrictions.
Therefor we add a new parameter to the cronjob delete_patrons.pl
(see manual  
https://koha-community.org/manual/latest/en/html/cron_jobs.html#batch-delete-patrons )
Comment 1 Raphael Straub 2024-07-26 10:28:09 UTC
Created attachment 169688 [details] [review]
Bug 37418: delete_patrons.pl: Exclude patrons with restrictions

Add the option "--without_restriction_type" so that delete_patrons.pl
does not delete patrons with given restriction types.

To test:
1) Run
   misc/cronjobs/delete_patrons.pl --not_borrowed_since 2010-01-01
   and choose a borrowernumber that would be deleted.
2) In your browser go to
   /cgi-bin/koha/members/moremember.pl?borrowernumber=<borrowernumber>
   and add a manual restriction to this patron.
3) Apply the patch.
4) Run
   misc/cronjobs/delete_patrons.pl --not_borrowed_since 2010-01-01 \
       --without_restriction_type MANUAL
5) Check that the patron with the manual restriction would not be
   deleted.

Sponsored-by: Karlsruhe Institute of Technology (KIT)
Comment 2 Roman Dolny 2024-07-30 21:43:13 UTC
Created attachment 169879 [details] [review]
Bug 37418: delete_patrons.pl: Exclude patrons with restrictions

Add the option "--without_restriction_type" so that delete_patrons.pl
does not delete patrons with given restriction types.

To test:
1) Run
   misc/cronjobs/delete_patrons.pl --not_borrowed_since 2010-01-01
   and choose a borrowernumber that would be deleted.
2) In your browser go to
   /cgi-bin/koha/members/moremember.pl?borrowernumber=<borrowernumber>
   and add a manual restriction to this patron.
3) Apply the patch.
4) Run
   misc/cronjobs/delete_patrons.pl --not_borrowed_since 2010-01-01 \
       --without_restriction_type MANUAL
5) Check that the patron with the manual restriction would not be
   deleted.

Sponsored-by: Karlsruhe Institute of Technology (KIT)
Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>
Comment 3 Lucas Gass (lukeg) 2025-01-10 16:02:23 UTC
Can there be a unit test added to cover the changes to GetBorrowersToExpunge?
Comment 4 Raphael Straub 2025-01-14 11:00:43 UTC
(In reply to Lucas Gass (lukeg) from comment #3)
> Can there be a unit test added to cover the changes to GetBorrowersToExpunge?
Yes, I will add a unit test.
Comment 5 Raphael Straub 2025-01-20 10:08:53 UTC
Created attachment 176777 [details] [review]
Bug 37418: (follow-up) Add unit tests for GetBorrowersToExpunge()

Add unit tests for testing the new parameter without_restriction_types
of C4::Members::GetBorrowersToExpunge().

Sponsored-by: Karlsruhe Institute of Technology (KIT)
Comment 6 Raphael Straub 2025-03-11 09:50:53 UTC
Created attachment 179151 [details] [review]
Bug 37418: delete_patrons.pl: Exclude patrons with restrictions

Add the option "--without_restriction_type" so that delete_patrons.pl
does not delete patrons with given restriction types.

To test:
1) Run
   misc/cronjobs/delete_patrons.pl --not_borrowed_since 2010-01-01
   and choose a borrowernumber that would be deleted.
2) In your browser go to
   /cgi-bin/koha/members/moremember.pl?borrowernumber=<borrowernumber>
   and add a manual restriction to this patron.
3) Apply the patch.
4) Run
   misc/cronjobs/delete_patrons.pl --not_borrowed_since 2010-01-01 \
       --without_restriction_type MANUAL
5) Check that the patron with the manual restriction would not be
   deleted.

Sponsored-by: Karlsruhe Institute of Technology (KIT)
Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>
Comment 7 Thomas Klausner 2025-04-08 11:26:41 UTC
Created attachment 180715 [details] [review]
Bug 37418: (follow-up) Add unit tests for GetBorrowersToExpunge()

Add unit tests for testing the new parameter without_restriction_types
of C4::Members::GetBorrowersToExpunge().

Sponsored-by: Karlsruhe Institute of Technology (KIT)
Signed-off-by: Thomas Klausner <domm@plix.at>
Comment 8 Thomas Klausner 2025-04-08 11:26:44 UTC
Created attachment 180716 [details] [review]
Bug 37418: delete_patrons.pl: Exclude patrons with restrictions

Add the option "--without_restriction_type" so that delete_patrons.pl
does not delete patrons with given restriction types.

To test:
1) Run
   misc/cronjobs/delete_patrons.pl --not_borrowed_since 2010-01-01
   and choose a borrowernumber that would be deleted.
2) In your browser go to
   /cgi-bin/koha/members/moremember.pl?borrowernumber=<borrowernumber>
   and add a manual restriction to this patron.
3) Apply the patch.
4) Run
   misc/cronjobs/delete_patrons.pl --not_borrowed_since 2010-01-01 \
       --without_restriction_type MANUAL
5) Check that the patron with the manual restriction would not be
   deleted.

Sponsored-by: Karlsruhe Institute of Technology (KIT)
Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl>
Signed-off-by: Thomas Klausner <domm@plix.at>
Comment 9 Thomas Klausner 2025-04-08 11:27:46 UTC
I had to adapt the test (because of NoWarnings and changed test count upstream)

Besides that everything works as advertives in the test plan!
Comment 10 Katrin Fischer 2025-04-25 06:48:37 UTC
Pushed for 25.05!

Well done everyone, thank you!