Bug 41786

Summary: membership_expiry.pl -renew -active should include patrons 0-MembershipExpiryDaysNotice days before expiration
Product: Koha Reporter: Lari Taskula <lari.taskula>
Component: Command-line UtilitiesAssignee: Bugs List <koha-bugs>
Status: In Discussion --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: robin
Version: unspecified   
Hardware: All   
OS: All   
GIT URL: Initiative type: ---
Sponsorship status: --- Comma delimited list of Sponsors:
Crowdfunding goal: 0 Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Bug 41786: membership_expiry.pl -renew -active should include patrons 0-MembershipExpiryDaysNotice days before expiration

Description Lari Taskula 2026-02-06 11:41:45 UTC
membership_expiry.pl -renew -active should include patrons 0-MembershipExpiryDaysNotice days before expiration, not exactly MembershipExpiryDaysNotice days before expiration.

membership_expiry.pl selects patrons who are expiring in exactly n days where n is the value from MembershipExpiryDaysNotice preference. Let's say, 30 as an example.

When we have a cronjob with the following flags

membership_expiry.pl -c -n -renew 12 -active

it would be expected behavior to renew patrons who are about to expire within 30 days and who have been active in the last 12 months, last activity defined by borrowers.lastseen.

It is not the case when lastseen is >12 months away at exactly 30 days from expiration, but <12 months <30 days from expiration. This could happen when login is defined as activity, and patron who hasn't been active receives a notification of an expiring account then logins to update their activity. Once the 30-day mark has been passed, such patrons will simply be ignored and they will expire.

This can be fixed with the -before flag, but I think it is unexpected behavior. Also you can only hardcode a value to -before, so if you change MembershipExpiryDaysNotice, it will not update the -before value.

I think the expected behavior is to renew patrons 0-MembershipExpiryDaysNotice days before expiration.
Comment 1 Lari Taskula 2026-02-06 11:45:52 UTC
I think this needs some discussion first.

We can't just change the behavior without having consensus, because this change could break someone's cronjob workflow.
Comment 2 Lari Taskula 2026-02-06 11:55:37 UTC
(In reply to Lari Taskula from comment #0)
> This can be fixed with the -before flag, but I think it is unexpected
> behavior. Also you can only hardcode a value to -before, so if you change
> MembershipExpiryDaysNotice, it will not update the -before value.

An alternative solution might be to use the --where flag and do a subquery selecting the value from MembershipExpiryDaysNotice. But I'm not a big fan of that solution.
Comment 3 Lari Taskula 2026-02-06 12:05:11 UTC
(In reply to Lari Taskula from comment #0)
> membership_expiry.pl -c -n -renew 12 -active
Correction,
membership_expiry.pl -c -n -renew -active 12

I wish Bugzilla had an option to edit :)
Comment 4 Lari Taskula 2026-02-06 12:16:05 UTC
Created attachment 192612 [details] [review]
Bug 41786: membership_expiry.pl -renew -active should include patrons 0-MembershipExpiryDaysNotice days before expiration