mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-15 01:44:04 +00:00
Fix some tests
This commit is contained in:
parent
a632b545b7
commit
1532ccf019
15 changed files with 121 additions and 118 deletions
|
|
@ -49,22 +49,23 @@ class Migrate extends MigrateCommand
|
|||
return;
|
||||
}
|
||||
|
||||
tenant()->all($this->option('tenants'))->each(function ($tenant) {
|
||||
$this->line("Tenant: {$tenant['id']} ({$tenant['domain']})");
|
||||
$originalTenant = tenancy()->getTenant();
|
||||
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
|
||||
$this->line("Tenant: {$tenant['id']}");
|
||||
|
||||
// See Illuminate\Database\Migrations\DatabaseMigrationRepository::getConnection.
|
||||
// Database connections are cached by Illuminate\Database\ConnectionResolver.
|
||||
$this->input->setOption('database', 'tenant');
|
||||
$this->database->connectToTenant($tenant); // todo test that this works with multiple tenants with MySQL
|
||||
tenancy()->initialize($tenant); // todo test that this works with multiple tenants with MySQL
|
||||
|
||||
// Migrate
|
||||
parent::handle();
|
||||
});
|
||||
|
||||
if (tenancy()->initialized) {
|
||||
tenancy()->switchDatabaseConnection();
|
||||
if ($originalTenant) {
|
||||
tenancy()->initialize($originalTenant);
|
||||
} else {
|
||||
$this->database->disconnect();
|
||||
tenancy()->endTenancy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,18 +51,19 @@ class Rollback extends RollbackCommand
|
|||
|
||||
$this->input->setOption('database', 'tenant');
|
||||
|
||||
tenant()->all($this->option('tenants'))->each(function ($tenant) {
|
||||
$this->line("Tenant: {$tenant['id']} ({$tenant['domain']})");
|
||||
$this->database->connectToTenant($tenant);
|
||||
$originalTenant = tenancy()->getTenant();
|
||||
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
|
||||
$this->line("Tenant: {$tenant['id']}");
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
// Migrate
|
||||
parent::handle();
|
||||
});
|
||||
|
||||
if (tenancy()->initialized) {
|
||||
tenancy()->switchDatabaseConnection();
|
||||
if ($originalTenant) {
|
||||
tenancy()->initialize($originalTenant);
|
||||
} else {
|
||||
$this->database->disconnect();
|
||||
tenancy()->endTenancy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,13 +32,10 @@ class Run extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($tenancy_was_initialized = tenancy()->initialized) {
|
||||
$previous_tenants_domain = tenant('domain');
|
||||
}
|
||||
|
||||
tenant()->all($this->option('tenants'))->each(function ($tenant) {
|
||||
$this->line("Tenant: {$tenant['id']} ({$tenant['domain']})");
|
||||
tenancy()->init($tenant['domain']);
|
||||
$originalTenant = tenancy()->getTenant();
|
||||
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
|
||||
$this->line("Tenant: {$tenant['id']}");
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
$callback = function ($prefix = '') {
|
||||
return function ($arguments, $argument) use ($prefix) {
|
||||
|
|
@ -58,11 +55,13 @@ class Run extends Command
|
|||
// Run command
|
||||
$this->call($this->argument('commandname'), \array_merge($arguments, $options));
|
||||
|
||||
tenancy()->end();
|
||||
tenancy()->endTenancy();
|
||||
});
|
||||
|
||||
if ($tenancy_was_initialized) {
|
||||
tenancy()->init($previous_tenants_domain);
|
||||
if ($originalTenant) {
|
||||
tenancy()->initialize($originalTenant);
|
||||
} else {
|
||||
tenancy()->endTenancy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,18 +49,19 @@ class Seed extends SeedCommand
|
|||
|
||||
$this->input->setOption('database', 'tenant');
|
||||
|
||||
tenant()->all($this->option('tenants'))->each(function ($tenant) {
|
||||
$this->line("Tenant: {$tenant['id']} ({$tenant['domain']})");
|
||||
$this->database->connectToTenant($tenant);
|
||||
$originalTenant = tenancy()->getTenant();
|
||||
tenancy()->all($this->option('tenants'))->each(function ($tenant) {
|
||||
$this->line("Tenant: {$tenant['id']}");
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
// Seed
|
||||
parent::handle();
|
||||
});
|
||||
|
||||
if (tenancy()->initialized) {
|
||||
tenancy()->switchDatabaseConnection();
|
||||
if ($originalTenant) {
|
||||
tenancy()->initialize($originalTenant);
|
||||
} else {
|
||||
$this->database->disconnect();
|
||||
tenancy()->endTenancy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class TenantList extends Command
|
|||
{
|
||||
$this->info('Listing all tenants.');
|
||||
tenancy()->all()->each(function ($tenant) {
|
||||
$this->line("[Tenant] id: {$tenant['id']} @ {$tenant['domain']}");
|
||||
$this->line("[Tenant] id: {$tenant['id']} @ ", implode('; ', $tenant->domains));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue