1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 18:04:03 +00:00

Get multiple envs (redis/db) to run correctly

This commit is contained in:
Samuel Štancl 2019-09-17 19:39:57 +02:00
parent 9c9858e97e
commit 8565cc7acc
19 changed files with 31 additions and 35 deletions

View file

@ -56,7 +56,7 @@ class Migrate extends MigrateCommand
// See Illuminate\Database\Migrations\DatabaseMigrationRepository::getConnection.
// Database connections are cached by Illuminate\Database\ConnectionResolver.
$this->input->setOption('database', 'tenant');
tenancy()->initialize($tenant); // todo test that this works with multiple tenants with MySQL
tenancy()->initialize($tenant); // todo2 test that this works with multiple tenants with MySQL
// Migrate
parent::handle();

View file

@ -8,7 +8,7 @@ use Stancl\Tenancy\Tenant;
interface TenancyBootstrapper
{
public function start(Tenant $tenant); // todo TenantManager instead of Tenant
public function start(Tenant $tenant); // todo2 TenantManager instead of Tenant
public function end();
}

View file

@ -129,7 +129,7 @@ class DatabaseManager
protected function getTenantDatabaseManager(Tenant $tenant): TenantDatabaseManager
{
// todo this shouldn't have to create a connection
// todo2 this shouldn't have to create a connection
$this->createTenantConnection($tenant->getDatabaseName(), $tenant->getConnectionName());
$driver = $this->getDriver($tenant->getConnectionName());

View file

@ -7,7 +7,7 @@ namespace Stancl\Tenancy\Facades;
use Illuminate\Support\Facades\Facade;
use Stancl\Tenancy\Tenant as Tenant;
// todo rename to CurrentTenant?
// todo2 rename to CurrentTenant?
class TenantFacade extends Facade
{
protected static function getFacadeAccessor()

View file

@ -26,7 +26,7 @@ class TelescopeTags implements Feature
if (in_array('tenancy', optional(request()->route())->middleware() ?? [])) {
$tags = array_merge($tags, [
'tenant:' . tenant('id'),
// 'domain:' . tenant('domain'), todo?
// todo2 domain?
]);
}

View file

@ -16,7 +16,7 @@ use Stancl\Tenancy\Tenant;
class DatabaseStorageDriver implements StorageDriver
{
// todo write tests verifying that data is decoded and added to the array
// todo2 write tests verifying that data is decoded and added to the array
/** @var Application */
protected $app;
@ -47,7 +47,7 @@ class DatabaseStorageDriver implements StorageDriver
public function ensureTenantCanBeCreated(Tenant $tenant): void
{
// todo test this
// todo2 test this
if (Tenants::find($tenant->id)) {
throw new TenantWithThisIdAlreadyExistsException($tenant->id);
}
@ -85,7 +85,7 @@ class DatabaseStorageDriver implements StorageDriver
public function updateTenant(Tenant $tenant): void
{
Tenant::find($tenant->id)->putMany($tenant->data);
// todo update domains
// todo1 update domains
}
public function deleteTenant(Tenant $tenant): void

View file

@ -10,10 +10,10 @@ use Stancl\Tenancy\Contracts\StorageDriver;
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
use Stancl\Tenancy\Tenant;
// todo transactions instead of pipelines?
// todo2 transactions instead of pipelines?
class RedisStorageDriver implements StorageDriver
{
// todo json encoding?
// todo2 json encoding?
/** @var Application */
protected $app;
@ -49,7 +49,7 @@ class RedisStorageDriver implements StorageDriver
public function ensureTenantCanBeCreated(Tenant $tenant): void
{
// todo
// todo2
}
public function findByDomain(string $domain): Tenant
@ -76,7 +76,7 @@ class RedisStorageDriver implements StorageDriver
}
$data = array_combine($keys, $values);
$domains = []; // todo
$domains = []; // todo2
return Tenant::fromStorage($data)->withDomains($domains);
}
@ -107,7 +107,7 @@ class RedisStorageDriver implements StorageDriver
$pipe->hmset("domains:$domain", 'tenant_id', $tenant->id);
}
// todo deleted domains
// todo2 deleted domains
});
}
@ -124,7 +124,7 @@ class RedisStorageDriver implements StorageDriver
public function all(array $ids = []): array
{
// todo $this->redis->pipeline() - return?
// todo2 $this->redis->pipeline()
$hashes = array_map(function ($hash) {
return "tenants:{$hash}";
}, $ids);

View file

@ -29,7 +29,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
public function start(Tenant $tenant)
{
// todo revisit this
// todo2 revisit this
$suffix = $this->app['config']['tenancy.filesystem.suffix_base'] . $tenant->id;
// storage_path()

View file

@ -50,7 +50,7 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
'tenant_id' => $id,
'tags' => [
"tenant:$id",
// todo domain?
// todo2 domain
],
];
}

View file

@ -52,7 +52,9 @@ class TenancyServiceProvider extends ServiceProvider
{
$this->mergeConfigFrom(__DIR__ . '/../assets/config.php', 'tenancy');
$this->app->bind(Contracts\StorageDriver::class, $this->app['config']['tenancy.storage_driver']);
$this->app->bind(Contracts\StorageDriver::class, function ($app) {
return $app->make($app['config']['tenancy.storage_driver']);
});
$this->app->bind(Contracts\UniqueIdentifierGenerator::class, $this->app['config']['tenancy.unique_id_generator']);
$this->app->singleton(DatabaseManager::class);
$this->app->singleton(TenantManager::class);

View file

@ -240,7 +240,7 @@ class Tenant implements ArrayAccess
public function put($key, $value = null): self
{
if ($key === 'id') {
throw new TenantStorageException("The tenant's id can't be changed.");
throw new TenantStorageException("Tenant ids can't be changed.");
}
if (is_array($key)) {

View file

@ -29,7 +29,7 @@ class TenantManager
protected $artisan;
/** @var Contracts\StorageDriver */
protected $storage;
public $storage;
/** @var DatabaseManager */
public $database;
@ -229,7 +229,7 @@ class TenantManager
protected function bootstrapFeatures(): self
{
// todo this doesn't work
// todo1 this doesn't work
// foreach ($this->app['config']['tenancy.features'] as $feature) {
// $this->app[$feature]->bootstrap($this);
// }