2023-05-18 11:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
2023-08-07 20:14:21 +00:00
|
|
|
namespace App\Http\Livewire\Project\Shared;
|
2023-05-18 11:26:35 +00:00
|
|
|
|
2023-09-22 09:34:27 +00:00
|
|
|
use App\Actions\Service\StopService;
|
2023-05-18 11:26:35 +00:00
|
|
|
use Livewire\Component;
|
2023-07-13 11:16:24 +00:00
|
|
|
use Visus\Cuid2\Cuid2;
|
2023-05-18 11:26:35 +00:00
|
|
|
|
|
|
|
class Danger extends Component
|
|
|
|
{
|
2023-08-07 20:14:21 +00:00
|
|
|
public $resource;
|
2023-05-22 10:47:15 +00:00
|
|
|
public array $parameters;
|
2023-07-13 11:16:24 +00:00
|
|
|
public string|null $modalId = null;
|
2023-05-22 10:47:15 +00:00
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
2023-07-13 11:16:24 +00:00
|
|
|
$this->modalId = new Cuid2(7);
|
2023-08-09 13:57:53 +00:00
|
|
|
$this->parameters = get_route_parameters();
|
2023-05-22 10:47:15 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-22 10:47:15 +00:00
|
|
|
public function delete()
|
|
|
|
{
|
2023-09-26 12:45:52 +00:00
|
|
|
// Should be queued
|
2023-09-22 09:23:49 +00:00
|
|
|
try {
|
|
|
|
if ($this->resource->type() === 'service') {
|
|
|
|
$server = $this->resource->server;
|
2023-09-22 09:34:27 +00:00
|
|
|
StopService::run($this->resource);
|
2023-09-22 09:23:49 +00:00
|
|
|
} else {
|
|
|
|
$destination = data_get($this->resource, 'destination');
|
|
|
|
if ($destination) {
|
|
|
|
$destination = $this->resource->destination->getMorphClass()::where('id', $this->resource->destination->id)->first();
|
|
|
|
$server = $destination->server;
|
|
|
|
}
|
2023-09-22 09:34:27 +00:00
|
|
|
instant_remote_process(["docker rm -f {$this->resource->uuid}"], $server);
|
2023-09-22 09:23:49 +00:00
|
|
|
}
|
|
|
|
$this->resource->delete();
|
|
|
|
return redirect()->route('project.resources', [
|
|
|
|
'project_uuid' => $this->parameters['project_uuid'],
|
|
|
|
'environment_name' => $this->parameters['environment_name']
|
|
|
|
]);
|
|
|
|
} catch (\Throwable $e) {
|
2023-09-22 12:47:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-09-22 09:23:49 +00:00
|
|
|
}
|
2023-05-22 10:47:15 +00:00
|
|
|
}
|
2023-05-18 11:26:35 +00:00
|
|
|
}
|