service class downgrade to the default service class on account expiration if using a non-default service class and account has expired.
This commit is contained in:
parent
9a51f8ce65
commit
7d4916ec71
@ -401,3 +401,55 @@ function user_deny($hash) {
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @function downgrade_accounts()
|
||||
* Checks for accounts that have past their expiration date.
|
||||
* If the account has a service class which is not the site default,
|
||||
* the service class is reset to the site default and expiration reset to never.
|
||||
* If the account has no service class it is expired and subsequently disabled.
|
||||
* called from include/poller.php as a scheduled task.
|
||||
*
|
||||
* Reclaiming resources which are no longer within the service class limits is
|
||||
* not the job of this function, but this can be implemented by plugin if desired.
|
||||
* Default behaviour is to stop allowing additional resources to be consumed.
|
||||
*/
|
||||
|
||||
|
||||
function downgrade_accounts() {
|
||||
|
||||
$r = q("select * from account where not ( account_flags & %d )
|
||||
and account_expires != '0000-00-00 00:00:00'
|
||||
and account_expires < UTC_TIMESTAMP() ",
|
||||
intval(ACCOUNT_EXPIRED)
|
||||
);
|
||||
|
||||
if(! $r)
|
||||
return;
|
||||
|
||||
$basic = get_config('system','default_service_class');
|
||||
|
||||
|
||||
foreach($r as $rr) {
|
||||
|
||||
if(($basic) && ($rr['account_service_class']) && ($rr['account_service_class'] != $basic)) {
|
||||
$x = q("UPDATE account set account_service_class = '%s', account_expires = '%s'
|
||||
where account_id = %d limit 1",
|
||||
dbesc($basic),
|
||||
dbesc('0000-00-00 00:00:00'),
|
||||
intval($rr['account_id'])
|
||||
);
|
||||
call_hooks('account_downgrade', array('account' => $rr));
|
||||
logger('downgrade_accounts: Account id ' . $rr['account_id'] . ' downgraded.');
|
||||
}
|
||||
else {
|
||||
$x = q("UPDATE account SET account_flags = (account_flags | %d) where account_id = %d limit 1",
|
||||
intval(ACCOUNT_EXPIRED),
|
||||
intval($rr['account_id'])
|
||||
);
|
||||
call_hooks('account_downgrade', array('account' => $rr));
|
||||
logger('downgrade_accounts: Account id ' . $rr['account_id'] . ' expired.');
|
||||
}
|
||||
}
|
||||
}
|
@ -32,16 +32,6 @@ function poller_run($argv, $argc){
|
||||
|
||||
proc_run('php',"include/queue.php");
|
||||
|
||||
// expire any expired accounts
|
||||
|
||||
q("UPDATE account
|
||||
SET account_flags = (account_flags | %d)
|
||||
where not (account_flags & %d)
|
||||
and account_expires != '0000-00-00 00:00:00'
|
||||
and account_expires < UTC_TIMESTAMP() ",
|
||||
intval(ACCOUNT_EXPIRED),
|
||||
intval(ACCOUNT_EXPIRED)
|
||||
);
|
||||
|
||||
// expire any expired mail
|
||||
|
||||
@ -115,6 +105,9 @@ function poller_run($argv, $argc){
|
||||
|
||||
q("delete from notify where seen = 1 and date < UTC_TIMESTAMP() - INTERVAL 30 DAY");
|
||||
|
||||
// expire any expired accounts
|
||||
require_once('include/account.php');
|
||||
downgrade_accounts();
|
||||
|
||||
// If this is a directory server, request a sync with an upstream
|
||||
// directory at least once a day, up to once every poll interval.
|
||||
|
Reference in New Issue
Block a user