Bug 39463

Summary: delete_patrons.pl to delete all patrons or provide reason why they're not deleted
Product: Koha Reporter: Caroline Cyr La Rose <caroline.cyr-la-rose>
Component: Command-line UtilitiesAssignee: Bugs List <koha-bugs>
Status: NEW --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: aude.charillon, robin
Version: unspecified   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=24483
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:

Description Caroline Cyr La Rose 2025-03-26 18:50:40 UTC
I'm trying to use the delete_patrons.pl script to delete all the patrons from a library (the library closed and I'm trying to delete everything from the environment which it shared with other independent libraries). I noticed I have to run it several times in order to delete all the patrons, but even with -v, it doesn't tell me why it doesn't delete some patrons.

Note that I already returned all the checkouts and written off all the unpaid charges for the patrons of that library.

I was able to recreate it partially on KTD
1. Count the patrons per branch before running the script

MariaDB [koha_kohadev]> select branchcode, count(*) from borrowers group by branchcode;
+------------+----------+
| branchcode | count(*) |
+------------+----------+
| CPL        |        3 |
| FRL        |        9 |
| MPL        |       18 |
| PVL        |        1 |
| SPL        |       22 |
+------------+----------+
5 rows in set (0.001 sec)

2. Use delete_patrons.pl to delete all MPL patrons

./misc/cronjobs/delete_patrons.pl --library MPL --confirm -v

Notice it says only 16 patrons "match conditions" even though I have 18 patrons with MPL branchcode. It does not explain why there are some that don't match. 

On my test DB for the actual environment, I have to run the script several times in a row to delete almost all the ~1000 patrons. When I run it the first time, it says 925 matches, then 88, then 1 then 0. And even after it says there are 0 matches, there are still 6 patrons in the database. It's probably the staff users, but I'd like it to tell me.

Maybe I'm misunderstanding the way this works. For example, in the KTD database, I would expect it to "match" all 18 patrons whose branchcode is MPL and tell me why the two are not deletable.
Comment 1 Caroline Cyr La Rose 2025-03-26 18:51:45 UTC
I did a whole rant on my specific use case here https://chat.koha-community.org/koha-community/pl/je4c6rgfijyqzqsij1ornwn1dc