Merge pull request #4474 from annando/issue-1312

Issue 1312: Improve account expiry
This commit is contained in:
Hypolite Petovan 2018-02-18 17:37:01 -05:00 committed by GitHub
commit dcd08c5236
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,6 +12,7 @@ use Friendica\Database\PostUpdate;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\User;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
use dba; use dba;
@ -106,17 +107,20 @@ class CronJobs
*/ */
private static function expireAndRemoveUsers() private static function expireAndRemoveUsers()
{ {
// expire any expired accounts // expire any expired regular accounts. Don't expire forums.
q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0 $condition = ["NOT `account_expired` AND `account_expires_on` > ? AND `account_expires_on` < UTC_TIMESTAMP() AND `page-flags` = 0", NULL_DATE];
AND `account_expires_on` > '%s' dba::update('user', ['account_expired' => true], $condition);
AND `account_expires_on` < UTC_TIMESTAMP()", dbesc(NULL_DATE));
// Remove any freshly expired account
$users = dba::select('user', ['uid'], ['account_expired' => true, 'account_removed' => false]);
while ($user = dba::fetch($users)) {
User::remove($user['uid']);
}
// delete user records for recently removed accounts // delete user records for recently removed accounts
$r = q("SELECT * FROM `user` WHERE `account_removed` AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY"); $users = dba::select('user', ['uid'], ["`account_removed` AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY"]);
if (DBM::is_result($r)) { while ($user = dba::fetch($users)) {
foreach ($r as $user) { dba::delete('user', ['uid' => $user['uid']]);
dba::delete('user', ['uid' => $user['uid']]);
}
} }
} }