Skip to content

Instantly share code, notes, and snippets.

@anhtuank7c
Last active February 12, 2016 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anhtuank7c/a4becbf5db9932542410 to your computer and use it in GitHub Desktop.
Save anhtuank7c/a4becbf5db9932542410 to your computer and use it in GitHub Desktop.
<?php
namespace App\Shell\Task;
use Cake\Console\Shell;
use Cake\Core\Configure;
use Cake\ORM\TableRegistry;
/**
* DeleteExpiredInactiveAccountTask
* Delete all user has status Inactive and expired token
*/
class DeleteExpiredPreactiveAccountTask extends Shell
{
public function main()
{
$Users = TableRegistry::get('Users');
$expired = Configure::read('Expired.signup');
$inactiveUsers = $Users->find('all', ['conditions' => ['status' => 'PREACTIVE']]);
$listExpired = [];
foreach ($inactiveUsers as $user) {
if (!$user->token_created || $user->token_created->wasWithinLast($expired)) {
continue;
}
array_push($listExpired, $user->email);
$Users->delete($user);
}
if (sizeof($listExpired) > 0) {
audit_log([
'subject' => $this->name,
'action' => 'CRONTAB',
'description' => 'DeleteExpiredPreactiveAccountTask: ' . sizeof($listExpired) . ' user has been wiped. Detail: ' . implode(', ', $listExpired),
'created_by' => '0',
'ip' => null,
'user_agent' => null,
], 'crontab');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment