1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-06 09:34:04 +00:00

FutureTest

This commit is contained in:
Samuel Štancl 2019-10-27 20:39:47 +01:00
parent 71d2ea1b62
commit d97f45b587
6 changed files with 82 additions and 15 deletions

View file

@ -9,6 +9,7 @@ use Illuminate\Database\Connection;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\DB;
use Stancl\Tenancy\Contracts\Future\CanDeleteKeys;
use Stancl\Tenancy\Contracts\Future\CanFindByAnyKey;
use Stancl\Tenancy\Contracts\StorageDriver;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Exceptions\DomainsOccupiedByOtherTenantException;
@ -17,7 +18,7 @@ use Stancl\Tenancy\Exceptions\TenantDoesNotExistException;
use Stancl\Tenancy\Exceptions\TenantWithThisIdAlreadyExistsException;
use Stancl\Tenancy\Tenant;
class DatabaseStorageDriver implements StorageDriver, CanDeleteKeys
class DatabaseStorageDriver implements StorageDriver, CanDeleteKeys, CanFindByAnyKey
{
/** @var Application */
protected $app;
@ -89,15 +90,14 @@ class DatabaseStorageDriver implements StorageDriver, CanDeleteKeys
*/
public function findBy(string $key, $value): Tenant
{
// The key has to be a custom column. It's recommended to set up an index // TODO can we query JSON?
$tenant = $this->tenants->where($key, $value)->first()->toArray();
$tenant = $this->tenants->findBy($key, $value);
if (! $tenant) {
throw new TenantDoesNotExistException($value, $key);
}
return Tenant::fromStorage($tenant->decoded())
->withDomains($this->domains->getTenantDomains($tenant->id));
return Tenant::fromStorage($this->tenants->decodeData($tenant))
->withDomains($this->domains->getTenantDomains($tenant['id']));
}
public function ensureTenantCanBeCreated(Tenant $tenant): void