From 8c1d19aafdf95f70e1e8f084e6b81d042aef5e66 Mon Sep 17 00:00:00 2001 From: Marick van Tuil Date: Mon, 13 Aug 2018 20:40:42 +0200 Subject: [PATCH 1/3] Remove email:retry --- src/LaravelDatabaseEmailsServiceProvider.php | 1 - src/ResendEmailsCommand.php | 57 +++++++++++++++++++- tests/RetryFailedEmailsCommandTest.php | 14 ----- 3 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/LaravelDatabaseEmailsServiceProvider.php b/src/LaravelDatabaseEmailsServiceProvider.php index 80cbb29..b38894b 100644 --- a/src/LaravelDatabaseEmailsServiceProvider.php +++ b/src/LaravelDatabaseEmailsServiceProvider.php @@ -33,7 +33,6 @@ public function register() { $this->commands([ SendEmailsCommand::class, - RetryFailedEmailsCommand::class, ResendEmailsCommand::class, ]); } diff --git a/src/ResendEmailsCommand.php b/src/ResendEmailsCommand.php index 4ae8f8c..80bf9a6 100644 --- a/src/ResendEmailsCommand.php +++ b/src/ResendEmailsCommand.php @@ -2,7 +2,9 @@ namespace Buildcode\LaravelDatabaseEmails; -class ResendEmailsCommand extends RetryFailedEmailsCommand +use Illuminate\Console\Command; + +class ResendEmailsCommand extends Command { /** * The name and signature of the console command. @@ -17,4 +19,57 @@ class ResendEmailsCommand extends RetryFailedEmailsCommand * @var string */ protected $description = 'Resend failed e-mails'; + + /** + * The e-mail repository. + * + * @var Store + */ + protected $store; + + /** + * Create a new SendEmailsCommand instance. + * + * @param Store $store + */ + public function __construct(Store $store) + { + parent::__construct(); + + $this->store = $store; + } + + /** + * Execute the console command. + * + * @return void + */ + public function handle() + { + $emails = $this->store->getFailed( + $this->argument('id') + ); + + if ($emails->isEmpty()) { + $this->line('There is nothing to reset.'); + + return; + } + + foreach ($emails as $email) { + $email->retry(); + } + + $this->info('Reset ' . $emails->count() . ' ' . ngettext('e-mail', 'e-mails', $emails->count()) . '!'); + } + + /** + * Execute the console command (backwards compatibility for Laravel 5.4 and below). + * + * @return void + */ + public function fire() + { + $this->handle(); + } } diff --git a/tests/RetryFailedEmailsCommandTest.php b/tests/RetryFailedEmailsCommandTest.php index 794eda1..d8a64cf 100644 --- a/tests/RetryFailedEmailsCommandTest.php +++ b/tests/RetryFailedEmailsCommandTest.php @@ -50,18 +50,4 @@ public function a_single_email_can_be_resent() $this->assertEquals(3, DB::table('emails')->count()); } - - /** @test */ - public function email_retry_is_deprecated() - { - $deprecated = 'This command is deprecated'; - - $this->artisan('email:retry'); - - $this->assertContains($deprecated, Artisan::output()); - - $this->artisan('email:resend'); - - $this->assertNotContains($deprecated, Artisan::output()); - } } From 40216b34d4e28297baf54fffe6df06dd417f5edf Mon Sep 17 00:00:00 2001 From: Marick van Tuil Date: Fri, 31 Aug 2018 22:25:36 +0200 Subject: [PATCH 2/3] Remove timeout option --- src/SendEmailsCommand.php | 6 +----- tests/SendEmailsCommandTest.php | 14 -------------- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/SendEmailsCommand.php b/src/SendEmailsCommand.php index 9588ab1..c9867f2 100644 --- a/src/SendEmailsCommand.php +++ b/src/SendEmailsCommand.php @@ -13,7 +13,7 @@ class SendEmailsCommand extends Command * * @var string */ - protected $signature = 'email:send {--timeout=300}'; + protected $signature = 'email:send'; /** * The console command description. @@ -48,8 +48,6 @@ public function __construct(Store $store) */ public function handle() { - set_time_limit($this->option('timeout')); - $emails = $this->store->getQueue(); if ($emails->isEmpty()) { @@ -73,8 +71,6 @@ public function handle() $progress->finish(); $this->result($emails); - - set_time_limit(0); } /** diff --git a/tests/SendEmailsCommandTest.php b/tests/SendEmailsCommandTest.php index 1d3e3e0..33a0b1e 100644 --- a/tests/SendEmailsCommandTest.php +++ b/tests/SendEmailsCommandTest.php @@ -122,18 +122,4 @@ public function the_failed_status_and_error_is_cleared_if_a_previously_failed_em $this->assertFalse($email->fresh()->hasFailed()); $this->assertEmpty($email->fresh()->getError()); } - - /** @test */ - public function the_command_will_be_stopped_after_the_timeout() - { - $this->assertEquals(0, ini_get('max_execution_time')); - - $this->artisan('email:send'); - - $this->assertEquals(300, ini_get('max_execution_time')); - - $this->artisan('email:send', ['--timeout' => 60]); - - $this->assertEquals(60, ini_get('max_execution_time')); - } } From c259aa2bef09e155ebf98de162e53124e9d2934f Mon Sep 17 00:00:00 2001 From: Marick van Tuil Date: Fri, 31 Aug 2018 22:34:29 +0200 Subject: [PATCH 3/3] Remove email:resend --- src/LaravelDatabaseEmailsServiceProvider.php | 1 - src/ResendEmailsCommand.php | 75 ------------------- src/RetryFailedEmailsCommand.php | 79 -------------------- src/Store.php | 21 ------ tests/RetryFailedEmailsCommandTest.php | 53 ------------- 5 files changed, 229 deletions(-) delete mode 100644 src/ResendEmailsCommand.php delete mode 100644 src/RetryFailedEmailsCommand.php delete mode 100644 tests/RetryFailedEmailsCommandTest.php diff --git a/src/LaravelDatabaseEmailsServiceProvider.php b/src/LaravelDatabaseEmailsServiceProvider.php index b38894b..3796a2a 100644 --- a/src/LaravelDatabaseEmailsServiceProvider.php +++ b/src/LaravelDatabaseEmailsServiceProvider.php @@ -33,7 +33,6 @@ public function register() { $this->commands([ SendEmailsCommand::class, - ResendEmailsCommand::class, ]); } } diff --git a/src/ResendEmailsCommand.php b/src/ResendEmailsCommand.php deleted file mode 100644 index 80bf9a6..0000000 --- a/src/ResendEmailsCommand.php +++ /dev/null @@ -1,75 +0,0 @@ -store = $store; - } - - /** - * Execute the console command. - * - * @return void - */ - public function handle() - { - $emails = $this->store->getFailed( - $this->argument('id') - ); - - if ($emails->isEmpty()) { - $this->line('There is nothing to reset.'); - - return; - } - - foreach ($emails as $email) { - $email->retry(); - } - - $this->info('Reset ' . $emails->count() . ' ' . ngettext('e-mail', 'e-mails', $emails->count()) . '!'); - } - - /** - * Execute the console command (backwards compatibility for Laravel 5.4 and below). - * - * @return void - */ - public function fire() - { - $this->handle(); - } -} diff --git a/src/RetryFailedEmailsCommand.php b/src/RetryFailedEmailsCommand.php deleted file mode 100644 index e6764af..0000000 --- a/src/RetryFailedEmailsCommand.php +++ /dev/null @@ -1,79 +0,0 @@ -store = $store; - } - - /** - * Execute the console command. - * - * @return void - */ - public function handle() - { - if (get_class($this) === self::class) { - $this->warn('This command is deprecated, please use email:resend instead'); - } - - $emails = $this->store->getFailed( - $this->argument('id') - ); - - if ($emails->isEmpty()) { - $this->line('There is nothing to reset.'); - - return; - } - - foreach ($emails as $email) { - $email->retry(); - } - - $this->info('Reset ' . $emails->count() . ' ' . ngettext('e-mail', 'e-mails', $emails->count()) . '!'); - } - - /** - * Execute the console command (backwards compatibility for Laravel 5.4 and below). - * - * @return void - */ - public function fire() - { - $this->handle(); - } -} diff --git a/src/Store.php b/src/Store.php index 9fc73c0..dd0afb1 100644 --- a/src/Store.php +++ b/src/Store.php @@ -29,25 +29,4 @@ public function getQueue() ->limit(Config::cronjobEmailLimit()) ->get(); } - - /** - * Get all e-mails that failed to be sent. - * - * @param int $id - * @return Collection|Email[] - */ - public function getFailed($id = null) - { - $query = new Email; - - return $query - ->when($id, function ($query) use ($id) { - $query->where('id', '=', $id); - }) - ->where('failed', '=', 1) - ->where('attempts', '>=', Config::maxAttemptCount()) - ->whereNull('sent_at') - ->whereNull('deleted_at') - ->get(); - } } diff --git a/tests/RetryFailedEmailsCommandTest.php b/tests/RetryFailedEmailsCommandTest.php deleted file mode 100644 index d8a64cf..0000000 --- a/tests/RetryFailedEmailsCommandTest.php +++ /dev/null @@ -1,53 +0,0 @@ -app['config']['laravel-database-emails.attempts'] = 3; - } - - /** @test */ - public function an_email_cannot_be_reset_if_the_max_attempt_count_has_not_been_reached() - { - $this->app['config']['mail.driver'] = 'does-not-exist'; - - $this->sendEmail(); - - $this->artisan('email:send'); - - $this->assertEquals(1, DB::table('emails')->count()); - - $this->artisan('email:resend'); - - $this->assertEquals(1, DB::table('emails')->count()); - - // try 2 more times, reaching 3 attempts and thus failing and able to retry - $this->artisan('email:send'); - $this->artisan('email:send'); - $this->artisan('email:resend'); - - $this->assertEquals(2, DB::table('emails')->count()); - } - - /** @test */ - public function a_single_email_can_be_resent() - { - $emailA = $this->sendEmail(); - $emailB = $this->sendEmail(); - - // simulate emailB being failed... - $emailB->update(['failed' => 1, 'attempts' => 3]); - - $this->artisan('email:resend', ['id' => 2]); - - $this->assertEquals(3, DB::table('emails')->count()); - } -}