lasthourcloud/app/Livewire/RunCommand.php

44 lines
949 B
PHP
Raw Normal View History

2023-03-20 12:04:22 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire;
2023-03-20 12:04:22 +00:00
use App\Actions\Server\RunCommand as ServerRunCommand;
use App\Models\Server;
2023-03-20 12:04:22 +00:00
use Livewire\Component;
class RunCommand extends Component
{
2023-05-12 13:39:07 +00:00
public string $command;
2024-06-10 20:43:34 +00:00
2023-03-28 13:47:37 +00:00
public $server;
2024-06-10 20:43:34 +00:00
public $servers = [];
protected $rules = [
'server' => 'required',
2023-05-04 08:00:08 +00:00
'command' => 'required',
];
2024-06-10 20:43:34 +00:00
2023-06-16 10:35:40 +00:00
protected $validationAttributes = [
'server' => 'server',
'command' => 'command',
];
2023-05-12 13:39:07 +00:00
public function mount($servers)
{
2023-05-12 13:39:07 +00:00
$this->servers = $servers;
$this->server = $servers[0]->uuid;
}
2023-03-20 12:04:22 +00:00
public function runCommand()
{
2023-06-19 09:02:01 +00:00
$this->validate();
2023-05-12 13:39:07 +00:00
try {
$activity = ServerRunCommand::run(server: Server::where('uuid', $this->server)->first(), command: $this->command);
$this->dispatch('activityMonitor', $activity->id);
2023-09-11 15:36:30 +00:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-05-12 13:39:07 +00:00
}
2023-03-20 12:04:22 +00:00
}
}