-
Notifications
You must be signed in to change notification settings - Fork 19
Add cleanup variable to verify function + cleanup command #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| class CleanupVerificationCodesCommand extends Command | ||
| { | ||
| protected $signature = 'verification-code:cleanup {days : Codes older than these days will be deleted.}'; | ||
|
|
||
| protected $description = 'Remove verification code older than the given days.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| class CleanupVerificationCodesCommand extends Command | |
| { | |
| protected $signature = 'verification-code:cleanup {days : Codes older than these days will be deleted.}'; | |
| protected $description = 'Remove verification code older than the given days.'; | |
| class PruneCommand extends Command | |
| { | |
| protected $signature = 'verification-code:prune {--hours=24 : The number of hours to retain verification codes}'; | |
| protected $description = 'Prune old verification codes'; |
I would set it up similarly to the prune command of Telescope (https://github.com/laravel/telescope/blob/4.x/src/Console/PruneCommand.php)
src/VerificationCodeManager.php
Outdated
| * @return bool | ||
| */ | ||
| public function verify(string $code, string $verifiable) | ||
| public function verify(string $code, string $verifiable, bool $cleanup = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, maybe we should call it $deleteAfterVerification 🤔 so there can not be any confusion about the meaning.
can you also document this extra option?
| VerificationCode::query() | ||
| ->where('created_at', '<=', now()->subDays($days)) | ||
| ->delete(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| VerificationCode::query() | |
| ->where('created_at', '<=', now()->subDays($days)) | |
| ->delete(); | |
| VerificationCode::where('created_at', '<=', now()->subDays($days))->delete(); |
can be on one line
src/VerificationCodeManager.php
Outdated
| * | ||
| * @param string $code | ||
| * @param string $verifiable | ||
| * @param bool $cleanup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * @param bool $cleanup | |
| * @param bool $deleteAfterVerification |
tests/Commands/PruneCommandTest.php
Outdated
|
|
||
| $this->artisan('verification-code:prune', ['--hours' => 3]); | ||
|
|
||
| $dbVerificationCode = VerificationCode::all(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $dbVerificationCode = VerificationCode::all(); | |
| $dbVerificationCodes = VerificationCode::all(); |
Fixes #22 #21