mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 15:32:35 +00:00
#591 - sites
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
use App\Models\CommandExecution;
|
||||
use App\Models\ServerLog;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class ExecuteCommand
|
||||
{
|
||||
@ -15,19 +16,31 @@ class ExecuteCommand
|
||||
*/
|
||||
public function execute(Command $command, User $user, array $input): CommandExecution
|
||||
{
|
||||
Validator::make($input, self::rules($command))->validate();
|
||||
|
||||
$variables = [];
|
||||
foreach ($command->getVariables() as $variable) {
|
||||
if (array_key_exists($variable, $input)) {
|
||||
$variables[$variable] = $input[$variable] ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
$execution = new CommandExecution([
|
||||
'command_id' => $command->id,
|
||||
'server_id' => $command->site->server_id,
|
||||
'user_id' => $user->id,
|
||||
'variables' => $input['variables'] ?? [],
|
||||
'variables' => $variables,
|
||||
'status' => CommandExecutionStatus::EXECUTING,
|
||||
]);
|
||||
$execution->save();
|
||||
|
||||
dispatch(function () use ($execution, $command): void {
|
||||
$log = ServerLog::newLog($execution->server, 'command-'.$command->id.'-'.strtotime('now'));
|
||||
$log->save();
|
||||
$execution->server_log_id = $log->id;
|
||||
$execution->save();
|
||||
|
||||
dispatch(function () use ($execution, $command, $log): void {
|
||||
$content = $execution->getContent();
|
||||
$log = ServerLog::newLog($execution->server, 'command-'.$command->id.'-'.strtotime('now'));
|
||||
$log->save();
|
||||
$execution->server_log_id = $log->id;
|
||||
$execution->save();
|
||||
$execution->server->os()->runScript(
|
||||
@ -48,18 +61,19 @@ public function execute(Command $command, User $user, array $input): CommandExec
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
* @return array<string, string|array<int, mixed>>
|
||||
*/
|
||||
public static function rules(array $input): array
|
||||
public static function rules(Command $command): array
|
||||
{
|
||||
return [
|
||||
'variables' => 'array',
|
||||
'variables.*' => [
|
||||
$rules = [];
|
||||
foreach ($command->getVariables() as $variable) {
|
||||
$rules[$variable] = [
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
];
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user