Aurora Corporate documentation

Deleting inactive users

This sample demonstrates deleting user accounts nobody logged into in a while, for example, within last 6 months. One of the reasons why you may wish to do it is to maintain a reasonable number of user accounts, in order to stay within licensed users count.

Please note that deleting user account is an irreversible operation, all the contacts, calendars, account settings and linked accounts will be removed. Since mail is stored on IMAP server, mail messages and folders will not be affected. Should this user log in again, they will get back into their email account just fine.

include './system/autoload.php';
$oCoreDecorator = \Aurora\Modules\Core\Module::Decorator();
$ul = $oCoreDecorator->GetUsers();
$ulItems = $ul["Items"];
foreach ($ulItems as $key=>$item) {
    $sEmail = $item["PublicId"];
    $oUser = $oCoreDecorator->GetUserByPublicId($sEmail);
    $dTime = $oUser->LastLogin; $iAge = time()-strtotime($dTime);
    if (($dTime !== null)&&($iAge > 6*30*24*60*60)) {
        $iUserId = $oUser->EntityId;
        echo "<p>$sEmail user deleted</p>";

For production use, you'll probably wish to replace echo line with adding a log record, especially if this is placed into cronjobs for running periodically.

We're omitting the accounts which don't have LastLogin information saved for them - for instance, the account was created in admin panel but user never logged into it. Should you wish to remove those users as well, modify the condition as follows:

    if (($dTime === null)||($iAge > 6*30*24*60*60)) {

The code was tested on current v9 of Aurora Corporate and should work just fine on the previous 8.* as well.