diff --git a/src/LaravelDatabaseEmailsServiceProvider.php b/src/LaravelDatabaseEmailsServiceProvider.php index 80cbb29..3796a2a 100644 --- a/src/LaravelDatabaseEmailsServiceProvider.php +++ b/src/LaravelDatabaseEmailsServiceProvider.php @@ -33,8 +33,6 @@ public function register() { $this->commands([ SendEmailsCommand::class, - RetryFailedEmailsCommand::class, - ResendEmailsCommand::class, ]); } } diff --git a/src/ResendEmailsCommand.php b/src/ResendEmailsCommand.php deleted file mode 100644 index 4ae8f8c..0000000 --- a/src/ResendEmailsCommand.php +++ /dev/null @@ -1,20 +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/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/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 794eda1..0000000 --- a/tests/RetryFailedEmailsCommandTest.php +++ /dev/null @@ -1,67 +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()); - } - - /** @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()); - } -} 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')); - } }