mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
2.x - databases
This commit is contained in:
@ -52,7 +52,7 @@ private function validate(array $input): void
|
||||
Validator::make($input, [
|
||||
'custom' => [
|
||||
'required',
|
||||
new CronRule(),
|
||||
new CronRule,
|
||||
],
|
||||
])->validate();
|
||||
}
|
||||
|
@ -5,36 +5,36 @@
|
||||
use App\Enums\DatabaseStatus;
|
||||
use App\Models\Database;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class CreateDatabase
|
||||
{
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function create(Server $server, array $input): Database
|
||||
{
|
||||
$this->validate($server, $input);
|
||||
|
||||
$database = new Database([
|
||||
'server_id' => $server->id,
|
||||
'name' => $input['name'],
|
||||
]);
|
||||
/** @var \App\SSH\Services\Database\Database */
|
||||
/** @var \App\SSH\Services\Database\Database $databaseHandler */
|
||||
$databaseHandler = $server->database()->handler();
|
||||
$databaseHandler->create($database->name);
|
||||
$database->status = DatabaseStatus::READY;
|
||||
$database->save();
|
||||
|
||||
if (isset($input['user']) && $input['user']) {
|
||||
$databaseUser = app(CreateDatabaseUser::class)->create($server, $input, [$database->name]);
|
||||
|
||||
app(LinkUser::class)->link($databaseUser, ['databases' => [$database->name]]);
|
||||
}
|
||||
|
||||
return $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private function validate(Server $server, array $input): void
|
||||
public static function rules(Server $server, array $input): array
|
||||
{
|
||||
$rules = [
|
||||
'name' => [
|
||||
@ -57,6 +57,7 @@ private function validate(Server $server, array $input): void
|
||||
if (isset($input['remote']) && $input['remote']) {
|
||||
$rules['host'] = 'required';
|
||||
}
|
||||
Validator::make($input, $rules)->validate();
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
use App\Enums\DatabaseUserStatus;
|
||||
use App\Models\DatabaseUser;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use App\SSH\Services\Database\Database;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
@ -16,8 +16,6 @@ class CreateDatabaseUser
|
||||
*/
|
||||
public function create(Server $server, array $input, array $links = []): DatabaseUser
|
||||
{
|
||||
$this->validate($server, $input);
|
||||
|
||||
$databaseUser = new DatabaseUser([
|
||||
'server_id' => $server->id,
|
||||
'username' => $input['username'],
|
||||
@ -25,7 +23,9 @@ public function create(Server $server, array $input, array $links = []): Databas
|
||||
'host' => isset($input['remote']) && $input['remote'] ? $input['host'] : 'localhost',
|
||||
'databases' => $links,
|
||||
]);
|
||||
$server->database()->handler()->createUser(
|
||||
/** @var Database $databaseHandler */
|
||||
$databaseHandler = $server->database()->handler();
|
||||
$databaseHandler->createUser(
|
||||
$databaseUser->username,
|
||||
$databaseUser->password,
|
||||
$databaseUser->host
|
||||
@ -43,7 +43,7 @@ public function create(Server $server, array $input, array $links = []): Databas
|
||||
/**
|
||||
* @throws ValidationException
|
||||
*/
|
||||
private function validate(Server $server, array $input): void
|
||||
public static function rules(Server $server, array $input): array
|
||||
{
|
||||
$rules = [
|
||||
'username' => [
|
||||
@ -59,6 +59,7 @@ private function validate(Server $server, array $input): void
|
||||
if (isset($input['remote']) && $input['remote']) {
|
||||
$rules['host'] = 'required';
|
||||
}
|
||||
Validator::make($input, $rules)->validate();
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
use App\Models\Database;
|
||||
use App\Models\DatabaseUser;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
@ -20,8 +19,6 @@ public function link(DatabaseUser $databaseUser, array $input): void
|
||||
$input['databases'] = [];
|
||||
}
|
||||
|
||||
$this->validate($databaseUser->server, $input);
|
||||
|
||||
$dbs = Database::query()
|
||||
->where('server_id', $databaseUser->server_id)
|
||||
->whereIn('name', $input['databases'])
|
||||
@ -48,15 +45,13 @@ public function link(DatabaseUser $databaseUser, array $input): void
|
||||
$databaseUser->save();
|
||||
}
|
||||
|
||||
private function validate(Server $server, array $input): void
|
||||
public static function rules(Server $server, array $input): array
|
||||
{
|
||||
$rules = [
|
||||
return [
|
||||
'databases.*' => [
|
||||
'required',
|
||||
Rule::exists('databases', 'name')->where('server_id', $server->id),
|
||||
],
|
||||
];
|
||||
|
||||
Validator::make($input, $rules)->validate();
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public function run(Site $site): Deployment
|
||||
}
|
||||
|
||||
if (! $site->deploymentScript?->content) {
|
||||
throw new DeploymentScriptIsEmptyException();
|
||||
throw new DeploymentScriptIsEmptyException;
|
||||
}
|
||||
|
||||
$deployment = new Deployment([
|
||||
|
@ -26,7 +26,7 @@ private function validate(array $input): void
|
||||
{
|
||||
Validator::make($input, [
|
||||
'aliases.*' => [
|
||||
new DomainRule(),
|
||||
new DomainRule,
|
||||
],
|
||||
])->validate();
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ private function validate(array $input): void
|
||||
'name' => 'required',
|
||||
'public_key' => [
|
||||
'required',
|
||||
new SshKeyRule(),
|
||||
new SshKeyRule,
|
||||
],
|
||||
])->validate();
|
||||
}
|
||||
|
@ -13,14 +13,14 @@ public function update(User $user, array $input): void
|
||||
$this->validate($input);
|
||||
$user->projects()->sync($input['projects']);
|
||||
|
||||
if ($user->currentProject && !$user->projects->contains($user->currentProject)) {
|
||||
if ($user->currentProject && ! $user->projects->contains($user->currentProject)) {
|
||||
$user->current_project_id = null;
|
||||
$user->save();
|
||||
}
|
||||
|
||||
/** @var Project $firstProject */
|
||||
$firstProject = $user->projects->first();
|
||||
if (!$user->currentProject && $firstProject) {
|
||||
if (! $user->currentProject && $firstProject) {
|
||||
$user->current_project_id = $firstProject->id;
|
||||
$user->save();
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public static function rules(User $user): array
|
||||
'email' => [
|
||||
'required',
|
||||
'email', 'max:255',
|
||||
Rule::unique('users', 'email')->ignore($user->id)
|
||||
Rule::unique('users', 'email')->ignore($user->id),
|
||||
],
|
||||
'timezone' => [
|
||||
'required',
|
||||
|
Reference in New Issue
Block a user