Last active
February 12, 2016 01:11
-
-
Save anhtuank7c/a4becbf5db9932542410 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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