config = $config; $this->entityManager = $entityManager; } public function run(): void { $authTokenLifetime = $this->config->get('authTokenLifetime'); $authTokenMaxIdleTime = $this->config->get('authTokenMaxIdleTime'); if (!$authTokenLifetime && !$authTokenMaxIdleTime) { return; } $whereClause = [ 'isActive' => true, ]; if ($authTokenLifetime) { $dt = new DateTime(); $dt->modify('-' . $authTokenLifetime . ' hours'); $authTokenLifetimeThreshold = $dt->format('Y-m-d H:i:s'); $whereClause['createdAt<'] = $authTokenLifetimeThreshold; } if ($authTokenMaxIdleTime) { $dt = new DateTime(); $dt->modify('-' . $authTokenMaxIdleTime . ' hours'); $authTokenMaxIdleTimeThreshold = $dt->format('Y-m-d H:i:s'); $whereClause['lastAccess<'] = $authTokenMaxIdleTimeThreshold; } $tokenList = $this->entityManager ->getRepository('AuthToken') ->where($whereClause) ->limit(0, 500) ->find(); foreach ($tokenList as $token) { $token->set('isActive', false); $this->entityManager->saveEntity($token); } } }