From 2faf9e8683c88ccc2073f5f5302857d094b41dd7 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Thu, 28 Jul 2022 09:42:47 +0200 Subject: [PATCH] Allow using only one time constraint for clearing the pending tenants --- src/Commands/ClearPendingTenants.php | 16 +++++++++++++--- tests/PendingTenantsTest.php | 7 +++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Commands/ClearPendingTenants.php b/src/Commands/ClearPendingTenants.php index 6af98178..db2e0ef5 100644 --- a/src/Commands/ClearPendingTenants.php +++ b/src/Commands/ClearPendingTenants.php @@ -31,7 +31,7 @@ class ClearPendingTenants extends Command */ public function handle() { - $this->info('Cleaning pending tenants.'); + $this->info('Removing pending tenants.'); $expirationDate = now(); // We compare the original expiration date to the new one to check if the new one is different later @@ -39,11 +39,21 @@ class ClearPendingTenants extends Command // Skip the time constraints if the 'all' option is given if (! $this->option('all')) { - if ($olderThanDays = $this->option('older-than-days')) { + $olderThanDays = $this->option('older-than-days'); + $olderThanHours = $this->option('older-than-hours'); + + if ($olderThanDays && $olderThanHours) { + $this->line(" Cannot use '--older-than-days' and '--older-than-hours' together \n"); + $this->line('Please, choose only one of these options.'); + + return 1; // Exit code for failure + } + + if ($olderThanDays) { $expirationDate->subDays($olderThanDays); } - if ($olderThanHours = $this->option('older-than-hours')) { + if ($olderThanHours) { $expirationDate->subHours($olderThanHours); } } diff --git a/tests/PendingTenantsTest.php b/tests/PendingTenantsTest.php index b30440b9..231018ba 100644 --- a/tests/PendingTenantsTest.php +++ b/tests/PendingTenantsTest.php @@ -81,6 +81,13 @@ class PendingTenantsTest extends TestCase $this->assertCount(1, Tenant::onlyPending()->get()); } + /** @test */ + public function clear_pending_tenants_command_cannot_run_with_both_time_constraints() + { + $this->artisan('tenants:pending-clear --older-than-days=2 --older-than-hours=2') + ->assertFailed(); + } + /** @test */ public function clear_pending_tenants_command_all_option_overrides_config() {