mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 06:04:03 +00:00
Merge branch 'db-users-rewrite' of github.com:stancl/tenancy into db-users-rewrite
This commit is contained in:
commit
ea72a7b4c7
5 changed files with 16 additions and 10 deletions
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Contracts;
|
||||
|
||||
use Stancl\Tenancy\DatabaseConfig;
|
||||
|
|
@ -7,5 +9,6 @@ use Stancl\Tenancy\DatabaseConfig;
|
|||
interface ManagesDatabaseUsers
|
||||
{
|
||||
public function createUser(DatabaseConfig $databaseConfig): void;
|
||||
|
||||
public function deleteUser(DatabaseConfig $databaseConfig): void;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy;
|
||||
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
|
@ -10,7 +12,7 @@ use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
|||
use Stancl\Tenancy\Exceptions\DatabaseManagerNotRegisteredException;
|
||||
|
||||
class DatabaseConfig
|
||||
{
|
||||
{
|
||||
/** @var Tenant */
|
||||
public $tenant;
|
||||
|
||||
|
|
@ -104,7 +106,7 @@ class DatabaseConfig
|
|||
// and it doesn't exist, we'll go for the default DB template.
|
||||
if (! array_key_exists($name, config('database.connections'))) {
|
||||
$name = config('tenancy.database.template_connection') ?? DatabaseManager::$originalDefaultConnectionName;
|
||||
};
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class DatabaseManager
|
|||
|
||||
/**
|
||||
* Check if a tenant can be created.
|
||||
*
|
||||
*
|
||||
* @throws TenantCannotBeCreatedException
|
||||
* @throws DatabaseManagerNotRegisteredException
|
||||
* @throws TenantDatabaseAlreadyExistsException
|
||||
|
|
@ -160,7 +160,7 @@ class DatabaseManager
|
|||
}
|
||||
|
||||
foreach ($afterCreating as $item) {
|
||||
if (is_object($item) && !$item instanceof Closure) {
|
||||
if (is_object($item) && ! $item instanceof Closure) {
|
||||
$item->handle($tenant);
|
||||
} else {
|
||||
$item($tenant);
|
||||
|
|
@ -170,7 +170,7 @@ class DatabaseManager
|
|||
|
||||
/**
|
||||
* Delete a tenant's database.
|
||||
*
|
||||
*
|
||||
* @throws DatabaseManagerNotRegisteredException
|
||||
*/
|
||||
public function deleteDatabase(Tenant $tenant)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\TenantDatabaseManagers;
|
||||
|
||||
use Stancl\Tenancy\Contracts\ManagesDatabaseUsers;
|
||||
|
|
@ -19,7 +21,7 @@ class PermissionControlledMySQLDatabaseManager extends MySQLDatabaseManager impl
|
|||
$username = $databaseConfig->getUsername();
|
||||
$hostname = $databaseConfig->connection()['host'];
|
||||
$password = $databaseConfig->getPassword();
|
||||
|
||||
|
||||
$this->database()->statement("CREATE USER `{$username}`@`{$hostname}` IDENTIFIED BY `{$password}`");
|
||||
|
||||
$grants = implode(', ', static::$grants);
|
||||
|
|
@ -44,4 +46,4 @@ class PermissionControlledMySQLDatabaseManager extends MySQLDatabaseManager impl
|
|||
{
|
||||
$this->database()->statement("DROP USER IF EXISTS '{$databaseConfig->username}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
class DatabaseUsersTest extends TestCase
|
||||
|
|
@ -7,18 +9,15 @@ class DatabaseUsersTest extends TestCase
|
|||
/** @test */
|
||||
public function users_are_created_when_permission_controlled_mysql_manager_is_used()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function correct_grants_are_given_to_the_users()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function having_existing_databases_without_users_and_switching_to_permission_controlled_mysql_manager_doesnt_break_existing_dbs()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue