mirror of
https://github.com/standardebooks/web.git
synced 2025-07-04 22:00:35 -04:00
35 lines
1 KiB
PHP
Executable file
35 lines
1 KiB
PHP
Executable file
#!/usr/bin/php
|
|
<?
|
|
/**
|
|
* Get a list of payments that are within 1 year / 45 days of today, and deactivate Patrons Circle members who aren't in that list.
|
|
* We give a 15 day grace period to Patrons Circle members because sometimes FA can be delayed in charging.
|
|
*/
|
|
|
|
require_once('/standardebooks.org/web/lib/Core.php');
|
|
|
|
$expiredPatrons = Db::Query('
|
|
SELECT * from Patrons where
|
|
Ended is null
|
|
and
|
|
UserId not in
|
|
(
|
|
select distinct p.UserId from Patrons p
|
|
inner join Payments py
|
|
using (UserId)
|
|
where
|
|
p.Ended is null and
|
|
(
|
|
(IsRecurring = true and CycleType = ? and Amount >= p.BaseCost and py.Created > ? - interval 45 day)
|
|
or
|
|
(IsRecurring = false and CycleType = ? and Amount >= p.BaseCost and py.Created > ? - interval 1 year)
|
|
)
|
|
)
|
|
', [Enums\CycleType::Monthly, NOW, Enums\CycleType::Yearly, NOW], Patron::class);
|
|
|
|
if(sizeof($expiredPatrons) > 0){
|
|
$ebooksThisYear = Db::QueryInt('SELECT count(*) from Ebooks where EbookCreated >= ? - interval 1 year', [NOW]);
|
|
|
|
foreach($expiredPatrons as $patron){
|
|
$patron->End($ebooksThisYear);
|
|
}
|
|
}
|