Skip to content

Commit

Permalink
formatting and commenting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 6, 2020
1 parent 30ffc91 commit 6c1ea42
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/Console/PurgeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,42 @@ class PurgeCommand extends Command
* @var string
*/
protected $signature = 'passport:purge
{--revoked : Only purge revoked tokens and auth codes}
{--expired : Only purge expired tokens and auth codes}';
{--revoked : Only purge revoked tokens and authentication codes}
{--expired : Only purge expired tokens and authentication codes}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Purges revoked and/or expired tokens and auth codes';
protected $description = 'Purge revoked and / or expired tokens and authentication codes';

/**
* Execute the console command.
*/
public function handle()
{
$options = $this->options();
$now = Carbon::now();
if (
($options['revoked'] && $options['expired']) ||
(! $options['revoked'] && ! $options['expired'])
) {
Token::where('revoked', 1)->orWhereDate('expires_at', '<', $now)->delete();
AuthCode::where('revoked', 1)->orWhereDate('expires_at', '<', $now)->delete();
RefreshToken::where('revoked', 1)->orWhereDate('expires_at', '<', $now)->delete();
} elseif ($options['revoked']) {
$expired = Carbon::now()->subDays(7);

if (($this->option('revoked') && $this->option('expired')) ||
(! $this->option('revoked') && ! $this->option('expired'))) {
Token::where('revoked', 1)->orWhereDate('expires_at', '<', $expired)->delete();
AuthCode::where('revoked', 1)->orWhereDate('expires_at', '<', $expired)->delete();
RefreshToken::where('revoked', 1)->orWhereDate('expires_at', '<', $expired)->delete();

$this->info('Purged revoked items and items expired for more than seven days.');
} elseif ($this->option('revoked')) {
Token::where('revoked', 1)->delete();
AuthCode::where('revoked', 1)->delete();
RefreshToken::where('revoked', 1)->delete();
} elseif ($options['expired']) {
Token::whereDate('expires_at', '<', $now)->delete();
AuthCode::whereDate('expires_at', '<', $now)->delete();
RefreshToken::whereDate('expires_at', '<', $now)->delete();

$this->info('Purged revoked items.');
} elseif ($this->option('expired')) {
Token::whereDate('expires_at', '<', $expired)->delete();
AuthCode::whereDate('expires_at', '<', $expired)->delete();
RefreshToken::whereDate('expires_at', '<', $expired)->delete();

$this->info('Purged items expired for more than seven days.');
}
}
}

0 comments on commit 6c1ea42

Please sign in to comment.