Delete users older than this.

@return string[]
356996
private function monthOptions(): array
    {
        return [
            3  => I18N::number(3),
            6  => I18N::number(6),
            9  => I18N::number(9),
            12 => I18N::number(12),
            18 => I18N::number(18),
            24 => I18N::number(24),
        ];
    }
976638
public function delete(): void
    {
        if (!userHasPermission('admin:auth:accounts:delete')) {
            unauthorised();
        }

        // --------------------------------------------------------------------------

        //  Get the user's details
        $oUri       = Factory::service('Uri');
        $oInput     = Factory::service('Input');
        $oSession   = Factory::service('Session', 'nails/module-auth');
        $oUserModel = Factory::model('User', 'nails/module-auth');
        $iUserId    = $oUri->segment(5);
        $oUser      = $oUserModel->getById($iUserId);

        // --------------------------------------------------------------------------

        //  Non-superusers editing superusers is not cool
        if (!isSuperuser() && userHasPermission('superuser', $oUser)) {
            $oSession->setFlashData('error', lang('accounts_edit_error_noteditable'));
            $this->returnToIndex();
        }

        // --------------------------------------------------------------------------

        //  Delete user
        $oUser = $oUserModel->getById($iUserId);

        if (!$oUser) {
            show404();
        } elseif ($oUser->id == activeUser('id')) {
            $oSession->setFlashData('error', lang('accounts_delete_error_selfie'));
            $this->returnToIndex();
        }

        // --------------------------------------------------------------------------

        //  Define messages
        if ($oUserModel->destroy($iUserId)) {

            $sStatus  = 'success';
            $sMessage = lang('accounts_delete_success', title_case($oUser->first_name . ' ' . $oUser->last_name));

            //  Update admin changelog
            $this->oChangeLogModel->add(
                'deleted',
                'a',
                'user',
                $iUserId,
                '#' . number_format($iUserId) . ' ' . $oUser->first_name . ' ' . $oUser->last_name
            );

        } else {
            $sStatus  = 'error';
            $sMessage = lang('accounts_delete_error', title_case($oUser->first_name . ' ' . $oUser->last_name));
        }

        $oSession->setFlashData($sStatus, $sMessage);

        // --------------------------------------------------------------------------

        $this->returnToIndex();
    }
818319
public function getCurrentUserPrincipals()
    {
        $currentUser = $this->getCurrentUserPrincipal();

        if (is_null($currentUser)) {
            return [];
        }

        return array_merge(
            [$currentUser],
            $this->getPrincipalMembership($currentUser)
        );
    }
959106
public function getAssignedMembers()
    {
        $list   = new ArrayList();
        $groups = $this->Groups();

        $list->merge($this->Users());

        foreach ($groups as $group) {
            $list->merge($group->Members());
        }

        $list->removeDuplicates();
        return $list;
    }
1193822
public function clear()
    {
        $params = [
            'index' => $this->_esindex,
            'type' => $this->_estype,
            'body' => [
                'query' => [
                    'match_all' => []
                ]
            ]
        ];
        $query = $this->_es->deleteByQuery($params); 
        // return $query['_indices']['tweets']['_shards']['successful'];
        $result = true;
        return $result;
    }
1028846
private function cleanup()
    {
        if (isset($this->collection[$this->id_info])) {
            foreach ($this->collection[$this->id_info] as $key => $val) {
                $expire = $this->getSessionInfo($key, 'expire');
                if ($expire === true) {
                    $this->setSessionInfo($key, 'expire', -1);
                } elseif ($expire == -1) {
                    $this->delete($key);
                }
            }
        }
    }
966391
public function deleteUserAction()
    {
        if(!$this->identity()) {
          return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
        }
      
        $id = (int) $this->params()->fromRoute('id', 0);

        if ($id == 0) {
            $this->flashMessenger()->addErrorMessage($this->getTranslatorHelper()->translate('User ID invalid'));
            return $this->redirect()->toRoute('user-admin');
        }
           
        try {
            $entityManager = $this->getEntityManager();
            $user = $entityManager->getRepository('CsnUser\Entity\User')->find($id);
            $entityManager->remove($user);
            $entityManager->flush();
            $this->flashMessenger()->addSuccessMessage($this->getTranslatorHelper()->translate('User Deleted Successfully'));
        }
        catch (\Exception $e) {
            return $this->getServiceLocator()->get('csnuser_error_view')->createErrorView(
                $this->getTranslatorHelper()->translate('Something went wrong during user delete process! Please, try again later.'),
                $e,
                $this->getOptions()->getDisplayExceptions(),
                false
            );
        }

        return $this->redirect()->toRoute('user-admin');
    }
134498
public function removeExpiredRegistrations($conditions = []) {
		$defaults = [
			$this->_table->aliasField($this->_field('emailVerified')) => 0,
			$this->_table->aliasField($this->_field('emailTokenExpires')) . ' <' => date('Y-m-d H:i:s')
		];

		$conditions = Hash::merge($defaults, $conditions);
		$count = $this->_table
			->find()
			->where($conditions)
			->count();

		if ($count > 0) {
			$this->_table->deleteAll($conditions);
		}

		return $count;
	}
1115353
public function getUsers() : array
    {
        /** @var \Adldap\Query\Builder $query */
        $query = Resolver::query();

        if ($filter = $this->option('filter')) {
            // If the filter option was given, we'll
            // insert it into our search query.
            $query->rawFilter($filter);
        }

        if ($user = $this->argument('user')) {
            $users = [$query->findOrFail($user)];
        } else {
            // Retrieve all users. We'll paginate our search in case we
            // hit the 1000 record hard limit of active directory.
            $users = $query->paginate()->getResults();
        }

        // We need to filter our results to make sure they are
        // only users. In some cases, Contact models may be
        // returned due the possibility of them
        // existing in the same scope.
        return array_filter($users, function ($user) {
            return $user instanceof User;
        });
    }
181628
public function deleteUserForced($uid)
    {
        $return['error'] = true;

        $query = "DELETE FROM {$this->config->table_users} WHERE id = :uid";
        $query_prepared = $this->dbh->prepare($query);

        if (!$query_prepared->execute(['uid' => $uid])) {
            $return['message'] = $this->__lang("system_error") . " #05";

            return $return;
        }

        $query = "DELETE FROM {$this->config->table_sessions} WHERE uid = :uid";
        $query_prepared = $this->dbh->prepare($query);

        if (!$query_prepared->execute(['uid' => $uid])) {
            $return['message'] = $this->__lang("system_error") . " #06";

            return $return;
        }

        $query = "DELETE FROM {$this->config->table_requests} WHERE uid = :uid";
        $query_prepared = $this->dbh->prepare($query);

        if (!$query_prepared->execute(['uid' => $uid])) {
            $return['message'] = $this->__lang("system_error") . " #07";

            return $return;
        }

        $return['error'] = false;
        $return['message'] = $this->__lang("account_deleted");

        return $return;
    }
163573
public function handleExpiration() : array
    {
        $deleted   = [];
        $cacheKeys = $this->cache->keys();

        foreach ($cacheKeys as $key) {
            $fileMeta = $this->cache->get($key, true);

            if ( ! $this->isExpired($fileMeta)) {
                continue;
            }

            if ( ! $this->cache->delete($key)) {
                continue;
            }

            if (is_writable($fileMeta['file_path'])) {
                unlink($fileMeta['file_path']);
            }

            $deleted[] = $fileMeta;
        }

        return $deleted;
    }
278193
public function cleanUsers()
    {
        // Remove any users that were created.
        if ($this->userManager->hasUsers()) {
            foreach ($this->userManager->getUsers() as $user) {
                $this->getDriver()->userDelete($user);
            }
            $this->getDriver()->processBatch();
            $this->userManager->clearUsers();
            // If the authentication manager supports logout, no need to check if the user is logged in.
            if ($this->getAuthenticationManager() instanceof FastLogoutInterface) {
                $this->logout(true);
            } elseif ($this->loggedIn()) {
                $this->logout();
            }
        }
    }
1171914
private function deleteOldSessions()
    {
        // 2% chance of kicking idle sessions
        if (mt_rand(0, 49)) {
            return false;
        }

        $sessions = new UsersSessionEntityRepository();
        $sessions->setOnlyOutdated();
        $sessions->deleteObjectCollection();

        return true;
    }
184003
private function flushDeletes()
    {
        $ids = array();
        foreach ($this->bulkDeleteRecords as $record) {
            $ids[] = $record->Id;
        }

        $result = $this->client->delete($ids);
        $this->bulkDeleteRecords = array();

        return $result;
    }
836646
public function getActiveTimers()
    {
        $result = $this->getActiveUsers( );
        if ( $result->isSuccess() ) {
            $data = array();
            foreach ($result->data as $user) {
                $subResult = $this->getUserEntries( $user->id, Range::today( $this->_timeZone ) );
                if ( $subResult->isSuccess() ) {
                    foreach ($subResult->data as $entry) {
                        if ($entry->timer_started_at != null || $entry->timer_started_at != "") {
                            $data[$user->id] = $entry;
                            break;
                        }
                    }
                }
            }
            $result->data = $data;
        }

        return $result;
    }
498175
public function findExpiredIdentifiers(): array
    {
        $queryBuilder = $this->createQuery();
        $rows = $queryBuilder->select('identifier')
            ->from($this->getTableName())
            ->where($queryBuilder->expr()->lt(
                'expires',
                $queryBuilder->createNamedParameter((new DateTimeService())->getCurrentTime(), \PDO::PARAM_INT)
            ))
            ->groupBy('identifier')
            ->execute()
            ->fetchAll();

        $cacheIdentifiers = [];
        foreach ($rows as $row) {
            $cacheIdentifiers[] = $row['identifier'];
        }

        return $cacheIdentifiers;
    }
1118287
public function deleteEach()
    {
        $objectIterator = $this->fetchIterator();
        $result = [];
        foreach ($objectIterator as $object) {
            $result[] = !$object->delete();
        }
        return $result;
    }