From f8512886a0fe6f34e88c851662182745b7fa4a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Fri, 29 Mar 2024 21:41:50 +0100 Subject: [PATCH] fix tenants:list and tenants:dump --prune --- src/Commands/TenantDump.php | 13 +++++++++++++ src/Commands/TenantList.php | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Commands/TenantDump.php b/src/Commands/TenantDump.php index 1d1eaf7e..d3d72cfb 100644 --- a/src/Commands/TenantDump.php +++ b/src/Commands/TenantDump.php @@ -7,6 +7,7 @@ namespace Stancl\Tenancy\Commands; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Database\ConnectionResolverInterface; use Illuminate\Database\Console\DumpCommand; +use Illuminate\Filesystem\Filesystem; use Stancl\Tenancy\Contracts\Tenant; use Symfony\Component\Console\Input\InputOption; @@ -41,8 +42,20 @@ class TenantDump extends DumpCommand return 1; } + // Prevent the parent command from pruning the central migrations folder + $prune = $this->option('prune'); + $this->input->setOption('prune', false); + tenancy()->run($tenant, fn () => parent::handle($connections, $dispatcher)); + if ($prune) { + (new Filesystem)->deleteDirectory( + database_path('migrations/tenant'), preserve: true + ); + + $this->components->info('Tenant migrations pruned.'); + } + return 0; } diff --git a/src/Commands/TenantList.php b/src/Commands/TenantList.php index dcbede84..77a561e7 100644 --- a/src/Commands/TenantList.php +++ b/src/Commands/TenantList.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace Stancl\Tenancy\Commands; use Illuminate\Console\Command; -use Illuminate\Database\Eloquent\Collection; +use Illuminate\Support\Collection; use Illuminate\Database\Eloquent\Model; use Stancl\Tenancy\Contracts\SingleDomainTenant; use Stancl\Tenancy\Contracts\Tenant;