]> git.mxchange.org Git - friendica.git/commitdiff
Issue 1312: Improve account expiry
authorMichael <heluecht@pirati.ca>
Sun, 18 Feb 2018 22:19:20 +0000 (22:19 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 18 Feb 2018 22:19:20 +0000 (22:19 +0000)
src/Worker/CronJobs.php

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