mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 18:04:03 +00:00
Fix #71
This commit is contained in:
parent
ae5527c9a9
commit
a3f37b7f77
7 changed files with 78 additions and 6 deletions
|
|
@ -57,6 +57,10 @@ class Migrate extends MigrateCommand
|
|||
parent::handle();
|
||||
});
|
||||
|
||||
$this->database->disconnect();
|
||||
if (tenancy()->initialized) {
|
||||
tenancy()->switchDatabaseConnection();
|
||||
} else {
|
||||
$this->database->disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,5 +56,11 @@ class Rollback extends RollbackCommand
|
|||
// Migrate
|
||||
parent::handle();
|
||||
});
|
||||
|
||||
if (tenancy()->initialized) {
|
||||
tenancy()->switchDatabaseConnection();
|
||||
} else {
|
||||
$this->database->disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,8 @@
|
|||
|
||||
namespace Stancl\Tenancy\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Stancl\Tenancy\DatabaseManager;
|
||||
use Stancl\Tenancy\Traits\HasATenantsOption;
|
||||
use Illuminate\Database\Migrations\Migrator;
|
||||
use Illuminate\Database\Console\Seeds\SeedCommand;
|
||||
use Illuminate\Database\ConnectionResolverInterface;
|
||||
|
||||
|
|
@ -56,5 +54,11 @@ class Seed extends SeedCommand
|
|||
// Seed
|
||||
parent::handle();
|
||||
});
|
||||
|
||||
if (tenancy()->initialized) {
|
||||
tenancy()->switchDatabaseConnection();
|
||||
} else {
|
||||
$this->database->disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,17 @@ use Stancl\Tenancy\Exceptions\PhpRedisNotInstalledException;
|
|||
trait BootstrapsTenancy
|
||||
{
|
||||
public $originalSettings = [];
|
||||
/**
|
||||
* Was tenancy initialized/bootstrapped?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $initialized = false;
|
||||
|
||||
public function bootstrap()
|
||||
{
|
||||
$this->initialized = true;
|
||||
|
||||
$this->switchDatabaseConnection();
|
||||
if ($this->app['config']['tenancy.redis.tenancy']) {
|
||||
$this->setPhpRedisPrefix($this->app['config']['tenancy.redis.prefixed_connections']);
|
||||
|
|
@ -23,6 +31,8 @@ trait BootstrapsTenancy
|
|||
|
||||
public function end()
|
||||
{
|
||||
$this->initialized = false;
|
||||
|
||||
$this->disconnectDatabase();
|
||||
if ($this->app['config']['tenancy.redis.tenancy']) {
|
||||
$this->resetPhpRedisPrefix($this->app['config']['tenancy.redis.prefixed_connections']);
|
||||
|
|
@ -53,7 +63,8 @@ trait BootstrapsTenancy
|
|||
}
|
||||
}
|
||||
|
||||
public function resetPhpRedisPrefix($connections = ['default']) {
|
||||
public function resetPhpRedisPrefix($connections = ['default'])
|
||||
{
|
||||
foreach ($connections as $connection) {
|
||||
$client = Redis::connection($connection)->client();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue