Allow Null = 0

Allow Value to be nullable, will autofill 0 if value is null or 0, to facilitate "unlimited" connections.
This commit is contained in:
Charles Morgan 2020-04-23 10:45:44 -04:00
parent 0ecfb40f5e
commit 82dd7dc8e3
8 changed files with 28 additions and 12 deletions

View file

@ -68,7 +68,7 @@ interface DatabaseRepositoryInterface extends RepositoryInterface
* @param string $username
* @param string $remote
* @param string $password
* @param string $max_connections
* @param $max_connections
* @return bool
*/
public function createUser(string $username, string $remote, string $password, string $max_connections): bool;

View file

@ -25,6 +25,7 @@ class StoreServerDatabaseRequest extends AdminFormRequest
$query->where('database_host_id', $this->input('database_host_id') ?? 0);
}),
],
'max_connections' => 'nullable',
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
'database_host_id' => 'required|integer|exists:database_hosts,id',
];

View file

@ -51,7 +51,7 @@ class Database extends Model
'database_host_id' => 'required|exists:database_hosts,id',
'database' => 'required|string|alpha_dash|between:3,100',
'username' => 'string|alpha_dash|between:3,100',
'max_connections' => 'string',
'max_connections' => 'nullable',
'remote' => 'required|string|regex:/^[0-9%.]{1,15}$/',
'password' => 'string',
];

View file

@ -135,12 +135,16 @@ class DatabaseRepository extends EloquentRepository implements DatabaseRepositor
* @param string $username
* @param string $remote
* @param string $password
* @param string $max_connections
* @param $max_connections
* @return bool
*/
public function createUser(string $username, string $remote, string $password, string $max_connections): bool
public function createUser(string $username, string $remote, string $password, $max_connections): bool
{
return $this->run(sprintf('CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\' WITH MAX_USER_CONNECTIONS %s', $username, $remote, $password, $max_connections));
if (!$max_connections) {
return $this->run(sprintf('CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\'', $username, $remote, $password));
} else {
return $this->run(sprintf('CREATE USER `%s`@`%s` IDENTIFIED BY \'%s\' WITH MAX_USER_CONNECTIONS %s', $username, $remote, $password, $max_connections));
}
}
/**